1. Куча / Говнокод #20865

    +1514

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    [151] ns-flow-pair-entry(n,c) ::= ns-flow-pair-yaml-key-entry(n,c)
                                    | c-ns-flow-map-empty-key-entry(n,c)
                                    | c-ns-flow-pair-json-key-entry(n,c)
    [152] ns-flow-pair-yaml-key-entry(n,c) ::= ns-s-implicit-yaml-key(flow-key)
                                               c-ns-flow-map-separate-value(n,c)
    [153] c-ns-flow-pair-json-key-entry(n,c) ::= c-s-implicit-json-key(flow-key)
                                                 c-ns-flow-map-adjacent-value(n,c)
    [154] ns-s-implicit-yaml-key(c) ::= ns-flow-yaml-node(n/a,c) s-separate-in-line?
                                       /* At most 1024 characters altogether */
    [155] c-s-implicit-json-key(c) ::= c-flow-json-node(n/a,c) s-separate-in-line?
                                       /* At most 1024 characters altogether */

    If the “?” indicator is omitted, parsing needs to see past the implicit key to recognize it as such. To limit the amount of lookahead required, the “:” indicator must appear at most 1024 Unicode characters beyond the start of the key. In addition, the key is restricted to a single line.

    Note that YAML allows arbitrary nodes to be used as keys. In particular, a key may be a sequence or a mapping. Thus, without the above restrictions, practical one-pass parsing would have been impossible to implement.


    Столкнулся, значит, с проблемой. ЙАМЛ парсер для Го не может распарсить даже примеры из спецификации.
    Заглянул в исходники - ад и погибель. Копипаста сишного кода из libyaml с косметическими изменениями. Функции по 200+ строк с кучей ифов, регулярками и т.п. Решил заглянуть в спецификацию в надежде, что может можно самому как-то... в спецификации - ад и погибель. Копипаста с грамматическими ошибками, и тьма их. Ну а как дошел до этого места, так сразу и понял, что тут уже делать больше нечего.

    wvxvw, 19 Августа 2016

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

    +452

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    const CHANGE_TYPE_ADD        = 'add';//add elem in groups
        const CHANGE_TYPE_CHANGE    = 'change';//add elem
        const CHANGE_TYPE_RECHANGE    = 'rechange';//edit elem
        const CHANGE_TYPE_EDIT        = 'edit';//delete element from groups
        const CHANGE_TYPE_DEL        = 'del';//delete element

    Кручу-верчу, запутать хочу

    _dk, 19 Августа 2016

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

    −256

    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
    var handler = new HttpClientHandler
    {
        Proxy = usingProxy ? new WebProxy(proxyURI) : null,
        UseProxy = usingProxy,
        UseCookies = true,
        CookieContainer = new CookieContainer()
    };
    
    if (session != null)
    {
        handler.CookieContainer.Add(new Uri(URL), new Cookie("PHPSESSID", session));
    }
    
    using (var client = new HttpClient(handler))
    {
        var content = new FormUrlEncodedContent(postParams);
        var responseTask = client.PostAsync(url, content);
        responseTask.Wait();
    
        var responseStringTask = responseTask.Result.Content.ReadAsStringAsync();
        responseStringTask.Wait();
    
        var cookies = handler.CookieContainer.GetCookies(new Uri(URL));
        session = cookies["PHPSESSID"].Value;
    
        return responseStringTask.Result;
    }

    Синхронный асинхронный код.

    Antibagor_100, 19 Августа 2016

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

    −320

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    string Char2Hex(char ch)
    {
    	StringWriter w = new StringWriter();
    	w.Write("\\u{0:x4}", (int)ch);
    	return w.ToString();
    }

    d_fomenok, 19 Августа 2016

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

    +366

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var organizations =
                test.ExtensionInformation.Cast<object>()
                .Select(ext => ext as GenericPair<string, string>)
                .Where(pair => pair.first == "{$idSenderOrganization}")
                .Where(pair =>
                           {
                               int o_O;
                               return int.TryParse(pair.second, out o_O);
                           })
                .Select(_ => int.Parse(_.second));

    laMer007, 19 Августа 2016

    Комментарии (7)
  6. Си / Говнокод #20860

    +262

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #define e if
    #define h while
    #define s return
    #define v NULL
    #define r else
    #define u case
    #define C switch
    #define D for
    #define L0 typedef
    #define L int
    L0 char S;L0 S*Z;L0 Z*U;L0 double N;
    L0 struct Q{L Z;union{N b;S c;}M;struct Q*w;struct Q*q;}Q;
    Q*K(L w){Q*n=(Q*)malloc(sizeof(Q));e(v==n)exit(1);n->Z=w;s n;}
    void A(Z g,U t){h(' '==*g)g++;*t=g;}
    Q*V(Z g,U t){Q*n=K(2);n->M.b=strtod(g,t);s n;}
    Q*I(Z g,U t){e('+'!=*g)s v;Q*n=K(1);n->M.c='+';++*t;s n;}
    Q*W(Z g,U t){e('x'!=*g)s v;Q*n=K(20);g++;e(*g<'0'||*g>'9'){n->M.b=1;*t=g;}r{n->M.b=strtod(g,t);e(*t==g)n->M.b=1;}s n;}
    Q*J(Z g,U t){Q*n,*p=v;h(*g){A(g,&g);Q*l=V(g,&g);A(g,&g);Q*m=W(g,&g);Q*o;e(v==m)o=l;r{o=K(1);o->M.c='*';o->w=l;o->q=m;}e(v==p)n=o;r{p->w=n;p->q=o;n=p;}A(g,&g);p=I(g,&g);e(v==p){*t=g;s n;}}}
    Q**E(Z g){L n=1,i;Z t=g;h(*t){e(';'==*t)n++;t++;}Q**R=(Q**)malloc((n+1)*sizeof(Q*));e(v==R)s v;D(i=0;i<n;++i){R[i]=J(g,&g);e(*g!=';'&&*g!=0)s v;e(v==R[i])s v;g++;}R[n]=v;s R;}
    N P(Q*I,N a){C(I->Z){u 1:C(I->M.c){u '+':s P(I->w,a)+P(I->q,a);u '*':s P(I->w,a)*P(I->q,a);u '/':s P(I->w,a)/P(I->q,a);u '-':s P(I->w,a)-P(I->q,a);}u 2:s I->M.b;u 20:s pow(a,I->M.b);}}
    N O(Q*I){N x=0,y=1,z=2,Z=P(I,x),X=P(I, y),H=P(I,z),j=1e-10;L i;D(i=0;i<100&&fabs(z-y)>j&&fabs(x-y)>j&&fabs(X)>j;i++){e(Z*X<0){z=y;H=X;}r e(H*X<0){x=y;Z=X;}r{N d=z-x;x=x-d;z=z+d;Z=P(I,x);X=P(I,y);}y=(z+x)/2;X=P(I,y);}s y;}
    Z B(Q**A){L n=0,i,j,d=0;D(;A[n]!=v;n++);Z M=(Z)malloc(n*10+1);e(v==M)s v;D(i=0;A[i]!=v;i++)D(j=0;j<10;j++){
      M[i*10+j-d]=(S)fmod(12.51*O(A[i])+j*17,256);
    e(!M[i*10+j-d])d++;}M[n*10-d]=0;s M;}
    L T(Z g,Z M){Z k=M;h(*g){*g++^=*k++;e(!*k)k=M;}s(0);}
    L main(void){
        Q**n=E("2.0x5+6.2x2+7;0.3x6.1+6x5+1");
        L i;
        Z k=B(n);
        S w[]={-91,-35,97,113,89,37,113,32,28,-10,124,67,93,32,123,70,63,-19,-71,-123,-114,45,109,64,96,57,13,7,-91,0};
        T(w,k);
        printf("%s\n",w);
    }

    Nastenka1998, 19 Августа 2016

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

    +313

    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
    <?php
    
    use PHPUnit\Framework\TestCase;
    
    class SecurityTokenTest extends TestCase
    {
    
        /**
         * @dataProvider getData
         */
        public function testGetCookieToken($user, $token, $result)
        {
            $reflect = new \ReflectionClass('AppBundle\Security\TokenCookieStorage');
            /** @var TokenCookieStorage $storage */
            $storage = $reflect->newInstanceWithoutConstructor();
    
            $reflect->getProperty('abstractUser')
                ->setValue($storage, $user);
            $reflect->getProperty('cookieDriver')
                ->setValue($storage, new class($token) {
                    public $token;
    
                    public function __construct($token)
                    {
                        $this->token = $token;
                    }
    
                    public function get($id)
                    {
                        return ($id) ? $this->token : null;
                    }
                });
    
            $this->assertSame($storage->getToken(), $result);
        }
    
    ....

    PHPUnit. Тяжело написать тесты для говнокода. Чувак не слышал про mockbuilder

    konmado, 19 Августа 2016

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

    +314

    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
    <?php
    require 'classes/_func.class.php';
    $func = new func();
    if($_SESSION['user']){
      $user_id = func::clear($_SESSION['user'],'int');
      $time = time();
      $ip = $_SERVER['REMOTE_ADDR'];
      $db->Query("UPDATE users SET last = '{$time}', ip = '{$ip}' WHERE id = '{$user_id}'");
      function stockGen($user_id){
        global $db;
        $db->Query("SELECT * FROM users WHERE id = '{$user_id}'");
        $user_data = $db->FetchArray();
        $db->Query("SELECT * FROM users_conf WHERE user_id = '{$user_id}'");
        $sub_data = $db->FetchArray();
        $data = array_merge($user_data,$sub_data);
        $day = time() - 86400;
        $db->Query("SELECT
          (SELECT ref_1 FROM users_ref WHERE user_id = '{$user_id}') ref_id,
          (SELECT COUNT(*) FROM banner_history WHERE user_id = '{$user_id}') banner_views,
          (SELECT COUNT(*) FROM link_history WHERE user_id = '{$user_id}') link_views,
          (SELECT COUNT(*) FROM users_ref WHERE ref_1 = '$user_id') referals,
          (SELECT time FROM auth WHERE user_id = '{$user_id}' ORDER BY id DESC LIMIT 1) last_auth,
          (SELECT SUM(money) FROM payments WHERE user_id = '{$user_id}' AND status = '2') pay,
          (SELECT SUM(money) FROM inserts WHERE user_id = '{$user_id}' AND status = '2') ins,
          (SELECT SUM(to_ref_1) FROM users_ref WHERE ref_1 = '{$user_id}') from_refs_1,
          (SELECT SUM(to_ref_2) FROM users_ref WHERE ref_2 = '{$user_id}') from_refs_2,
          (SELECT SUM(to_ref_3) FROM users_ref WHERE ref_3 = '{$user_id}') from_refs_3,
          (SELECT to_ref_1 FROM users_ref WHERE user_id = '{$user_id}') to_ref");
        $data += $db->FetchArray();
        $data['from_refs'] = sprintf('%.2f',$data['from_refs_1'] + $data['from_refs_2'] + $data['from_refs_3']);
        $data['all_view'] = intval($data['banner_views']) + intval($data['link_views']);
        $data['all_money'] = 0;/*sprintf('%.2f',(floatval($data['link_money']) + floatval($data['banner_money']) + floatval($data['mails_money'])))*/
        $data['all_money_day'] = 0;/*sprintf('%.2f',(floatval($data['link_money_day']) + floatval($data['banner_money_day']) + floatval($data['mails_money_day'])))*/
        $ref_id = $data['ref_id'];
        if ($ref_id != '0') {
          $db->Query("SELECT login FROM users WHERE id = '{$ref_id}'");
          $data['referer'] = $db->FetchRow();
        }else $data['referer'] = 'Пришел сам';
        $db->Query("SELECT * FROM auth WHERE user_id = '{$user_id}' ORDER BY time DESC LIMIT 10");
        if ($db->NumRows() > 0) {
          $data['auth_history'] = $db->FetchAll();
        }else $data['auth_history'] = '0';
        new gen('account/account',$data);
      }
      if(isset($url[2]) && !empty($url[2])){
        $ctrl = $func->clear($url[2]);
        $file = 'controllers/account/'.$ctrl.'Ctrl.php';
        if(file_exists($file)){
          include $file;
        }else stockGen($user_id);
      }else stockGen($user_id);
    }else header('location: /login');
    
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}') banner_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}') link_money,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}') mails_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}' AND time > '{$day}') link_money_day,
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}' AND time > '{$day}') banner_money_day,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}' AND time > '{$day}') mails_money_day,

    источник: https://toster.ru/q/346342

    riot26, 19 Августа 2016

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

    −677

    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
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
            
            let rootViewController = LAMainViewController(nibName: nil, bundle: nil)
            let navigationController = LANavigationController()
            
            let gradientLayer = CAGradientLayer()
            
            gradientLayer.colors = [UIColor.blackColor().CGColor, UIColor(hexString: "330033", alpha: 1)!.CGColor]
            gradientLayer.locations = [0, 1]
            gradientLayer.frame = window!.frame
    
            navigationController.viewControllers = [rootViewController]
            
            window!.rootViewController = navigationController
            window!.makeKeyAndVisible()
            window!.layer.insertSublayer(gradientLayer, atIndex: 0)
            
            return true
        }

    давайте слой зафигачим на окно

    grampe, 18 Августа 2016

    Комментарии (15)
  10. PHP / Говнокод #20852

    +317

    1. 1
    $this->db->query("UPDATE `" . DB_PREFIX . "order` SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($payment_country) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($payment_zone) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($payment_address_format) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "',  shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($shipping_country) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($shipping_zone) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($shipping_address_format) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', order_status_id = '" . (int)$data['order_status_id'] . "', affiliate_id  = '" . (int)$data['affiliate_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");

    Строчечка

    govnozmey, 18 Августа 2016

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