1. PHP / Говнокод #20401

    +2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    public function addBankAccount(
    						$firstName, $lastName, $companyName, $phone, $addressId, $bankName, $bankSwiftCode, $bankStreet,$bankCity, $bankCountry, $bankState, $bankPostalCode,
    						$bankAccountNumber, $currency, $bankRoutingCode, $accountType, $bankAccountType, $intermediaryName, $intermediaryStreet,
    						$intermediaryCountry, $intermediaryState, $intermediaryCity, $intermediaryPostalCode, $intermediarySwift, $intermediaryCodeBank, $intermediaryFurtherAccount, $intermediaryBank
    						)
    	{
    		$key = md5(sprintf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
    			$this->encryptedPassword, $firstName, $lastName, $companyName,
    			$phone, $addressId, $bankName, $bankSwiftCode, $bankStreet, $bankCity,
    			$bankState, $bankCountry, $bankPostalCode, $bankAccountNumber, 
    			$currency, $bankRoutingCode, $bankAccountType, $accountType, 
    			$intermediaryName, $intermediaryStreet, $intermediaryCountry, 
    			$intermediaryState, $intermediaryCity, $intermediaryPostalCode, 
    			$intermediarySwift, $intermediaryCodeBank, $intermediaryFurtherAccount, $intermediaryBank
    		));
    
    		// Prepare the request
    
    		$req  = sprintf("method=%s", urlencode("addBankAccount"));
    		$req .= sprintf("&fromEmail=%s", urlencode($this->fromEmail));
    		$req .= sprintf("&firstName=%s", urlencode($firstName));
    		$req .= sprintf("&lastName=%s", urlencode($lastName));
    		$req .= sprintf("&companyName=%s", urlencode($companyName));
    		$req .= sprintf("&phone=%s", urlencode($phone));
    		$req .= sprintf("&addressId=%s", urlencode($addressId));
    		$req .= sprintf("&bankName=%s", urlencode($bankName));
    		$req .= sprintf("&bankSwiftCode=%s", urlencode($bankSwiftCode));
    		$req .= sprintf("&bankStreet=%s", urlencode($bankStreet));
    		$req .= sprintf("&bankCity=%s", urlencode($bankCity));
    		$req .= sprintf("&bankCountry=%s", urlencode($bankCountry));
    		$req .= sprintf("&bankState=%s", urlencode($bankState));
    		$req .= sprintf("&bankPostalCode=%s", urlencode($bankPostalCode));
    		$req .= sprintf("&bankAccountNumber=%s", urlencode($bankAccountNumber));
    		$req .= sprintf("&currency=%s", urlencode($currency));
    		$req .= sprintf("&bankRoutingCode=%s", urlencode($bankRoutingCode));
    		$req .= sprintf("&accountType=%s", urlencode($accountType));
    		$req .= sprintf("&bankAccountType=%s", urlencode($bankAccountType));
    		$req .= sprintf("&intermediaryName=%s", urlencode($intermediaryName));
    		$req .= sprintf("&intermediaryStreet=%s", urlencode($intermediaryStreet));
    		$req .= sprintf("&intermediaryCountry=%s", urlencode($intermediaryCountry));
    		$req .= sprintf("&intermediaryState=%s", urlencode($intermediaryState));
    		$req .= sprintf("&intermediarySwift=%s", urlencode($intermediarySwift));
    		$req .= sprintf("&intermediaryCodeBank=%s", $intermediaryCodeBank);
    		$req .= sprintf("&intermediaryFurtherAccount=%s", urlencode($intermediaryFurtherAccount));
    		$req .= sprintf("&intermediaryBank=%s", $intermediaryBank);
    		$req .= sprintf("&key=%s", urlencode($key));
    
    		// the following two lines are for testing only (in production they should be commented out)
    		//$req .= sprintf("&sandbox=ON");
    		//$req .= sprintf("&return=%s", urlencode("51"));
    
    		$res = $this->process($req);
    
    		// TODO: Parse the response from server and return error code
    		printf("<textarea cols=\"60\" rows=\"10\" wrap=\"off\">\n%s\n</textarea>\n", $res);
    	}
    
    	protected function process($req)
    	{
    		$header  = "POST /payment/api/paymentAPI.php HTTP/1.0\r\n";
    		$header .= "Host: www.paxum.com\r\n";
    		$header .= "Accept: */*\r\n";
    		$header .= "User-Agent: php-agent/1.0\r\n";
    		$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    		$header .= "Connection: close\r\n";        
    		$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    
    		// Make the request to the server
    		// If possible, securely post using HTTPS, your PHP server will need to be SSL enabled
    		$fp = fsockopen ("ssl://www.paxum.com", 443, $errno, $errstr, 30);
    
    		if (!$fp)
    		{
    			// HTTP ERROR
    			return -1;
    		}
    		
    		//echo $req;exit;
    		
    		fputs ($fp, sprintf("%s%s", $header, $req));
    
    		// Read the server response
    
    		$res = "";
    		$headerdone = false;
    		while (!feof($fp))
    		{
    			$line = fgets ($fp, 1024);
    			if (strcmp($line, "\r\n") == 0)
    			{
    				// read the header
    				$headerdone = true;
    			}
    			else if ($headerdone)
    			{
    				// header has been read. now read the contents
    				$res .= $line;
    			}
    		}
            }

    hardcode = true;

    hack3p, 20 Июля 2016

    Комментарии (13)
  2. Куча / Говнокод #20399

    +4

    1. 1
    https://www.reddit.com/r/ProgrammerHumor/comments/4to9vx/so_im_working_on_a_new_language/

    "So I'm working on a new language…"

    n1919, 20 Июля 2016

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

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    #include <iostream>
    
    struct Test {
    	operator auto() -> bool { return true; }
    };
    
    int main() {
    	std::cout << std::boolalpha << Test() << std::endl;
    }

    operator auto() завезли!
    http://ideone.com/sGxeQn

    Antervis, 20 Июля 2016

    Комментарии (22)
  4. PHP / Говнокод #20394

    −3

    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
    function formSelect($itxt, $name = '', $val = array(), $selected = 0, $data = 0, $nullF = false, $atr = '', $optatr = array()) {
    	if(is_array($selected)) { $atr .= ' multiple'; }
    	$html = '<select  name="'.$name.'" '.$atr.">\r\n";
    	if($nullF) {
    		$t = ($nullF === true) ? ' ' : $nullF;
    		$html .= '<option value="0">'.$t.'</option>'; }
    	if($data == 3) { $start = $itxt; $count = $val[0]; $step = $val[1]; }
    	else { $count = count($itxt); }
    	for($i = 0; $i < $count; $i++) {
    			// 4 - для быза данных
    		switch($data) {
    			case 1: $key = $val[$i]; $txt = $itxt[$i]; break;
    			case 2: $key = $i; $txt = $itxt[$i]; break;
    			case 3: $txt = $key = ($start + ($step*$i)); break;
    			case 4: $key = $itxt[$i][$val[0]]; $txt = $itxt[$i][$val[1]]; break;
    			default: $key = $txt = $itxt[$i]; break;
    		}
    		$sel = '';
    		if(is_array($selected)) {
    			if(in_array($key, $selected)) { $sel = 'selected'; }
    		} elseif($selected == $key) { $sel = 'selected'; }
    		if(!empty($optatr[$i])) { $opt = $optatr[$i]; } else { $opt = ''; }
    		$html .= '<option value="'.$key.'" '.$sel.$opt.'>'.$txt."</option>\r\n";
    	}
    	$html .= "</select>\r\n";
    	return $html;
    }

    Теперь бызить вореции как никогда просто!

    daniser, 19 Июля 2016

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

    +3

    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
    #define __DEBUG
    #ifdef __DEBUG
        #define print_pair(p) do{std::cout << "(" << ((p).first + 1) << ", "\
                                << ((p).second + 1) << ")" << std::endl;}while(0);
    #endif
    
    Graph::result
    Graph::dijkstra (int start)
    {
    #ifdef __DEBUG
        std::cout << "Dijkstra algorithm tracing:" << std::endl;
    #endif
        distances[start] = 0;
        std::set<std::pair<int, int>> q;
        q.insert (std::make_pair(distances[start], start));
        while (!q.empty())
        {
    #ifdef __DEBUG
            std::cout << "top element of a set: ";
            print_pair(*q.begin());
    #endif
            int current = q.begin()->second;
            q.erase(q.begin());
            for (int i = 0; i < adj[current].size(); ++i)
            {
    #ifdef __DEBUG
        std::cout << "current vertex: " << (current + 1);
        std::cout << " ad current state of distances array is: " << std::endl;
        for (auto i: distances)
            std::cout << i << " ";
        std::cout << std::endl;
    #endif
                int to = adj[current][i].second;
                int length = adj[current][i].first;
                // Relaxations
                if (distances[to] > distances[current] + length)
                {
    #ifdef __DEBUG
        std::cout << "relaxation for edge (" << current << ", " << to << ") ";
        std::cout << "with weight " << length << std::endl;
    #endif
                    
                    q.erase(std::make_pair(distances[to], to));
                    distances[to] = distances[current] + length;
                    path[to] = current;
                    q.insert(std::make_pair(distances[to], to));
                }
            }
        }
        // Replace INF by -1
        std::replace (distances.begin(), distances.end(), INF, -1);
        return distances;
    }

    Я у мамы решил подебажить как мыщъх дебажил при помощи отладочной печати. Вот что получилось.

    HiewMorjowie, 18 Июля 2016

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

    +11

    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
    using System; 
    using System.Threading; 
    using System.Threading.Tasks; 
    
    
    
    namespace ConsoleApplication23 { 
    
    
    class InternalRandom { 
    static double x; 
    
    Task t, t2; 
    
    public InternalRandom() { 
    t = new Task(ThreadFunc); 
    t.Start(); 
    t2 = new Task(ThreadFunc); 
    t2.Start(); 
    } 
    
    public double Next() { 
    return x; 
    } 
    
    public double Next(double max) { 
    x+=7; 
    return NORMALNYYREM(x,max); 
    //return Math.IEEERemainder(max, x); 
    } 
    
    
    
    static double NORMALNYYREM(double A,double B) { 
    return A - ((double)((long)(A/B))) * B; 
    } 
    
    
    static void ThreadFunc() { 
    while(true) { 
    x += 1; 
    } 
    } 
    
    } 
    
    
    
    class Program { 
    static InternalRandom ir; 
    
    static void Main(string[] args) { 
    ir = new InternalRandom(); 
    for(int i = 1; i <= 20; i++) { 
    Console.WriteLine( "#"+i+" = "+ Random() ); 
    } 
    Console.ReadLine(); 
    //Environment.Exit(0); 
    } 
    
    
    static double Random() { 
    return ir.Next(10); 
    } 
    
    
    } 
    }

    dm_fomenok, 18 Июля 2016

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

    +2

    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
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    #define CREATE_EVENT_LISTENER(_elname, arg1_type, arg1_name) \
    class _elname : public EventListener	 \
    {	 \
    private:	 \
    	class IContainer	 \
    		{	 \
    	public:	 \
    		virtual void Call(arg1_type arg1_name) = 0;	 \
    		virtual ~IContainer() {}	 \
    		};	 \
    	 \
    	class FunctionContainer : public IContainer	 \
    		{	 \
    	private:	 \
    		typedef void(*__CallbackPtr)(arg1_type);	 \
    	public:	 \
    		FunctionContainer(__CallbackPtr fn)	 \
    				{	 \
    			this->fn = fn;	 \
    				}	 \
    	 \
    		virtual void Call(arg1_type arg1_name)	 \
    				{	 \
    			fn(arg1_name);	 \
    				}	 \
    	 \
    	private:	 \
    		__CallbackPtr fn;	 \
    		};	 \
    		 \
    	template<class T, class Q>	 \
    	class MethodContainer : public IContainer	 \
    		{	 \
    	public:	 \
    		MethodContainer(T method, Q _this)	 \
    				{	 \
    			this->method = method;	 \
    			this->_this = _this;	 \
    				}	 \
    	 \
    		virtual void Call(arg1_type arg1_name )	 \
    				{	 \
    			(_this->*method)(arg1_name);	 \
    				}	 \
    	 \
    	private:	 \
    		T method;	 \
    		Q _this;	 \
    		};	 \
    public:	 \
    	typedef void(*__FN_CALLBACK)(arg1_type);	 \
    	 \
    	_elname(__FN_CALLBACK fn)	 \
    		{	 \
    		this->container = new FunctionContainer(fn);	 \
    		}	 \
    	 \
    	template <class T, class Q>	 \
    	_elname(T method, Q _this)	 \
    		{	 \
    		this->container = new MethodContainer<T, Q>(method, _this);	 \
    		}	 \
    	 \
    	void Call(arg1_type arg1_name)	 \
    		{	 \
    		container->Call(arg1_name);	 \
    		}	 \
    	 \
    	virtual ~_elname()	 \
    		{	 \
    		delete this->container;	 \
    		}	 \
    private:	 \
    	IContainer* container;	 \
    };	 \
    
    #define CREATE_EVENT(_ename, _elname, arg1_type, arg1_name) \
    class _ename : public Event	 \
    {	 \
    public:	 \
    	void AddListener(_elname* listener)	 \
    		{	 \
    		Event::AddListener(listener);	 \
    		}	 \
    	 \
    	void Handle(arg1_type arg1_name)	 \
    		{	 \
    		for (size_t i = 0; i < this->listeners.size(); i++)	 \
    												{	 \
    			((_elname*)listeners[i])->Call(arg1_name);	 \
    												}	 \
    		}	 \
    	 \
    	void RemoveListener(_elname* listener)	 \
    		{	 \
    		Event::RemoveListener(listener);	 \
    		}	 \
    	 \
    };	 \

    Я когда то это написал. Думал, это хорошая идея...
    Полный файл: https://github.com/arhyme/CPP_EVENTS/blob/master/Event.h

    Avery, 18 Июля 2016

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

    +7

    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
    public static List<String> ParseVKPermissionsFromInteger(int permissionsValue)
    {
                var res = new List<String>();
                if ((permissionsValue & 1) > 0) res.Add(NOTIFY);
                if ((permissionsValue & 2) > 0) res.Add(FRIENDS);
                if ((permissionsValue & 4) > 0) res.Add(PHOTOS);
                if ((permissionsValue & 8) > 0) res.Add(AUDIO);
                if ((permissionsValue & 16) > 0) res.Add(VIDEO);
                if ((permissionsValue & 128) > 0) res.Add(PAGES);
                if ((permissionsValue & 1024) > 0) res.Add(STATUS);
                if ((permissionsValue & 2048) > 0) res.Add(NOTES);
                if ((permissionsValue & 4096) > 0) res.Add(MESSAGES);
                if ((permissionsValue & 8192) > 0) res.Add(WALL);
                if ((permissionsValue & 32768) > 0) res.Add(ADS);
                if ((permissionsValue & 65536) > 0) res.Add(OFFLINE);
                if ((permissionsValue & 131072) > 0) res.Add(DOCS);
                if ((permissionsValue & 262144) > 0) res.Add(GROUPS);
                if ((permissionsValue & 524288) > 0) res.Add(NOTIFICATIONS);
                if ((permissionsValue & 1048576) > 0) res.Add(STATS);
                return res;
     }

    Больше кала тут: github.com/VKCOM/vk-windowsphone-sdk

    dm_fomenok, 17 Июля 2016

    Комментарии (54)
  9. Куча / Говнокод #20386

    +2

    1. 1
    2. 2
    https://www.youtube.com/watch?v=Zrd7kFFCfp4
    https://www.youtube.com/watch?v=yuMlhKI-pzE

    CPU

    laMer007, 16 Июля 2016

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

    0

    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
    function syn_s_lms_support_get_bl_specific_urls($bl_node) {
        $bl_specific_urls=array();
        $url = field_extract_value('node', $bl_node, 'field_business_website', 'url');
        if (isset($url[0]) && strlen($url[0]) ) {
            $bl_specific_urls[] = $url[0];
        }
        $url = field_extract_value('node', $bl_node, 'field_business_yelp', 'url');
        if (isset($url[0]) && strlen($url[0]) ) {
            $bl_specific_urls[] = $url[0];
        }
        $url = field_extract_value('node', $bl_node, 'field_business_gplus', 'url');
        if (isset($url[0]) && strlen($url[0]) ) {
            $bl_specific_urls[] = $url[0];
        }
        $url = field_extract_value('node', $bl_node, 'field_business_facebook', 'url');
        if (isset($url[0]) && strlen($url[0]) ) {
            $bl_specific_urls[] = $url[0];
        }
        $twitname = field_extract_value('node', $bl_node, 'field_business_twitter');
        if ($twitname) {
            $twit_name_clean = str_replace("@", '',  $twitname);
            $bl_specific_urls[] = 'https://twitter.com/' . $twit_name_clean;
        }
        return $bl_specific_urls;
    }

    Давай, ман не читай,
    код пиши от души.

    zima, 15 Июля 2016

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