- 1
$->db->select_value('select now()');
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+149
$->db->select_value('select now()');
наверное в мускуле какое-то другое время
+141
ЕБАТЬ АДМИНИСТРАТОРА ВИО
ДЖАСТИН БИБЕР ПИДОРАС
Я ЕБАЛ МАМКУ АДМИНА ГОВНОКОДА
Тест, хули. (С) мафия ВиО
+154
$background_nid = _get_last_section_background($node);
$new_background_nid = ($background_nid == 47)?48:47;
$background_color = db_query("SELECT field_background_color_value FROM {field_revision_field_background_color} WHERE entity_id=:nid AND entity_type='node'", array(":nid" => $new_background_nid))->fetchField();
$style_background = "background-color: #".$background_color."; ";
Изысканное получение node id в Drupal
+136
private AseConnection con;
public void CloseConnection()
{
if (this.con != null && this.con.State == ConnectionState.Open)
{
CloseConnection(this.con);
}
}
public void CloseConnection(AseConnection con)
{
if (con == null)
return;
if (con.State == ConnectionState.Closed)
return;
con.Close();
}
А кому ещё враппэровъ? У меня много ихъ!
+115
for (int i = 0; i < 40; i++)
{
GC.Collect();
}
чтоб наверняка :))
+91
function TDuel.getFieldStr(p1: ansistring; p2: ansistring; p3: ansistring = ''): ansistring;
begin
Result := '';
if p1 = 'p1' then begin
if p2 = 'attack' then begin
if p3 = '' then Result := p1attack;
if p3 = '1' then Result := p1attack1;
end;
if p2 = 'defend' then begin
Result := p1defend;
end;
end;
if p1 = 'p2' then begin
if p2 = 'attack' then begin
if p3 = '' then Result := p2attack;
if p3 = '1' then Result := p2attack1;
end;
if p2 = 'defend' then begin
Result := p2defend;
end;
end;
end;
function TDuel.getFieldInt(p1: ansistring; p2: ansistring; p3: ansistring = ''): integer;
begin
if p1 = 'player' then begin
if p2 = '1' then Result := player1;
if p2 = '2' then Result := player2;
end;
if p1 = 'p' then begin
if p2 = '1' then begin
if p3 = 'dmg' then Result := p1dmg;
end;
if p2 = '2' then begin
if p3 = 'dmg' then Result := p2dmg;
end;
end;
end;
procedure TDuel.updFieldInt(p1: ansistring; p2: ansistring; value: integer);
begin
if p1 = 'p1' then begin
if p2 = 'dmg' then p1dmg := p1dmg + value;
end;
if p1 = 'p2' then begin
if p2 = 'dmg' then p2dmg := p2dmg + value;
end;
end;
Вот такой шедевр программерской мысли остался в коде сервера браузерки от первых девелоперов. Я так и не распарсил пока, что он делает-)
−184
- (Pt) menuItemPos: (int) i colRef: (int *) colr
{
int rowBeg [6] = { 1, 8, 15, 22, 28, 100 };
float rowNum [6] = { 7, 7, 7, 6.0, 5.0 };// { 7.03, 6.72, 7, 5.65, 4.43 };
int col = -5;
int row = -5;
for(int j = 1; j < 6; ++j)
if(i < rowBeg[j] && i >= rowBeg[j - 1])
{
row = j - 1;
col = i - rowBeg[row];
*colr = col;
break;
}
float S = _large ? 80 : 30;
float W = _large ? 1474/2 : 320;
float w = W - 2 * S;
float dx = w / (rowNum[row] - 1);
// float scX = _large ? 2.1 : 1.0;
float scY = _large ? 2.0 : 1.0;
float aX = _large ? 18 : 0;
return ccp( (S + col * dx) + aX, (210 - row * 56.0) * scY);
}
Хардкодинг 90 уровня. Все константы подобраны вручную, с заботой и любовью.
+131
#region GetObjectTree
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public RootNode getObjectTree() {
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DSDPortal"].ConnectionString)) {
using (SqlCommand cmd = new SqlCommand("Report.ObjectTree_Read", conn))
using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) {
cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
conn.Open();
sda.Fill(dt);
var RootObjects = (from row
in dt.AsEnumerable()
where row.Field<int>("IsAttribute") == 0 && (row.Field<string>("FullName").Split('.').Count() == 1 || !row.Field<string>("FullName").Contains('.'))
select new { Desc = row["Description"].ToString(), FullName = row.Field<string>("FullName"), Type = row.Field<string>("DataType") }).AsEnumerable();
RootNode rt = new RootNode();
foreach (var obj in RootObjects) {
TreeNode o = new TreeNode();
o.data.title = obj.Desc;
o.attr.Name = obj.FullName;
o.attr.Type = obj.Type;
o.children.AddRange(getChildTreeNode(dt, obj.FullName));
rt.data.Add(o);
}
return rt;
}
}
}
private List<TreeNode> getChildTreeNode(DataTable dt, string contextName) {
var nodes = from row
in dt.AsEnumerable()
where row.Field<string>("FullName") != contextName
&& row.Field<string>("FullName").StartsWith(contextName)
&& (contextName).Split('.').Count() + 1 == row.Field<string>("FullName").Split('.').Count()
select new {
Desc = row["Description"].ToString(),
FullName = row["FullName"].ToString(),
Type = row["DataType"].ToString()
};
List<TreeNode> items = new List<TreeNode>();
foreach (var o in nodes) {
TreeNode ob = new TreeNode();
ob.data.title = o.Desc;
ob.attr.Name = o.FullName;
ob.attr.Type = o.Type;
ob.children.AddRange(getChildTreeNode(dt, ob.attr.Name));
if (ob.children.Count == 0) {
ob.children = null;
}
items.Add(ob);
}
return items;
}
#endregion
и весь этот фарш, только чтобы распарсить строки типа PARENT_OBJECT.OBJECT.CHILD_OBJECT.ATTRIB UTE, и показать их в виде дерева, вместо того, чтобы сразу хранить иерархию по человечески :(
+88
Попытка внедрить контрол TCheckBox в заголовок 1 колонки TListView:
type
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FListHeaderWnd: HWND;
FListHeaderChk: TCheckBox;
FSaveListHeaderWndProc, FListHeaderWndProc: Pointer;
procedure ListHeaderWndProc(var Msg: TMessage);
end;
var
Form1: TForm1;
implementation
uses
commctrl;
{$R *.dfm}
function GetCheckSize: TPoint;
begin
with TBitmap.Create do
try
Handle := LoadBitmap(0, PChar(OBM_CHECKBOXES));
Result.X := Width div 4;
Result.Y := Height div 3;
finally
Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
CheckSize: TPoint;
HeaderSize: TRect;
begin
ListView1.HandleNeeded;
FListHeaderWnd := ListView_GetHeader(ListView1.Handle);
FListHeaderChk := TCheckBox.Create(nil);
CheckSize := GetCheckSize;
FListHeaderChk.Height := CheckSize.X;
FListHeaderChk.Width := CheckSize.Y;
// the below won't show anything since the form is not visible yet
ShowWindow(ListView1.Handle, SW_SHOWNORMAL); // otherwise header is not sized
windows.GetClientRect(FListHeaderWnd, HeaderSize);
FListHeaderChk.Top := (HeaderSize.Bottom - FListHeaderChk.Height) div 2;
FListHeaderChk.Left := FListHeaderChk.Top;
FListHeaderChk.Parent := Self;
windows.SetParent(FListHeaderChk.Handle, FListHeaderWnd);
FListHeaderWndProc := classes.MakeObjectInstance(ListHeaderWndProc);
FSaveListHeaderWndProc := Pointer(GetWindowLong(FListHeaderWnd, GWL_WNDPROC));
SetWindowLong(FListHeaderWnd, GWL_WNDPROC, NativeInt(FListHeaderWndProc));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLong(FListHeaderWnd, GWL_WNDPROC, NativeInt(FSaveListHeaderWndProc));
classes.FreeObjectInstance(FListHeaderWndProc);
FListHeaderChk.Free;
end;
procedure TForm1.ListHeaderWndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_COMMAND) and (HWND(Msg.LParam) = FListHeaderChk.Handle)
and (Msg.WParamHi = BN_CLICKED) then begin
FListHeaderChk.Checked := not FListHeaderChk.Checked;
// code that checks/clears all items
end;
Msg.Result := CallWindowProc(FSaveListHeaderWndProc, FListHeaderWnd,
Msg.Msg, Msg.WParam, Msg.LParam);
end;
function GetCheckSize: TPoint;
begin
with TBitmap.Create do
try
Handle := LoadBitmap(0, PChar(OBM_CHECKBOXES));
Result.X := Width div 4;
Result.Y := Height div 3;
finally
Free;
end;
end;
+153
<?if($_POST["is_ajax_post"] != "Y"){?>
<input type="hidden" name="is_ajax_post" id="is_ajax_post" value="Y">
<? } ?>
Форма оформления заказа в компоненте sale.order.ajax. Bitrix. Логика.