1. Си / Говнокод #17534

    +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
    void MSSequencerPatternCopyToMusicTrack(MSSequencerPatternRef self, MusicTrack track)
    {
        // Get signature and length of pattern
        TimeSignature sign   = MSSequencerPatternGetTimeSignature(self);
        CABarBeatTime length = pattern_barbeat_duration_without_mutes(self);
        CABarBeatTime insert = CABarBeatTime(1, 1);
        // Get muted beats
        CFRange *mutedBeats = (CFRange*)CFDataGetBytePtr(self->mutedBeats);
        CFIndex  mutedCount = CFDataGetLength(self->mutedBeats) / sizeof(CFRange);
        // Copy with muted regions
        if (mutedCount > 0)
        {
            // Clear output track
            MSSequencerTrackClear(self->parent, track);
            // Copy phrase by phrase
            for (int i = 0; i < mutedCount; ++i)
            {
                CFRange muteRange  = mutedBeats[i];
                CFIndex beatsCount = (sign.numerator * sign.denominator);
                
                if ((beatsCount * (i + 1)) > muteRange.location + muteRange.length)
                {
                    if (muteRange.length > 0)
                    {
                        // Copy beats before mute range
                        if (muteRange.location > (beatsCount * i))
                        {
                            CFIndex start = (beatsCount * i);
                            CFIndex end   = muteRange.location;
                            insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                        }
                        // Copy beats after range
                        {
                            CFIndex start = (muteRange.location + muteRange.length);
                            CFIndex end   = (beatsCount * (i + 1));
                            insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                        }
                    }
                    else
                    {
                        // Copy without mutes
                        CFIndex start = (beatsCount * i);
                        CFIndex end   = (beatsCount * (i + 1));
                        insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                    }
                }
                else
                {
                    // Copy beats
                    CFIndex firstBeat = (muteRange.location + muteRange.length) % beatsCount;
                    CABarBeatTime start = CABarBeatTimeAddBeats(CABarBeatTime(1, 1), sign, (beatsCount * i) + firstBeat);
                    CABarBeatTime end   = CABarBeatTimeAddBeats(start, sign, (beatsCount - muteRange.length));
                    copy_beats_from_pattern_to_track(self, track, start, end, insert);
                    //CFLog("start: {%i, %i}, end: {%i, %i}, insert: {%i, %i}", (int)start.bar, (int)start.beat, (int)end.bar, (int)end.beat, (int)insert.bar, (int)insert.beat);
                    // Update insert time
                    insert = CABarBeatTimeAddBeats(insert, sign, (beatsCount - muteRange.length));
                }
            }
        }
        // Copy without muted regions
        else
        {
            copy_beats_from_pattern_to_track(self, track, insert, length, insert);
        }
        //CAShow(track);
    }

    Вот такая вот какашечка...

    gerasim13, 28 Января 2015

    Комментарии (0)
  2. Objective C / Говнокод #17533

    −388

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    - (void) setLevel:(NSInteger)level {
        if (level > (long)[_ranksDictionary count] - 1) level = (long)[_ranksDictionary count] - 1;
        if (level < 0) level = 0;
    
        _level = level;
        
        self.currentRank = [_ranksDictionary objectForKey:[NSNumber numberWithInteger:_level]];
        
        if (rankDataItem.integerValue != -_level)
            rankDataItem.integerValue = _level;
    }

    Я совсем хуевый?

    ExT, 28 Января 2015

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;
        label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
        progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
    }

    Вычилсяем проценты :D

    Xekep, 28 Января 2015

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

    −113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    def convert_get_to_post(header='HTTP_X_GET_DATA'):
        def decorator(function):
            @wraps(function)
            def wrapper(request, *args, **kwargs):
                if header in request.META:
                    request.method = 'GET'
                    request.GET = request.POST
                return function(request, *args, **kwargs)
            return wrapper
        return decorator

    Как избежать проблему с большим количеством параметров в URL при GET запросе...

    winter, 27 Января 2015

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

    +51

    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
    static bool convertCharToHexByte(char& ch)
    {
    	if (ch >= '0' && ch <= '9') {
    		ch -= '0';
    		return true;
    	}
    
    	if (ch >= 'a' && ch <= 'f') {
    		ch -= 'a';
    		ch += 0xA;
    		return true;
    	}
    
    	if (ch >= 'A' && ch <= 'F') {
    		ch -= 'A';
    		ch += 0xA;
    		return true;
    	}
    
    	return false;
    }

    alek0585, 27 Января 2015

    Комментарии (29)
  6. ActionScript / Говнокод #17529

    −89

    1. 1
    2. 2
    3. 3
    4. 4
    private static function isNumber(value: String): Boolean
    {
    	return !ArrayUtils.isEmpty(value.match(/\d/));
    }

    Не синтетика!

    wvxvw, 27 Января 2015

    Комментарии (0)
  7. ActionScript / Говнокод #17528

    −84

    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
    /**
     		 * returns file size in bytes/Kb/Mb/Gb
    -		 * 
    -		 * @param  bytes 
    +		 *
    +		 * @param  bytes
     		 */
     		public static function formatFileSize(bytes: uint): String
     		{
     			if (bytes < 1024)
    -				return bytes + " bytes";
    +			{
    +				return bytes + SPACE_STRING + "bytes";
    +			}
     			else
     			{
     				bytes /= 1024;
     				if (bytes < 1024)
    -					return bytes + " Kb";
    +				{
    +					return bytes + SPACE_STRING + "Kb";
    +				}
     				else
     				{
     					bytes /= 1024;
     					if (bytes < 1024)
    -						return bytes + " Mb";
    +					{
    +						return bytes + SPACE_STRING + "Mb";
    +					}
     					else
     					{
     						bytes /= 1024;
     						if (bytes < 1024)
    -							return bytes + " Gb";
    +						{
    +							return bytes + SPACE_STRING + "Gb";
    +						}
     					}
     				}
     			}
     			return String(bytes);
     		}

    Все те же утилиты.

    wvxvw, 27 Января 2015

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

    +54

    1. 1
    2. 2
    _defaultLog
    #include "stdafx.h"

    Это первые две строчки в C++ файле. Сам файл включен файл проекта. Ошибок компиляции нет. Сегодня удалю эту первую строку. В комментариях к комиту с этим изменением в свн написано: "Исправление дидлока".

    laMer007, 27 Января 2015

    Комментарии (14)
  9. Python / Говнокод #17526

    −110

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # количество гласных в строке
    vowelsCount = lambda s: sum([1 for x in s if x in ['i','a','e','o','u']])
    # Вхождение подстроки в строку
    substringOccurence = lambda S,s:sum([1 for i in range(len(S) + 1 - len(s)) if S[i:i + len(s)] == s])
    g = lambda S,s:'Number of times ' + substr + ' occurs is: ' + str(substringOccurence(S,s))
    # первая из упорядоченных подстрок максимальной длины
    alpha = lambda s:  [x for x in  
       [s[i:i + j] for j in range(len(s),0,-1)for i in range(len(s) - j + 1)]
        if x == ''.join(sorted(x))][0]
    # atoi без atoi
    stringToInteger = lambda s: sum([(ord(n) - ord('0')) * (10 ** i) for i,n in enumerate(s[::-1])])

    Питонячьи извращения для одного курса или не все однострочники одинаково полезны.

    wowsuchdoge, 27 Января 2015

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

    −127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    //200114		
    //ОбластьКонОстаткиДоговор.Параметры.ПеременныйДоговор = ВыборкаДоговор.Договор;  //Убери рем когда договор опять нужен будет 
    
    //210014
    //ОбластьКонОстаткиДоговор.Параметры.ПеенныйДоговор = ВыборкаДоговор.Договор;  //Убери рем когда договор опять нужен будет

    Пенный договор вновь вступил в силу..

    gStill, 27 Января 2015

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