1. Objective C / Говнокод #11883

    −98

    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
    -(UIImage*) getImageForDigit:(int)value
    {
    	UIImage *img = nil;
    	
    	switch (value)
    	{
    		case -1:
    		{
    			img = [UIImage imageNamed:@"beat_0_off.png"];
    			break;
    		}
    		case 0:
    		{
    			img = [UIImage imageNamed:@"beat_0.png"];
    			break;
    		}
    		case 1:
    		{
    			img = [UIImage imageNamed:@"beat_1.png"];
    			break;
    		}
    		case 2:
    		{
    			img = [UIImage imageNamed:@"beat_2.png"];
    			break;
    		}
    		case 3:
    		{
    			img = [UIImage imageNamed:@"beat_3.png"];
    			break;
    		}
    		case 4:
    		{
    			img = [UIImage imageNamed:@"beat_4.png"];
    			break;
    		}
    		case 5:
    		{
    			img = [UIImage imageNamed:@"beat_5.png"];
    			break;
    		}
    		case 6:
    		{
    			img = [UIImage imageNamed:@"beat_6.png"];
    			break;
    		}
    		case 7:
    		{
    			img = [UIImage imageNamed:@"beat_7.png"];
    			break;
    		}
    		case 8:
    		{
    			img = [UIImage imageNamed:@"beat_8.png"];
    			break;
    		}
    		case 9:
    		{
    			img = [UIImage imageNamed:@"beat_9.png"];
    			break;
    		}
    		default:
    		{
    			break;
    		}
    	}
    	
    	return img;
    }

    Ученица отрыла простановку цифр на "кагбэ жидкокристаллический" дисплей.

    QuickNick, 06 Октября 2012

    Комментарии (10)
  2. C++ / Говнокод #11882

    +20

    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
    D:\Sources\jimbot_at_cpp>make -f Makefile.win clean-full
    rm -f *.o lib.a dist/jimbot.exe
    
    D:\Sources\jimbot_at_cpp>make -f Makefile.win lib
    gcc -c sqlite3.c -pipe -O2 -g1 DSQLITE_THREADSAFE=1
    gcc.exe: error: DSQLITE_THREADSAFE=1: No such file or directory
    make: *** [lib] Error 1
    
    D:\Sources\jimbot_at_cpp>make -f Makefile.win
    g++ -c *.cpp -std=c++0x -O2 -g1 -pipe -Wno-deprecated -Wno-write-strings -Wno-de
    precated-declarations  -DDEBUG -DEASTER -DTESTER
    g++  -o dist/jimbot -pipe *.o -O2 -g1 lib.a -lpthread -lgnutls -lwsock32 -ladvap
    i32 -lcrypt32 -lsecur32 -ldnsapi -liconv
    g++.exe: error: lib.a: No such file or directory
    make: *** [all] Error 1
    
    D:\Sources\jimbot_at_cpp>

    JavaCoder, 06 Октября 2012

    Комментарии (5)
  3. Си / Говнокод #11881

    +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
    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
    // histogram_data.c   550 Kb
    int n_records = 100000;
    unsigned char data[] = {
      215, 100, 200, 204, 233, 50 , 85 , 196, 71 , 141, 122, 160, 93 , 131, 243, 234, 162, 183, 36 , 155, 
      4  , 62 , 35 , 205, 40 , 102, 33 , 27 , 255, 55 , 131, 214, 156, 75 , 163, 134, 126, 249, 74 , 197, 
      134, 197, 102, 228, 72 , 90 , 206, 235, 17 , 243, 134, 22 , 49 , 169, 227, 89 , 16 , 5  , 117, 16 , 
      60 , 248, 230, 217, 68 , 138, 96 , 194, 131, 170, 136, 10 , 112, 238, 238, 184, 72 , 189, 163, 90 , 
      176, 42 , 112, 225, 212, 84 , 58 , 228, 89 , 175, 244, 150, 168, 219, 112, 236, 101, 208, 175, 233, 
      123, 55 , 243, 235, 37 , 225, 164, 110, 158, 71 , 201, 78 , 114, 57 , 48 , 70 , 142, 106, 43 , 232, 
      26 , 32 , 126, 194, 252, 239, 175, 98 , 191, 94 , 75 , 59 , 149, 62 , 39 , 187, 32 , 203, 42 , 190, 
      19 , 243, 13 , 133, 45 , 61 , 204, 187, 168, 247, 163, 194, 23 , 34 , 133, 20 , 17 , 52 , 118, 209, 
      146, 193, 13 , 40 , 255, 52 , 227, 32 , 255, 13 , 222, 18 , 1  , 236, 152, 46 , 41 , 100, 233, 209, 
      91 , 141, 148, 115, 175, 25 , 135, 193, 77 , 254, 147, 224, 191, 161, 9  , 191, 213, 236, 223, 212, 
      250, 190, 231, 251, 170, 127, 41 , 212, 227, 19 , 166, 63 , 161, 58 , 179, 81 , 84 , 59 , 18 , 162, 
      57 , 166, 130, 248, 71 , 139, 184, 28 , 120, 151, 241, 115, 86 , 217, 111, 0  , 88 , 153, 213, 59 , 
      172, 123, 123, 78 , 182, 46 , 159, 10 , 105, 178, 172, 163, 88 , 47 , 155, 160, 187, 84 , 189, 51 , 
      235, 175, 167, 65 , 136, 22 , 66 , 224, 175, 23 , 28 , 92 , 147, 151, 170, 73 , 198, 73 , 84 , 48 , 
      251, 0  , 211, 84 , 48 , 111, 245, 235, 195, 178, 31 , 175, 98 , 198, 241, 234, 220, 52 , 203, 140, 
     // over 5000 строк подобного
    
    int expected_results[] = {
        404,   389,   376,   394,   376,   342,   364,   364,   383,   396, 
        412,   409,   394,   409,   405,   383,   379,   401,   377,   400, 
        383,   410,   386,   383,   418,   416,   406,   349,   390,   388, 
        393,   372,   386,   386,   400,   384,   404,   355,   400,   361, 
        398,   371,   389,   383,   406,   414,   364,   389,   418,   391, 
        404,   396,   390,   397,   375,   389,   387,   392,   368,   430, 
        407,   387,   380,   380,   383,   352,   386,   413,   435,   413, 
        358,   453,   436,   409,   419,   393,   423,   398,   407,   372, 
        399,   353,   370,   389,   399,   376,   395,   439,   412,   379, 
        404,   374,   392,   393,   366,   377,   374,   395,   402,   380, 
        422,   407,   379,   398,   376,   410,   376,   392,   374,   409, 
        415,   382,   411,   398,   379,   385,   383,   374,   421,   371, 
        359,   403,   373,   396,   365,   365,   382,   383,   352,   399, 
        367,   439,   401,   418,   407,   403,   392,   373,   385,   374, 
        389,   365,   414,   415,   360,   384,   387,   381,   400,   410, 
        400,   406,   385,   395,   373,   381,   419,   362,   383,   399, 
        424,   379,   394,   401,   371,   426,   376,   375,   383,   370, 
        405,   402,   372,   404,   364,   419,   390,   376,   368,   405, 
        393,   386,   402,   393,   420,   388,   380,   364,   412,   383, 
        411,   357,   412,   377,   346,   389,   380,   371,   393,   408, 
        386,   425,   392,   338,   373,   382,   380,   365,   379,   394, 
        379,   378,   415,   394,   352,   378,   417,   403,   407,   388, 
        390,   433,   352,   394,   398,   407,   397,   409,   419,   378, 
        387,   359,   406,   384,   403,   385,   411,   418,   408,   371, 
        384,   386,   392,   422,   377,   399,   364,   381,   362,   379, 
        393,   383,   381,   400,   434,   404};
    
    // example_vectors.c - 1.8 Mb
    int vector_size=100000;
    int vector_a[] = {
      215 , 100 , 200 , 204 , 233 , 50  , 85  , 196 , 71  , 141 , 122 , 160 , 93  , 131 , 243 , 234 , 162 , 183 , 36  , 155 , 
      4   , 62  , 35  , 205 , 40  , 102 , 33  , 27  , 255 , 55  , 131 , 214 , 156 , 75  , 163 , 134 , 126 , 249 , 74  , 197 , 
      134 , 197 , 102 , 228 , 72  , 90  , 206 , 235 , 17  , 243 , 134 , 22  , 49  , 169 , 227 , 89  , 16  , 5   , 117 , 16  , 
      60  , 248 , 230 , 217 , 68  , 138 , 96  , 194 , 131 , 170 , 136 , 10  , 112 , 238 , 238 , 184 , 72  , 189 , 163 , 90  , 
      176 , 42  , 112 , 225 , 212 , 84  , 58  , 228 , 89  , 175 , 244 , 150 , 168 , 219 , 112 , 236 , 101 , 208 , 175 , 233 , 
      123 , 55  , 243 , 235 , 37  , 225 , 164 , 110 , 158 , 71  , 201 , 78  , 114 , 57  , 48  , 70  , 142 , 106 , 43  , 232 , 
      26  , 32  , 126 , 194 , 252 , 239 , 175 , 98  , 191 , 94  , 75  , 59  , 149 , 62  , 39  , 187 , 32  , 203 , 42  , 190 , 
      19  , 243 , 13  , 133 , 45  , 61  , 204 , 187 , 168 , 247 , 163 , 194 , 23  , 34  , 133 , 20  , 17  , 52  , 118 , 209 , 
      146 , 193 , 13  , 40  , 255 , 52  , 227 , 32  , 255 , 13  , 222 , 18  , 1   , 236 , 152 , 46  , 41  , 100 , 233 , 209 , 
      91  , 141 , 148 , 115 , 175 , 25  , 135 , 193 , 77  , 254 , 147 , 224 , 191 , 161 , 9   , 191 , 213 , 236 , 223 , 212 , 
      250 , 190 , 231 , 251 , 170 , 127 , 41  , 212 , 227 , 19  , 166 , 63  , 161 , 58  , 179 , 81  , 84  , 59  , 18  , 162 , 
      57  , 166 , 130 , 248 , 71  , 139 , 184 , 28  , 120 , 151 , 241 , 115 , 86  , 217 , 111 , 0   , 88  , 153 , 213 , 59  , 
      172 , 123 , 123 , 78  , 182 , 46  , 159 , 10  , 105 , 178 , 172 , 163 , 88  , 47  , 155 , 160 , 187 , 84  , 189 , 51  , 
      235 , 175 , 167 , 65  , 136 , 22  , 66  , 224 , 175 , 23  , 28  , 92  , 147 , 151 , 170 , 73  , 198 , 73  , 84  , 48  , 
    
    // over 15000 cтрок

    - Сударь, вы изволили принять наркотических средств?
    - Чего?
    - Ты что, сука, упоротый?!

    denis90, 06 Октября 2012

    Комментарии (84)
  4. Python / Говнокод #11880

    −94

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    def __call__(self, *args, **kw):
        # ...
        if args and len(args) > 1 and args[0] is args[1][0]:
            # fml...
            temp = list(args)
            temp.pop(1)
            args = tuple(temp)
        return self._execute(*args, **kw)

    Быль про архитектуру.

    wvxvw, 06 Октября 2012

    Комментарии (4)
  5. C++ / Говнокод #11879

    +29

    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
    template <class Monad>
       struct XMapM {
          template <class F, class M> struct Sig : FunType<F,M,
             typename RT<typename ::fcpp::BindM<Monad>::Type,M,typename LEType<
                LAM<LV<1>,CALL<typename ::fcpp::UnitM<Monad>::Type,
                CALL<F,LV<1> > > > >::Type>::ResultType> {};
          template <class F, class M>
          typename Sig<F,M>::ResultType
          operator()( const F& f, const M& m ) const {
             LambdaVar<1> A;
             return bindM<Monad>()( m, lambda(A)[ unitM<Monad>()[f[A]] ] );
          }
       };

    Хаскель не нужен.

    serpinski, 05 Октября 2012

    Комментарии (16)
  6. Java / Говнокод #11878

    +95

    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
    final HCons<String, HCons<Integer, HCons<Boolean, HNil>>> a =
          nil().extend(true).extend(3).extend("Foo");
        final HCons<Double, HCons<String, HCons<Integer[], HNil>>> b =
          nil().extend(new Integer[]{1, 2}).extend("Bar").extend(4.0);
    
        // A lot of type annotation
        final HAppend<HNil, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
          HCons<Double, HCons<String, HCons<Integer[], HNil>>>> zero = append();
        final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
          HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
        final HAppend<HCons<Integer, HCons<Boolean, HNil>>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
          HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> two = append(one);
        final HAppend<HCons<String, HCons<Integer, HCons<Boolean, HNil>>>,
          HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
          HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>>
          three = append(two);
    
        // And all of that lets us append one list to the other.
        final HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>
          x = three.append(a, b);
    
        // And we can access the components of the concatenated list in a type-safe manner
        System.out.println(x.head()); // Foo
        System.out.println(x.tail().tail().tail().tail().head()); // Bar

    Это вот такая она, функциональщина, упрощающая жизнь.
    http://functionaljava.googlecode.com/svn/artifacts/3.0/demo/1.5/HList_append.java

    3.14159265, 05 Октября 2012

    Комментарии (18)
  7. PHP / Говнокод #11877

    +52

    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
    foreach ($sxe->categories->category as $category) {
    			$cid = $category['id'];
    			if ($clear == 0) {
    				$query = "SELECT `id` FROM `" . PREF . "category` WHERE `id`='" . $cid . "' LIMIT 1;";
    				$result = mysql_query($query);
    				if (mysql_num_rows($result) == 0) {
    					$parent = $category['parentId'];
    					$name = quote_smart($category);
    					$query = "INSERT IGNORE INTO `" . PREF . "category` VALUES('$cid','$parent','$name','1', 0);";
    					mysql_query($query);
    				}
    			} else {
    				$parent = $category['parentId'];
    				$name = quote_smart($category);
    				$query = "INSERT IGNORE INTO `" . PREF . "category` VALUES('$cid','$parent','$name','1');";
    				mysql_query($query);
    			}
    			$cat_i++;
    		}

    uadeveloper, 05 Октября 2012

    Комментарии (8)
  8. PHP / Говнокод #11876

    +122

    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
    class xxxxxxxxxx
    {
    	
    	private $string_services;
    	
    	public  function init() {
    		$this->string_services  = '<script type="text/javascript" src="//yandex.st/share/share.js" charset="utf-8"></script>
    		<div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="yaru,vkontakte,facebook,twitter,odnoklassniki,moimir,lj,friendfeed,moikrug,gplus"></div> ';
    	}
    	
    	public function run() {
    		if(empty($this->string_services))
    		{
    			$this->init();
    		}
    		echo $this->string_services;
    	}
    }

    В нашел в проекте над которым работаю.

    Vasiliy, 05 Октября 2012

    Комментарии (4)
  9. JavaScript / Говнокод #11875

    +154

    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
    this.draw = function(scale) {
      ctx.save();
      ctx.translate(this.posX, this.posY);
      if (this.scale && this.scale < 1) ctx.scale(this.scale, this.scale);
      if (scale > 0) { 
        var boxHeight = 124.678568 + 0.394292; // ?!
        ctx.translate(0, ((boxHeight)-(scale*(boxHeight))));
        ctx.scale(scale,scale);
      }
      // вырезанный говнокод, отрисовывающий бабл в обычном масштабе
    
      ctx.restore();
    }

    Отрисовка нескольких фигур а-ля "бабл" на canvas с анимацией "выростания" бабла из своего нижнего левого угла. В метод draw передается параметр scale, содержащий значение масштаба фигуры в текущем кадре. /facepalm

    nbspjr, 05 Октября 2012

    Комментарии (1)
  10. C# / Говнокод #11874

    +138

    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
    private static T GetElementValue<T>(this XmlElement elm, string elementName, T defaultValue = default(T), bool throwIfError = false, bool throwIfMissing = false)
    			where T : IConvertible
    {
    	string val = GetElementValue(elm, elementName);
    	if (string.IsNullOrEmpty(val) == false)
    	{
    		if (typeof(T) == typeof(string))
    		{
    			return (T)(object)val;
    		}
    
    		if (typeof(T) == typeof(bool))
    		{
    			return (T)(object)(val == "1");
    		}
    
    		try
    		{
    			if (typeof(T) == typeof(DateTime))
    			{
    				return (T)(object)DateTime.Parse(val, System.Globalization.CultureInfo.InvariantCulture); ;
    			}
    
    
    			return (T)Convert.ChangeType(val, typeof(T), CultureInfo.InvariantCulture);
    		}
    		catch (Exception exc)
    		{
    			if (throwIfError)
    				throw exc;
    		}
    	}
    	if (throwIfMissing)
    		throw new ArgumentNullException("The parameter '" + elementName + "' is missing");
    
    	return defaultValue;
    }

    Используем Generics по-фэншую!

    Eugene, 05 Октября 2012

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