1. JavaScript / Говнокод #13321

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    // ==UserScript==
    // @name		GK parent comment
    // @namespace	GK
    // @description	Adds links to parent commentary to GK comments, and sets parent commentary text as link tooltip.
    // @include	http://govnokod.ru/*
    // @include	http://www.govnokod.ru/*
    // @version	1.0.0
    // @updateURL	http://userscripts.org/scripts/source/172756.meta.js
    // @downloadURL http://userscripts.org/scripts/source/172756.user.js
    // ==/UserScript==
    
    (function(){
    //hack for Chrome, as it doesn't support unsafeWindow.
    if (typeof unsafeWindow == 'undefined')
    	{
    	unsafeWindow = (function() 
    		{
    		var el = document.createElement('p');
    		el.setAttribute('onclick', 'return window;');
    		return el.onclick();
    		}())
    	};
    $ = unsafeWindow.jQuery;
    
    //dirty, DIRTY hack to wait for certain element to appear. -_- 
    //But I have no idea how to do it right.
    function waitForSelector(selector, context, mustexist, callback) {
    	var l = $(selector, context).length;
    	if ((l>0) != mustexist)
    		{
    		setTimeout(function(){waitForSelector(selector, context, mustexist, callback)}, 50);
    		return false;
    		};
    	callback();
    	}
    
    //short function for adding custom CSS rules. Why use Greasemonkey specific GM_setStyle() just for that?
    function addCSS(rule) {
    	var styleElement = document.createElement("style");
    	styleElement.type = "text/css";
    	if (typeof styleElement.styleSheet !== 'undefined')
    		styleElement.styleSheet.cssText = rule;
    	else
    		styleElement.appendChild(document.createTextNode(rule));
    	document.getElementsByTagName("head")[0].appendChild(styleElement);
    	}
    
    addCSS([
    	'.comment-parent-link {margin-left:10px;font-size:10pt}',
    	].join('/n'));
    
    var PARENT = '<a class="comment-link comment-parent-link" href="">↑</a>';
    
    var oldLoadComments = unsafeWindow.comments['load'];
    
    function newLoadComments(aElemTrigger) {
    	var $parent = $(aElemTrigger).closest('.entry-comments');
    	oldLoadComments.call(this,aElemTrigger);
    	waitForSelector('.hcomment', $parent, true, function(){
    		setParentLinks($parent);
    		});
    	}
    
    unsafeWindow.comments['load'] = newLoadComments;
    	
    function setParentLinks($context) {
    	$context.find('.hcomment').each(function(i,e){
    		var $this = $(this);
    		var $parent = $this.parents('.hcomment:eq(0)');
    		if ($parent.length) {
    			var $parentlink = $(PARENT);
    			$parentlink.attr('href', $parent.find('a.comment-link:eq(0)').attr('href'));
    			$parentlink.attr('title', $parent.find('.comment-text:eq(0)').text());
    			$this.find('a.comment-link:eq(0)').after($parentlink);
    			}
    		});
    	}
    
    setParentLinks($('body'));
    })();

    http://userscripts.org/scripts/show/172756
    По просьбам трудящихся, скрипт для поиска родительского комментария. Добавляет ссылку на родителя, и ставит его текст как тултип.
    Учитывая подключение либы с самого сайта и метод поиска динамически подгруженных комментариев, вполне себе говнокод. А потому: тов. Страйкер, вынесите уже отдельно функцию comments.loadSuccessful()! А то адский гемморой любую постобработку комментариев делать.

    Vindicar, 07 Июля 2013

    Комментарии (105)
  2. Куча / Говнокод #13320

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    <Target Inputs="@(DeployLabel)" Name="GenericDeploy" Outputs="%(Identity).Dummy">
        <PropertyGroup>
          <TargetFilter>%(DeployLabel.Dir)</TargetFilter>
          <TargetFilterReplaced>$(TargetFilter.Replace('\', ''))</TargetFilterReplaced>
        </PropertyGroup>
        <WriteLinesToFile
            File="$(ProjectDir)tsfiles.txt"
            Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filter),
                       '$(TargetFilterReplaced)'))"
            Lines="@(TypeScriptCompile -&gt;'&quot;%(fullpath)&quot;', ' ')"
            Overwrite="false" />
        <PropertyGroup>
          <TSFilesFiltered>$([System.IO.File]::ReadAllText($(ProjectDir)tsfiles.txt))</TSFilesFiltered>
          <TSFilesOneLine>$([System.Text.RegularExpressions.Regex]::Replace(
          $(TSFilesFiltered), "[\n\r]+", " "))</TSFilesOneLine>
        </PropertyGroup>
        <Exec Command="tsc --target ES3 -c -d --out $(Deployroot)\foo.js $(TSFilesOneLine)" />
        <Delete Files="$(ProjectDir)tsfiles.txt"/>
      </Target>

    Кто не был, тот будет, кто был, тот не забудет.
    MSBuild: задача отфильтровать массив из строк. Я за два дня ничего лучшего не придумал.

    wvxvw, 07 Июля 2013

    Комментарии (3)
  3. Pascal / Говнокод #13319

    +140

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    procedure TForm1.CloseChecker1Click(Sender: TObject);
    begin
    Halt;
    end;
    
    procedure TForm1.CoolTrayIcon1DblClick(Sender: TObject);
    begin
    Form1.Show;
    CoolTrayIcon1.IconVisible:=false;
    end;
    
    end.

    Продолжение. Начало на http://govnokod.ru/13317, http://govnokod.ru/13318

    Stertor, 06 Июля 2013

    Комментарии (8)
  4. Pascal / Говнокод #13318

    +139

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    procedure TMyTr.Execute;
    var
    s,resp,ip,port:string;
    cw,i:integer;
    begin
      http:=TIdHTTP.Create(nil);
      cw:=getnumberproxy;
      while cw<form1.Memo1.Lines.Count do
      begin
        s:=form1.Memo1.Lines[cw];
        i := Pos(':',s);
        IP := Copy(s,1,i-1);
        PORT := Copy(s,i+1,Length(s));
    
        try
          http.ProxyParams.ProxyServer:=ip;
          http.ProxyParams.ProxyPort:=StrToInt(port);
          http.ReadTimeout:=Form1.SpinEdit2.Value*1000;
          resp:=http.Get('http://ya.ru/');
          if pos('ya.ru',resp)<>0 then
          form1.Memo2.Lines.Add(ip+':'+port);
          except
            end;
          cw:=getnumberproxy;
          checked:=checked+1;
          end;
      http.Free;
    
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
    begin
      ind:=-1;
      label6.caption:=inttostr(Memo1.Lines.count);
      for i:=1 to spinedit1.Value do
      begin
        thr[i]:=TMyTr.Create;
        thr[i].Pause(1);
        thr[i].Resume;
      end;
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    form1.label4.caption:=IntToStr(Form1.Memo2.Lines.Count);
    Form1.Label6.Caption:=IntToStr(form1.Memo1.Lines.Count);
    Form1.Label3.Caption:=IntToStr(checked);
    
    end;
    
    
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    Form1.Memo1.Clear;
    end;
    
    procedure TForm1.Button4Click(Sender: TObject);
    begin
    Form1.Memo2.Clear;
    end;
    
    procedure TForm1.Button5Click(Sender: TObject);
    begin
    if SaveDialog1.Execute=true then
    Form1.Memo2.Lines.SaveToFile(Form1.SaveDialog1.FileName);
    end;
    
    procedure TForm1.Button3Click(Sender: TObject);
    begin
    if Form1.OpenDialog1.Execute=True
    then
    Form1.Memo1.lines.LoadFromFile(Form1.OpenDialog1.FileName);
    end;
    
    
    procedure TForm1.Button6Click(Sender: TObject);
    begin
    Form1.CoolTrayIcon1.IconVisible:=True;
    Form1.Hide;
    end;
    
    procedure TForm1.Show1Click(Sender: TObject);
    begin
    Form1.Show;
    Form1.CoolTrayIcon1.IconVisible:=false;
    end;
    
    procedure TForm1.SaveGood1Click(Sender: TObject);
    begin
    if SaveDialog1.Execute=true then
    Form1.Memo2.Lines.SaveToFile(Form1.SaveDialog1.FileName);
    
    end;
    
    procedure TForm1.ClearGood1Click(Sender: TObject);
    begin
    Form1.Memo2.Clear;
    end;

    Продолжение. Начало на http://govnokod.ru/13317

    Stertor, 06 Июля 2013

    Комментарии (2)
  5. Pascal / Говнокод #13317

    +135

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    (***************************************************************************
       _____          _ _          __          __        _     _   _____       
     / ____|        | (_)         \ \        / /       | |   | | |  __ \      
    | |     ___   __| |_ _ __   __ \ \  /\  / /__  _ __| | __| | | |__) |   _ 
    | |    / _ \ / _` | | '_ \ / _` \ \/  \/ / _ \| '__| |/ _` | |  _  / | | |
    | |___| (_) | (_| | | | | | (_| |\  /\  / (_) | |  | | (_| |_| | \ \ |_| |
     \_____\___/ \__,_|_|_| |_|\__, | \/  \/ \___/|_|  |_|\__,_(_)_|  \_\__,_|
                                __/ |                                         
                               |___/                                          
    *****************************************************************************)
    (*****************************************************************************
    
     Автор программы - CraftR14
     Исходники предоставлены для форума CodingWorld.Ru
    
    
    *****************************************************************************)
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
       gsvThread, idhttp,  Spin,  ShellAPI, Menus, CoolTrayIcon, Dialogs,
      ExtCtrls, StdCtrls;
         type
      TForm1 = class(TForm)
        Memo1: TMemo;
        SpinEdit1: TSpinEdit;
        Button1: TButton;
        Memo2: TMemo;
        Label5: TLabel;
        Label6: TLabel;
        Timer1: TTimer;
        SpinEdit2: TSpinEdit;
        Label1: TLabel;
        Label4: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Button2: TButton;
        Button3: TButton;
        GroupBox1: TGroupBox;
        GroupBox2: TGroupBox;
        Button4: TButton;
        Button5: TButton;
        GroupBox3: TGroupBox;
        GroupBox4: TGroupBox;
        Label7: TLabel;
        Label8: TLabel;
        GroupBox5: TGroupBox;
        SaveDialog1: TSaveDialog;
        OpenDialog1: TOpenDialog;
        Bevel1: TBevel;
        Button6: TButton;
        CoolTrayIcon1: TCoolTrayIcon;
        PopupMenu1: TPopupMenu;
        PopupMenu2: TPopupMenu;
        Show1: TMenuItem;
        SaveGood1: TMenuItem;
        ClearGood1: TMenuItem;
        CloseChecker1: TMenuItem;
        Label9: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure Button5Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button6Click(Sender: TObject);
        procedure Show1Click(Sender: TObject);
        procedure SaveGood1Click(Sender: TObject);
        procedure ClearGood1Click(Sender: TObject);
        procedure CloseChecker1Click(Sender: TObject);
        procedure CoolTrayIcon1DblClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      TMyTr = class(TgsvThread)
        http:TidHttp;
      protected
        procedure Execute; override;
      end;
    
    var
      Form1: TForm1;
      ind:integer=-1;
      thr: array [1..900] of TMyTr;
      checked:Integer=0;
    implementation
    
    {$R *.dfm}
    
    function getnumberproxy:integer;
    begin
      if ind<>form1.Memo1.Lines.Count then
      inc(ind);
      result:=ind;
    end;

    Вот эта вот, херня ходит по интернету и называется "Прокси-чеккер". Особо умилило то, что автор каким-то макаром приплел сюда GSVthreads.

    Stertor, 06 Июля 2013

    Комментарии (13)
  6. Pascal / Говнокод #13316

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // Delpih 7 отказывается компилировать этот код, тогда как в Delphi 2010 он вполне успешно компилируется.
    // Отчего это?
    
    for pthread in lst do
    ...
    
    >>[Error] Unit1.pas(89): Operator not applicable to this operand type

    Stertor, 06 Июля 2013

    Комментарии (40)
  7. Python / Говнокод #13315

    −95

    1. 1
    2. 2
    3. 3
    4. 4
    obj.serialized_data = str(serialized_data).replace(
                        " u'", " '").replace("{u'", "{'").replace(" '", ' "').replace("':", '":').replace(
                        "{'", '{"').replace("', ", '", ').replace("'}", '"}').replace(' True,', ' true,').replace(
                        'None', 'null').replace(' False,', 'false,')

    Сериализация словаря

    Crazyzubr, 05 Июля 2013

    Комментарии (7)
  8. C# / Говнокод #13314

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    using System;
    using System.Security.Cryptography;
    
    namespace sha1_calc
    {
        class Program
        {
            static void Main(string[] args)
            {
                SHA1 sha = new SHA1CryptoServiceProvider();
                foreach (var fname in args)
                {
                    Console.WriteLine("file: " + fname);
                    try
                    {
                        System.IO.FileStream fs = System.IO.File.Create(fname);
                        byte [] res = sha.ComputeHash(fs);
                        fs.Close();
                        Console.Write("0x");
                        foreach (var i in res)
                        {
                            Console.Write(i.ToString("X"));
                        }
                        Console.WriteLine();
                        Console.WriteLine("---------------------------------");
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine("error: " + e);
                    }
                }
                Console.ReadKey();
            }
        }
    }

    Скачал парочку образов и решил проверить их чексуммы. Протестировал программу на скачанных файлах. Удивился, почему же у них хеши одинаковые?

    Xom94ok, 05 Июля 2013

    Комментарии (103)
  9. Objective C / Говнокод #13313

    −103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    - (void)updateRating 
    {
        [NSObject cancelPreviousPerformRequestsWithTarget:self
                                                 selector:@selector(delayedUpdateRating)
                                                   object:nil];
        [self performSelector:@selector(delayedUpdateRating)
                   withObject:nil
                   afterDelay:0];
    }

    Коллега занес покушать.
    Большой проект, для американцев, пишут ребята из Днепра...

    clockworkman, 05 Июля 2013

    Комментарии (11)
  10. Куча / Говнокод #13309

    +124

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    [% FOREACH i IN DYN_DATE_OPT %]
    <td class="number [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_COMMIFY( distr_row.lic.$i ) || 0 %]</td>
    [% UNLESS DYN_PARAMS.display_unprocent %]
    <td class="number right_b [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_PERCENT( distr_row.lic.$i, distr_row.commonper.$i ) %]</td>
    [% END %]
    <td class="number left_b [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_COMMIFY( distr_row.gsn_lic.$i ) || 0 %]</td>
    [% UNLESS DYN_PARAMS.display_unprocent %]
    <td class="number right_b [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_PERCENT( distr_row.gsn_lic.$i, distr_row.gsnper.$i ) %]</td>
    [% END %]
    <td class="number left_b [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_COMMIFY( distr_row.lic_ov.$i, 'red' ) || 0 %]</td>
    [% UNLESS DYN_PARAMS.display_unprocent %]
    <td class="number [% IF loop.count mod 2 != 0 %]odd[% END %] distri_td" [% distri_style %]>[% DYN_FILTER_PERCENT( distr_row.lic_ov.$i, distr_row.gsnper.$i ) %]</td>
    [% END %]
    [% END %]

    Template::Toolkit

    236 вот такого вот шаблона. Во всём сервисе их пачка, и все аналогичны.

    kainwinterheart, 05 Июля 2013

    Комментарии (10)