- 1
- 2
- 3
- 4
for (int i = 0; i < 40; i++)
{
GC.Collect();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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. Логика.
+148
<div id="html-header">
<!--Начало этого долбаного скрипта-->
<Sсгiрt>
<!--
var checkpass=''''
tell=0
counttimes=0
disComp=0
function preferences(encryptpass,encryptdepth,what,dis){
disComp=dis
tell=0
tell=what
checkpass=''''
counttimes=0
times=encryptdepth
checkpass=encryptpass
orig=''''
this.check=mkasci
}
bases=new Array(17,33,57,101);
var acharset=''XYZNOhijkVWHIJ45ncdefMyzopqPQRSTUABKL6789ab_rs23CDEFGlmwtuvg01x''
var storeup='''';
function mkasci(orig){
if(counttimes==0){storeup=orig}
ascival=new Array()
for(i=0;i<=orig.length-1;i++){
for(i1=0;i1<=acharset.length;i1++){
if(orig.charAt(i)==acharset.charAt(i1)){ascival=i1}
}
}
themeat(ascival)
}
function cutoff(code){
eval("var whatcode=''"+code+"''");
eval("var whatcode2=''"+Math.ceil(code)+"''");
bigVal=(Math.pow(10,whatcode.length-(whatcode2.length)-2)<1)?1:Math.pow(10,whatcode.length-(whatcode2.length)-2);
whatcode3=Math.round(code*bigVal)/bigVal
return(whatcode3)
}
function themeat(basecode){
if(basecode.length>=4){
counttimes++
if(disComp==1){windоw.status="Computating encryption level "+counttimes+"/"+times}
newcode=0
finalcode=1
for(count=0;count!=basecode.length;count++){
newcode=(basecode[(count<(basecode.length-1))?count+1:count-2]+(basecode[count]*bases[2])*(2.303)+basecode[Math.round(((basecode.length-1)*((Math.atan(basecode[(count!=0)?count-1:count+1])*basecode.length)+2*bases[0]))/100)]+1)
newcode=cutoff(newcode)
newcode=(newcode>basecode[Math.round(basecode.length/2)])?newcode-=bases[3]:newcode+=bases[3]
finalcode=cutoff(((newcode/10)*finalcode)/(basecode.length-bases[0]))
}
var deconstruct=''''
eval(''var finalcode="''+(finalcode+times)+''"'');
for(count=0;count<finalcode.length;count++){
if(!isNaN(finalcode.charAt(count))){
deconstruct=deconstruct+finalcode.charAt(count)
}
}
finalcode=deconstruct
var encrypt=new Array()
for(count=2;count<finalcode.length+2;count+=2){
eval("encrypt["+((count/2)-1)+"]=''"+((finalcode.charAt(count-2)!=''0'')?finalcode.charAt(count-2):'''')+""+finalcode.charAt(count-1)+"''")
encrypt[((count/2)-1)]=acharset.charAt(Math.round((acharset.length*encrypt[((count/2)-1)])/100))
}
encrypt=encrypt.join('''')
if(counttimes<times){mkasci(encrypt)} else {
counttimes=0
if(encrypt==checkpass&&tell==0){а1егt(''OK! Password '');1осаtiоn.replace(storeup+encrypt.substring(0,5)+".html");} else {
if(tell==1){dосиmеnt.write("<B>"+storeup+"</B> is encrypted as <B>"+encrypt+"</B>");} else {
if(history.length>0){
а1егt("ERROR! Password ");
history.go(-1);
} else {1осаtiоn.replace("err.html")}
}
}
}
} else {
if(history.length>0){
а1егt("ERROR! Password ");
history.go(-1);
} else {1осаtiоn.replace("vhod.html")}
}
}
password=new preferences(''s_mkAi_Z'',15,0,1);
var enter='''';
while(enter.length<4){
enter=ргоmрt(''Enter Password PAROL '','''');
if(!enter){enter='' ''}
}
password.check(enter);
</Sсгiрt>
<!--конец этого долбаного скрипта-->
</div>
Гк, однако.
+142
/* 3.0.17-73642 */
!function(){function createCookie(a,b,c){if(c){var d=new Date;d.setTime(d.getTime()+1000*60*60*24*c);var e="; expires="+d.toGMTString();}else{var e="";}document.cookie=a+"="+b+e+"; path=/";}function readCookie(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d<c.length;d++){for(var e=c[d];" "==e.charAt(0);){e=e.substring(1,e.length);}if(0==e.indexOf(b)){return e.substring(b.length,e.length);}}return null;}function eraseCookie(a){createCookie(a,"",-1);}var requirejs,require,define;!function(a){function b(a,b){var c,d,e,f,g,h,i,j=b&&b.split("/"),k=m.map,l=k&&k["*"]||{};if(a&&"."===a.charAt(0)&&b){for(j=j.slice(0,j.length-1),a=j.concat(a.split("/")),g=0;i=a[g];g++){if("."===i){a.splice(g,1),g-=1;}else{if(".."===i){if(1===g&&(".."===a[2]||".."===a[0])){return !0;}g>0&&(a.splice(g-1,2),g-=2);}}}a=a.join("/");}if((j||l)&&k){for(c=a.split("/"),g=c.length;g>0;g-=1){if(d=c.slice(0,g).join("/"),j){for(h=j.length;h>0;h-=1){if(e=k[j.slice(0,h).join("/")],e&&(e=e[d])){f=e;break;}}}if(f=f||l[d]){c.splice(0,g,f),a=c.join("/");break;}}}return a;}function c(b,c){return function(){return j.apply(a,o.call(arguments,0).concat([b,c]));};}function d(a){return function(c){return b(c,a);};}function e(a){return function(b){k[a]=b;};}function f(b){if(l.hasOwnProperty(b)){var c=l[b];delete l[b],n[b]=!0,i.apply(a,c);}if(!k.hasOwnProperty(b)){throw new Error("No "+b);}return k[b];}function g(a,c){var e,g,h=a.indexOf("!");return -1!==h?(e=b(a.slice(0,h),c),a=a.slice(h+1),g=f(e),a=g&&g.normalize?g.normalize(a,d(c)):b(a,c)):a=b(a,c),{f:e?e+"!"+a:a,n:a,p:g};}function h(a){return function(){return m&&m.config&&m.config[a]||{};};}var i,j,k={},l={},m={},n={},o=[].slice;i=function(b,d,i,j){var m,o,p,q,r,s,t=[];if(j=j||b,"function"==typeof i){for(d=!d.length&&i.length?["require","exports","module"]:d,s=0;s<d.length;s++){if(r=g(d[s],j),p=r.f,"require"===p){t[s]=c(b);}else{if("exports"===p){t[s]=k[b]={},m=!0;}else{if("module"===p){o=t[s]={id:b,uri:"",exports:k[b],config:h(b)};}else{if(k.hasOwnProperty(p)||l.hasOwnProperty(p)){t[s]=f(p);}else{if(r.p){r.p.load(r.n,c(j,!0),e(p),{}),t[s]=k[p];}else{if(!n[p]){throw new Error(b+" missing "+p);}}}}}}}q=i.apply(k[b],t),b&&(o&&o.exports!==a&&o.exports!==k[b]?k[b]=o.exports:q===a&&m||(k[b]=q));}else{b&&(k[b]=i);}},requirejs=require=j=function(b,c,d,e){return"string"==typeof b?f(g(b,c).f):(b.splice||(m=b,c.splice?(b=c,c=d,d=null):b=a),c=c||function(){},e?i(a,b,c,d):setTimeout(function(){i(a,b,c,d);},15),j);},j.config=function(a){return m=a,j;},define=function(a,b,c){b.splice||(c=b,b=[]),l[a]=[a,b,c];},define.amd={jQuery:!0};}(),define("../vendor/almond",function(){}),fortyone=new function(){this.e=new Date(2005,0,15).getTimezoneOffset(),this.f=new Date(2005,6,15).getTimezoneOffset(),this.plugins=[],this.d={Flash:["ShockwaveFlash.ShockwaveFlash",function(a){return a.getVariable("$version");}],Director:["SWCtl.SWCtl",function(a){return a.ShockwaveVersion("");}]},this.r=function(a){var b;try{b=document.getElementById(a);}catch(c){}if(null===b||"undefined"==typeof b){try{b=document.getElementsByName(a)[0];}catch(d){}}if(null===b||"undefined"==typeof b){for(var e=0;e<document.forms.length;e++){for(var f=document.forms[e],g=0;g<f.elements.length;g++){var h=f[g];if(h.name===a||h.id===a){return h;}}}}return b;},this.b=function(a){var b="";try{"undefined"!=typeof this.c.getComponentVersion&&(b=this.c.getComponentVersion(a,"ComponentID"));}catch(c){a=c.message.length,a=a>40?40:a,b=escape(c.message.substr(0,a));}return b;},this.exec=function(b){for(var c=0;c<b.length;c++){try{var d=eval(b[c]);if(d){return d;}}catch(e){}}return"";},this.p=function(a){var b="";try{if(navigator.plugins&&navigator.plugins.length){var c=RegExp(a+".* ([0-9._]+)");for(a=0;a<navigator.plugins.length;a++){var d=c.exec(navigator.plugins[a].name);null===d&&(d=c.exec(navigator.plugins[a].description)),d&&(b=d[1]);}}else{if(window.ActiveXObject&&this.d[a]){try{var e=new ActiveXObject(this.d[a][0]);b=this.d[a][1](e);}catch(f){b="";}}}}catch(g){b=g.message;}return b;},this.q=function(){for(var a=["Acrobat","Flash","QuickTime","Java Plug-in","Director","Office"],b=0;b<a.length;b++){var c=a[b];this.plugins[c]=this.p(c);}},this.g=function(){return Math.abs(this.e-this.f);},this.h=function(){return 0!==this.g();},this.i=function(a){var b=Math.min(this.e,this.f);return this.h()&&a.getTimezoneOffset()===b;},this.n=function(a){var b=0;return b=0,this.i(a)&&(b=this.g()),b=-(a.getTimezoneOffset()+b)/60;},this.j=function(a,b,c,d){"boolean"!=typeof d&&(d=!1);for(var e,f=!0;(e=a.indexOf(b))>=0&&(d||f);){a=a.substr(0,e)+c+a.substr(e+b.length),f=!1;}return a;},this.m=function(){return new Date(2005,5,7,21,33,44,888).toLocaleString();},this.k=function(b){var c=new Date,d=[function(){return"TF1";},function(){return"015";},function(){return ScriptEngineMajorVersion();},function(){return ScriptEngineMinorVersion();},function(){return ScriptEngineBuildVersion();},function(a){return a.b(
йарасна зажыгаюць
+161
static function anyToTimestamp($date) {
// 2009-09-03 12:10:55
if (preg_match('/^([0-9]{4})\-([0-9]{2})\-([0-9]{2})(?: ([0-9]{2})\:([0-9]{2})\:([0-9]{2}))?$/', $date, $arr)) {
$ts = mktime($arr[4], $arr[5], $arr[6], $arr[2], $arr[3], $arr[1]);
// 03.04.2008 10:12:11
} elseif (preg_match('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})(?: ([0-9]{1,2})\:([0-9]{1,2})(?:\:([0-9]{2}))?)?$/', $date, $arr)) {
$ts = mktime($arr[4], $arr[5], $arr[6], $arr[2], $arr[1], $arr[3]);
// MySQL timestamp YYYYMMDDHHMISS
} elseif (preg_match('/^\d{14}$/', $date)) {
$ts = mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2), substr($string, 6, 2),
substr($string, 0, 4));
// PHP timestamp
} elseif (is_int($date)) {
$ts = $date;
// давно заметил, что предыдущее условие не всегда срабатывает. добавил условие ниже. если передается timestamp 100% сработает
}elseif(strlen((int)$date)>=10 && is_int((int)$date)) {
$ts = $date;
}
return ($ts && $ts!=-1)?$ts:null;
}
Копаюсь как обычно в проекте, а этот довольно большой на протяжении нескольких лет над ним трудились разные программисты.
Причем бывает читаю смешные комментарии.
Однако весь смысл не в этом как вы уже поняли.
−110
struct testStruct
{
char test[1024*1024*110];
};
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
logMemUsage();
testStruct* test = new testStruct();
NSLog(@"test mem: %d", sizeof(test));
logMemUsage();
delete test;
logMemUsage();
<...>
}
Особенности управления памятью в iOS 6.
Без этого фрагмента на слабых устройствах может ВНЕЗАПНО понизить объём доступной для приложения памяти со 120 до 90мб.
Почему-то не порнографических ассоциаций не возникает.