1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. C# / Говнокод #11873

    +104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    283: public static IList<Service> MultithreadHostCheckImplementation(string userName, string userPassword, string clientName, string serviceName, int iImplType, string samsungAccessToken,
    			bool checkSamsungAccountInCustomProps,string clientSoftware,string decryptedInstallKey,
    			out Guid userRefId, out string subscriptionId, out bool isIPhoneUser, out string serviceHostHeader)
             {
                 //....
    783: }

    Русский код. Ровно 500 строк отборного!

    Eugene, 05 Октября 2012

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

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if($_POST['gtype'] == "" || $_POST['ip'] == "" || $_POST['c_port'] == "" || $_POST['q_port'] == "" || $_POST['s_port'] == "" || $_POST['zone'] == "" || $_POST['disabled'] == "") $msg = '<div class="status error"><p><img src="./template/images/icons/icon_error.png" alt="Error"><span>Ошибка!</span>.</p></div>';
    		else
    		{
    			mysql_query('INSERT INTO lgsl(type,ip,c_port,q_port,s_port,zones,disabled,comment) VALUES(\'' .$_POST['type']. '\',\'' .$_POST['ip']. '\',\'' . $_POST['c_port'] . '\', \'' .$_POST['q_port']. '\', \'' .$_POST['s_port']. '\', \'' .$_POST['zone']. '\', \'' .$_POST['disabled']. '\', \'' .$_POST['comment']. '\')', $con);
    			$msg = '<div class="status success"><p><img src="./template/images/icons/icon_success.png" alt="Sėkmingai"><span>Įrašyta!</span> Serveris sėkmingai pridėtas.</p></div>';
    		}

    как-то так...

    nonamez, 04 Октября 2012

    Комментарии (27)
  10. JavaScript / Говнокод #11871

    +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
    let origOverviewShow;
    
    function onOverviewShow() {
        /* ... */
        Lang.bind(Main.overview, origOverviewShow)();
    }
    
    function enable() {
        /* ... */
        origOverviewShow = Overview.Overview.prototype.show;
        Overview.Overview.prototype.show = onOverviewShow;
    }

    https://github.com/rat4/layoutperwindow/blob/master/layoutperwindow%40rat4.github.com/extension.js

    rat4, 04 Октября 2012

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