- 1
- 2
if (dbg)
printf("2\n");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+133
if (dbg)
printf("2\n");
// This is debug mode
+133
//......................................
void DlPortWritePortUshort(WORD addr, WORD data) {
DWORD br;
(&addr)[1]=data;
DeviceIoControl(hdriver,IOCTL_WRITE_PORT_USHORT,&addr,4,NULL,0,&br,NULL);
}
DWORD DlPortReadPortUlong(WORD addr) {
DWORD br;
DeviceIoControl(hdriver,IOCTL_READ_PORT_ULONG,&addr,2,&addr,4,&br,NULL);
return *(DWORD*)&addr;
}
void DlPortWritePortUlong(WORD addr, DWORD data) {
DWORD br;
DeviceIoControl(hdriver,IOCTL_WRITE_PORT_ULONG,&addr,8,NULL,0,&br,NULL);
}
//......................................
Кусок очередного форка dll-ки для работы с очередным, мать его, форком драйвера inpout32.sys.
Попался в поисках исправленного драйвера и dll-обёртки для него.
+133
var hContextMenu = (ContextMenu)MainDataGrid.Resources["CellContextMenu"];
//UndoMenuItem.CommandTarget = MainDataGrid;
UndoMenuItem.Command = ((MenuItem)hContextMenu.Items[0]).Command; //Undo
//RedoMenuItem.CommandTarget = MainDataGrid;
RedoMenuItem.Command = ((MenuItem)hContextMenu.Items[1]).Command; //Redo
//CutMenuItem.CommandTarget = MainDataGrid;
CutMenuItem.Command = ((MenuItem)hContextMenu.Items[3]).Command; //Cut
//CopyMenuItem.CommandTarget = MainDataGrid;
CopyMenuItem.Command = ((MenuItem)hContextMenu.Items[4]).Command; //Copy
//PasteMenuItem.CommandTarget = MainDataGrid;
PasteMenuItem.Command = ((MenuItem)hContextMenu.Items[5]).Command; //Paste
Из моего проекта. Так я писал код год назад.
+133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nonopt
{
class Program
{
static void Main(string[] args)
{
string h = "h";
string e = "e";
string l1 = "l";
string l2 = "l";
string o1 = "o";
string he = h + e;
string ll = l1 + l2;
string hell = he + ll;
string hello = hell + o1;
string w = "w";
string o2 = "o";
string r = "r";
string l3 = "l";
string d = "d";
string wo = w + o2;
string rl = r + l3;
string worl = wo + rl;
string world = worl + d;
string empty = " ";
Console.WriteLine(hello + empty + world);
Console.ReadKey();
}
}
}
+133
http://www.youtube.com/watch?v=yRsT5wBSYZ0
Советую
+133
public static T ElementAtReverse<T>(this IEnumerable<T> source, int index)
{
while (true)
{
var array = source as T[] ?? source.ToArray();
var elementsCount = array.Count();
if (index < elementsCount || elementsCount == 0)
return array.ElementAt(elementsCount - 1 - index);
source = array;
index = index % elementsCount;
}
}
+133
BaseIndexerObjectType type;
<...>
var searchType = (SearchEntity)Enum.Parse(typeof(SearchEntity), type.ToString());
Наткнулся на просторах рабочего кода. Конвертируем один енум в другой.
+133
bool findImageToleranceIn(CTSInfo *info, bitmap *imageToFind, int32_t *x, int32_t *y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t tolerance)
{
int I, J, XX, YY;
info->tol = tolerance;
int dX = (x2 - x1) - (imageToFind->width - 1);
int dY = (y2 - y1) - (imageToFind->height - 1);
for (I = 0; I < dY; ++I)
{
for (J = 0; J < dX; ++J)
{
for (YY = 0; YY < imageToFind->height; ++YY)
{
for (XX = 0; XX < imageToFind->width; ++XX)
{
rgb32* pixel = &imageToFind->pixels[YY * imageToFind->width + XX];
rgb32* targetPixel = &info->targetImage->pixels[(YY + I) * info->targetImage->width + (XX + J)];
if (pixel->a != 0)
{
if (!(*info->ctsFuncPtr)(info, pixel, targetPixel))
{
goto Skip;
}
}
}
}
*x = J + x1;
*y = I + y1;
return true;
Skip:
continue;
}
}
*x = -1;
*y = -1;
return false;
}
В чём здесь сакральный смысл GoTo?
+133
private static List<User> Users
{
get
{
if (_customers == null) { _customers = new List<Customer>(); }
lock (((ICollection)_customers).SyncRoot)
{
return _customers;
}
}
set
{
lock (((ICollection)Customer).SyncRoot)
{
_customers = value;
}
}
+133
if (*wpPat == L'\\')
{
wpCharStart=wpPat;
if (++wpPat >= wpMaxPat) goto Error;
if (*wpPat == L'x')
{
if (++wpPat >= wpMaxPat) goto Error;
if (*wpPat == L'{')
{
wpStrTmp=++wpPat;
for (;;)
{
if (wpPat >= wpMaxPat) goto Error;
if (*wpPat++ == L'}') break;
}
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
{
nPatChar=(int)hex2decW(wpStrTmp, (wpPat - 1) - wpStrTmp);
if (nPatChar == -1)
{
wpPat=wpStrTmp;
goto Error;
}
if (nPatChar <= MAXWORD)
lpREGroupItem->nGroupLen+=1;
else
lpREGroupItem->nGroupLen+=2;
}
}
else
{
if (wpPat + 2 > wpMaxPat)
goto Error;
wpPat+=2;
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
++lpREGroupItem->nGroupLen;
}
}
else if (*wpPat == L'u')
{
if (wpPat + 5 > wpMaxPat)
goto Error;
wpPat+=5;
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
++lpREGroupItem->nGroupLen;
}
Регулярные велосипеды.
Akelpad.