1. Ruby / Говнокод #8269

    −99

    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
    # Work fine only on call with has_many association
    def self.new_from_params options
      new_rule = Rule.new
      return nil if new_rule.project_id.nil?
    
      rule = Rule.find_by_id options[:rule_id]
      if rule.nil? or (new_rule.project.id != rule.project.id)
        rule = Rule.new
      end
    
      new_rule.rule_id = options[:rule_id]
      new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
      new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
      new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
      new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
      new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
      new_rule.search = options[:search].presence || rule.search.presence
      new_rule.period_start = options[:period_start].presence || rule.period_start.presence
      new_rule.period_end = options[:period_end].presence || rule.period_end.presence
    
      new_rule
     end

    emerald, 21 Октября 2011

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

    −111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function cloneString(str:String):String {
    			if(str == null) return null;
    			_byteArray.position = 0;
    			_byteArray.writeUTF(str);
    			_byteArray.position = 0;
    			var res:String =  _byteArray.readUTF();
    			// fuck yeah!
    			return res;
    		}

    суровые сибирские программисты клонируют строки like a pro

    makc3d, 21 Октября 2011

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

    +161

    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
    ...
    
      public function getLocations($fresh = 0)
        {
            $tld =& $this->varGet('tld');
            $domain =& $this->varGet('domain');
            
            // if website is viewed via IP
            $noWWWButIP =& $this->varGet('noWWWButIP');
    
            $memCacheKey = 'getLocations';
    
            if (!$fresh) {
                // already fetched and stored in vars?
                if (is_array($this->varGet('arrLocations')))
                    $arrLocations = $this->varGet('arrLocations');
                // lets try fetching from memcache
                else
                    $arrLocations = kd()->lib('kdCache')->get($memCacheKey);
            }
            // regenerate
            unset($arrLocations);
    
            if (!is_array($arrLocations)) {
    ...

    Кэшируем))

    kovel, 21 Октября 2011

    Комментарии (2)
  4. Java / Говнокод #8266

    +78

    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
    /*
             * Для операций UPDATE идентификаторы объектов должны быть уникальными.
             */
            HashMap<Long,Boolean> filterUniqueChangeObjects = new HashMap<Long, Boolean>();
            for (RepositoryObject repositoryObject : resultRepositiry) {
    			if(repositoryObject.getOperationType()  == OperationType.UPDATE) {
    				if(filterUniqueChangeObjects.containsKey(repositoryObject.getObjectId())) {
    					log.warn("Объект с идентификатором уже присутствует в обработке UPDATE " + repositoryObject.getObjectId());
    				} else {
    					resultUniqueRepositiry.add(repositoryObject);
    					filterUniqueChangeObjects.put(repositoryObject.getObjectId(), true);
    				}
    			}
    		}

    al_open, 21 Октября 2011

    Комментарии (8)
  5. JavaScript / Говнокод #8265

    +157

    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
    $(function () {
        $("#tree_cat").jstree({ 
          
          
        
          "html_data" : {
            "data" : "<ul><li id='cat_41'><a href='/cat/41'>Продажа автомобилей, спецтехники, вело, мототехники, водной техники</a><ul><li id='cat_72'><a href='/cat/72'>Автомобили легковые  новые</a></li></ul><ul><li id='cat_73'><a href='/cat/73'>Автомобили легковые  подержанные</a></li>
    ....и т.д. ....
    d='cat_146'><a href='/cat/146'>Автокредитование, лизинг</a><ul><li id='cat_147'><a href='/cat/147'>Автокредитование</a></li></ul><ul><li id='cat_148'><a href='/cat/148'>Лизинг автомобилей, техники</a></li></ul><ul><li id='cat_203'><a href='/cat/203'>Автоломбарды</a></li></ul></li></ul><ul><li id='cat_199'><a href='/cat/199'>Автострахование</a><ul><li id='cat_200'><a href='/cat/200'>Автострахование</a></li></ul></li></ul>"
          },
    
    ......
    
    if((node.attr("class") !== "jstree-open") && (node.attr("class") !== "jstree-closed") && (node.attr("class") !== "jstree-last jstree-closed")&& (node.attr("class") !== "jstree-last jstree-open")){
            window.location = this+"#cat";
          }

    Ещё один эллитный питон программист....

    DrFreez, 21 Октября 2011

    Комментарии (9)
  6. PHP / Говнокод #8264

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (asdfadfsdf != 1) {
    
    // всякий код
    
    define ('asdfadfsdf',1);
    }

    Типа проверка чтобы "всякий код" исполнялся только 1 раз...

    Tairesh, 21 Октября 2011

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

    +118

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (mainWareHouseId.HasValue && mainWareHouseId.Value.ToString() == this._locationList.SelectedValue)
    {
        return false;
    }
    else
    {
        return location == null ? true : !location.RegionalFulfillment;
    }

    abatishchev, 21 Октября 2011

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

    +159

    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
    echo "<center><br><br><form method=\"POST\" action=\"\">
      <select name=\"Data\">";
    $query="SELECT dtDate FROM Energo ORDER BY dtDate Desc"; 
    $res=mssql_query($query) or die("Ошибка запроса!"); 
    while($row = mssql_fetch_array($res))
    {
    echo "
      <option>".$row['dtDate']."</option>";
    }
    echo "</select>
      <input value=\"OK\" type=\"submit\">
    </form><center>";
    
    if(!empty($Data))
    	{
    	echo "<br><br><center><span style=\"font-weight: bold;\">Справка</span><br style=\"font-weight: bold;\">
            <span style=\"font-weight: bold;\">по ..... по состоянию на $Data г.<br><br>";
    		require_once ("tablebuh.lpd");
    		echo "<center><br><br>
    Начальник %Отдел% <img style=\"width: 50%;\"
     alt=\"\" src=\"podpis.gif\" align=\"middle\">
    К***в Н.А.<br><br>
    </center>"; 
    	}
    	
    else
    	{
    	echo "<form method=\"POST\" action=\"\">";
    	echo "<br><br><center><span style=\"font-weight: bold;\">Справка</span><br style=\"font-weight: bold;\">
            <span style=\"font-weight: bold;\">по .... по состоянию на ";
    	$query="SELECT dtDate FROM Energo WHERE id='1'"; 
    	$res=mssql_query($query) or die("Ошибка запроса!"); 
    	while($row = mssql_fetch_array($res)) 
    		{ 
    			$Data=$row['dtDate'];
    			echo $row['dtDate']."<br><br>";
    			require_once ("tablebuh.lpd");
    			echo "</center>"; 
    		}
    	echo "<center><br>
    Начальник %Отдел% <img style=\"width: 50%;\"
     alt=\"\" src=\"podpis.gif\" align=\"middle\">
    К***в Н.А.<br><br>
    ";
    
    //А вот и сам tablebuh.php
    
    <?php
    if(empty($Data))
    {
    require_once ("t2.php");
    }
    else 
    {
    require_once ("t1.php");
    }

    Хах, первый вопрос который задал себе, не пьян ли я был тогда=)
    Самое забавное, в течении 4 месяцев директор не имел никаких претензий по поводу одной и той же информации ежедневно=)

    LazyPiG, 21 Октября 2011

    Комментарии (7)
  9. bash / Говнокод #8261

    −133

    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
    #!/bin/bash
    
    ps -eo pid,ppid,comm > data
    
    #treeNet[0]=1
    
    depth=0
    
    init=0
    tree()
    {
    
    #echo $1
    let depth=depth+1
    treeNet[$depth]=1
    
    for ((i=1;i<depth-1;i++))
    do
    # echo ${treeNet[$depth]}
    if [[ ${treeNet[$i]} -eq 0 ]]
    then
    echo -n " "
    fi
    if [[ ${treeNet[$i]} -eq 1 ]]
    then
    echo -n "¦ "
    fi
    
    done
    
    if [[ $init -ne 0 ]]
    then
    echo -n '¦====='
    else
    init=1
    fi
    #let depth=depth+1
    # treeNet[depth]=1
    #prints process name
    echo $(cat data | awk '{ if ($1 == '$1') print $3}' )
    
    
    #printing branches
    local count=0 #amount of child branches
    for i in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
    do
    let count=count+1
    #echo $i
    done
    
    #recursive call tree()
    local n=0;
    for child in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
    do
    
    let n=n+1
    # echo -n " # child no $n of $count depth $depth debug ${treeNet[1]} ${treeNet[2]} ${treeNet[3]} ${treeNet[4]}"; 
    if [[ $n -eq $count ]]
    then
    #echo -n " last " 
    treeNet[$depth]=0
    fi
    # echo
    # let n=n+1
    tree $child
    done
    treeNet[$depth]=0
    
    let depth=depth-1
    return 0
    }
    
    
    tree 1

    kurganec, 21 Октября 2011

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

    +94

    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
    /**
     * Interface for string cleaners. Defines method that takes a string to perform cleaning and returns
     * cleaned string.
     * 
     * @author Король Абстракций.
     * @version 1.0 29.04.2011
     *
     */
    public interface StringCleaner {
    	//---------------------------------------------------------------------------------------------
    	/**
    	 * Cleans given string. Returns cleaned string.
    	 * @param string String to clean
    	 * @return Cleaned string
    	 * @throws NullPointerException <code>If string == null</code>
    	 * @since 1.0
    	 */
    	public String clean(String string);
    	//---------------------------------------------------------------------------------------------
    }
    
    // Далее реализации.
    
    public abstract class SymbolStringCleaner implements StringCleaner { ... }
    public final class AllSymbolStringCleaner extends SymbolStringCleaner { ... }
    public final class RepeatedSymbolStringCleaner extends SymbolStringCleaner { ... }
    public class TrimStringCleaner extends SymbolStringCleaner { ... }
    public final class CombinedStringCleaner implements StringCleaner { ... }
    
    // Пример использования.
    
    public class StringCleanerFactory {
    	private static final char END_OF_LINE_SYMBOL = '\n';
    	
    	public static synchronized StringCleaner createCommonStringCleaner() {
    		char[] symbolsToExclude = new char[] {' ', END_OF_LINE_SYMBOL};
    		StringCleaner repeatedSymbolsCleaner = new RepeatedSymbolStringCleaner(symbolsToExclude);
    		StringCleaner trimCleaner = new TrimStringCleaner(symbolsToExclude, true, true);
    		
    		CombinedStringCleaner resultCleaner = new CombinedStringCleaner();
    		resultCleaner.add(repeatedSymbolsCleaner);
    		resultCleaner.add(trimCleaner);
    		return resultCleaner;
    	}
    }
    
    // В реале выходит что-то вроде
    
    return str.trim().replace(" \n", '');

    Очистка строк огнем инквизиции еше никогда не была настолько абстрактной.


    P.S.

    Я удалял этот StringCleaner API 3 раза, и каждый раз наши адепты стринг клинеров под любым
    предлогом поднимали это г***о из анналов ада (svn history). Последний раз я сдался и этот
    ёжик теперь живет с нами.

    enikey, 21 Октября 2011

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