- 1
- 2
- 3
- 4
public void Children_OnAdd(object sender, EventArgs e)
{
((MyEventArgs<Document>)e).D.Parent = this;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+134
public void Children_OnAdd(object sender, EventArgs e)
{
((MyEventArgs<Document>)e).D.Parent = this;
}
+131
public class UserData : EventArgs {
public int UserCod { get; set; }
public string Name { get; set; }
public UserData(DataRow dataRow)
{
UserCod = (int)(decimal)dataRow["user_cod"];
Name = (string)dataRow["name"];
}
}
Во время рефакторинга появилось сообщение от VS UserData нельзя привести к типу UserData...
Заглянули в один из классов UserData...
теперь понятно откуда запах)))
+125
//сервер сайд (из colors.php)
$colors = [
'banana' => 'yellow',
'orange' => 'orange',
'cucumber' => 'green'
];
echo $colors[$_GET['fruit']];
//клиент сайд (js)
var fruits = ['banana', 'orange', 'cucumber']
for (var i in fruits) {
var fruit = fruits[i]
$.get('colors.php?fruit='+fruit, function(color){
document.write(fruit +' is '+ color +'<br/>')
})
}
Этот код показывают и задают вопрос почти на любом собеседовании на должность web-программита:
Что здесь неверно и как это исправить?
+128
/// <summary>
/// Проверка нажатия 2 клавиш (напрмер: Ctrl+W)
/// </summary>
/// <param name="firstKey">Первая клавиша</param>
/// <param name="hotKey">Сочетание из БД</param>
/// <param name="e">Аргументы события нажатия клавиши</param>
/// <param name="Scope">Область видимости</param>
/// <returns>Действие</returns>
private static string CheckMultipleKeyPress(string firstKey, DBHotKeys_new hotKey, KeyEventArgs e, HotKeyScope Scope)
{
System.Text.StringBuilder concat = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(PreviousKey))
{
concat.Append('+');
}
if (!string.IsNullOrEmpty(firstKey))
{
concat.Append(firstKey).Append('+');
}
if (!string.IsNullOrEmpty(PreviousKey))
{
concat.Append(PreviousKey).Append('+');
}
PreviousKey = ReplaceKeyCode(e.KeyCode);
if (e.KeyCode != Keys.ControlKey)
{
concat.Append(ReplaceKeyCode(e.KeyCode));
}
//if (concat[0] == '+')
//{
// concat = new System.Text.StringBuilder(concat.ToString().Substring(1));
//}
if ((hotKey.Scope == Scope) && (concat.ToString().Equals(hotKey.HotKeyString)))
{
PreviousKey = string.Empty;
return hotKey.Action;
}
PreviousKey = string.Empty;
return string.Empty;
}
+138
/// <summary>
/// Преобразование системных наименований клавиш в "понятные пользователю"
/// </summary>
/// <param name="key">Нажатая системная клавиша</param>
/// <returns>Понятное представление</returns>
public static string ReplaceKeyCode(System.Windows.Forms.Keys key)
{
switch (key)
{
case Keys.OemQuestion: return "'?'";
case Keys.OemOpenBrackets: return "'{'";
case Keys.Oemtilde: return "'~'";
case Keys.Next: return "PageDown";
}
switch (key)
{
case Keys.A: return "A";
case Keys.Add: return "Num'+'";
case Keys.Alt: return "Alt";
case Keys.B: return "B";
case Keys.Back: return "Backspace";
case Keys.C: return "C";
case Keys.Cancel: return "Cancel";
case Keys.Clear: return "Clear";
case Keys.ControlKey: return "Ctrl";
case Keys.D: return "D";
case Keys.D0: return "0"; case Keys.D1: return "1"; case Keys.D2: return "2"; case Keys.D3: return "3";
case Keys.D4: return "4"; case Keys.D5: return "5"; case Keys.D6: return "6"; case Keys.D7: return "7";
case Keys.D8: return "8"; case Keys.D9: return "9"; case Keys.Decimal: return "Num'.'";
case Keys.Delete: return "Delete";
case Keys.Divide: return "Num'/'";
case Keys.Down: return "Down";
case Keys.E: return "E";
case Keys.End: return "End";
case Keys.Escape: return "Esc";
case Keys.F: return "F";
case Keys.F1: return "F1";
case Keys.F10: return "F10";
case Keys.F11: return "F11";
case Keys.F12: return "F12";
case Keys.F2: return "F2";
case Keys.F3: return "F3";
case Keys.F4: return "F4";
case Keys.F5: return "F5";
case Keys.F6: return "F6";
case Keys.F7: return "F7";
case Keys.F8: return "F8";
case Keys.F9: return "F9";
case Keys.G: return "G";
case Keys.H: return "H";
case Keys.Home: return "Home";
case Keys.I: return "I";
case Keys.Insert: return "Insert";
case Keys.J: return "J";
case Keys.K: return "K";
case Keys.L: return "L";
case Keys.M: return "M";
case Keys.N: return "N";
case Keys.Next: return "Next";
case Keys.NumPad0: return "Num0";
case Keys.NumPad1: return "Num1";
case Keys.NumPad2: return "Num2";
case Keys.NumPad3: return "Num3";
case Keys.NumPad4: return "Num4";
case Keys.NumPad5: return "Num5";
case Keys.NumPad6: return "Num6";
case Keys.NumPad7: return "Num7";
case Keys.NumPad8: return "Num8";
case Keys.NumPad9: return "Num9";
case Keys.O: return "O";
case Keys.Oem1: return "';'";
case Keys.Oem5: return "'/'";
case Keys.Oem6: return "'{'";
case Keys.Oem7: return "\"";
case Keys.OemMinus: return "'-'";
case Keys.OemPeriod: return "'>'";
case Keys.Oemcomma: return "'<'";
case Keys.Oemplus: return "'+'";
case Keys.P: return "P";
case Keys.PageUp: return "PageUp";
case Keys.Q: return "Q";
case Keys.R: return "R";
case Keys.S: return "S";
case Keys.ShiftKey: return "Shift";
case Keys.Space: return "Space";
case Keys.Subtract: return "Num'-'";
case Keys.T: return "T";
case Keys.Tab: return "Tab";
case Keys.U: return "U";
case Keys.Up: return "Up";
case Keys.V: return "V";
case Keys.W: return "W";
case Keys.X: return "X";
case Keys.Y: return "Y";
case Keys.Z: return "Z";
case Keys.Menu: return "Alt";
case Keys.Multiply: return "Num'*'";
default: return string.Empty;
}
}
+133
/// <summary>
/// Подключение к удаленному трек серверу
/// Повторяет попытки подключения в фоновом режиме.
/// </summary>
public void ConnectToTrackServer()
{
lock (LockConnToTrack)
{
if (ConnTrackServer == null)
{
ConnTrackServer = new Thread(new ParameterizedThreadStart(ConnectToTrackServerAsync));
ConnTrackServer.Start();
}
else if (!ConnTrackServer.IsAlive)
{
ConnTrackServer.Start();
}
}
//ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectToTrackServerAsync));
}
Продолжение к прошлому посту
+135
private uint IdOnTrackServer
{
get
{
try
{
if (m_IdOnTrackServer == null || m_IdOnTrackServer == uint.MaxValue)
{
ConnectToTrackServer();
}
//if (m_IdOnTrackServer == null)
//{
// // асинхронно подключаемся к серверу треков
// // если сразу подключиться не получилось, то в фоновом потоке стартим reconnect
// if (!TryToConnectToTrackServer_UseResults())
// {
// ConnectToTrackServer();
// }
//}
//else if (m_IdOnTrackServer == uint.MaxValue)
//{
// TryToConnectToTrackServer_UseResults();
//}
return m_IdOnTrackServer.Value;
}
catch
{
return uint.MaxValue;
}
}
}
+159
function validateForm(form){
if (isNotEmpty(form.fa)){
if (isColvo(form.fa,3)){
if (isNotEmpty(form.im)){
if (isColvo(form.im,2)){
if (isNotEmpty(form.ot)){
if (isColvo(form.ot,3)){
if(isNotEmpty(form.day)){
if(isNumbr(form.day)){
if(isNotEmpty(form.month)){
if(isNumbr(form.month)){
if(isNotEmpty(form.year)){
if (isColvo(form.year,4)){
if(isNumbr(form.year)){
if(isNotEmpty(form.city)){
if(isNotEmpty(form.road)){
if(isNotEmpty(form.house)){
if(isNumbr(form.house)){
return true;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return false;
};
http://национальныйзакон.рф
+179
$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
Форматирование даты в жс. Без jQuery ясное дело не обойтись.
If you are already using jQuery UI in your project, you can use the built-in datepicker method for formatting your date object:
http://stackoverflow.com/a/7022296
Раз уж неделя стековерфловочки...
+71
String currentDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date());
accountNumber.append(String.valueOf(1900 + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getYear()));
accountNumber.append(String.valueOf(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getMonth()));
accountNumber.append(String.valueOf(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getDate()));
accountNumber.append(String.valueOf(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getHours()));
accountNumber.append(String.valueOf(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getMinutes()));
accountNumber.append(String.valueOf(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(currentDate).getSeconds()));
ну а чо, зато внушительно выглядит