1. Список говнокодов пользователя konmado

    Всего: 6

  2. PHP / Говнокод #22913

    −107

    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
    #!/usr/bin/php
    <?php
    
    $responce = exec("curl 'https://npm.by/booking/route-time' -sb -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest'  --data 'id_departure_station=140&departure_is_waypoint=0&id_arrival_station=66&arrival_is_waypoint=0&date=06-05-2017'");
    
    $data = array_filter(
        json_decode($responce, true), 
        function ($item) {return !empty($item);}
    );
    
    $data = array_filter(
        reset($data),
        function ($item) {
            return $item['time'] > '19:30' && $item['count'] > 0;
        }
    );
    
    if ($data) {
        print_r($data);
        exec(sprintf('zenity --notification --text="%s"', var_export($data, true)));
    }

    Отслеживание свободных мест на маршрутку https://npm.by/

    konmado, 06 Мая 2017

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

    −16

    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
    <?php
    
        public function getGlobals()
        {
            return $this->globals;
        }
    
        /**
         * Initializes the built-in escapers.
         *
         * Each function specifies a way for applying a transformation to a string
         * passed to it. The purpose is for the string to be "escaped" so it is
         * suitable for the format it is being displayed in.
         *
         * For example, the string: "It's required that you enter a username & password.\n"
         * If this were to be displayed as HTML it would be sensible to turn the
         * ampersand into '&amp;' and the apostrophe into '&aps;'. However if it were
         * going to be used as a string in JavaScript to be displayed in an alert box
         * it would be right to leave the string as-is, but c-escape the apostrophe and
         * the new line.
         *
         * For each function there is a define to avoid problems with strings being
         * incorrectly specified.
         */
        protected function initializeEscapers()
        {
            $that = $this;
            $this->escapers = array(
                'html' =>
                /**
                 * Runs the PHP function htmlspecialchars on the value passed.
                 *
                 * @param string $value the value to escape
                 *
                 * @return string the escaped value
                 */
                function ($value) use ($that) {
                    // Numbers and Boolean values get turned into strings which can cause problems
                    // with type comparisons (e.g. === or is_int() etc).
                    return is_string($value) ? htmlspecialchars($value, ENT_QUOTES, $that->getCharset(), false) : $value;
                },
                'js' =>
                /**
                 * A function that escape all non-alphanumeric characters
                 * into their \xHH or \uHHHH representations
                 *
                 * @param string $value the value to escape
                 * @return string the escaped value
                 */
                function ($value) use ($that) {
                    if ('UTF-8' != $that->getCharset()) {
                        $value = $that->convertEncoding($value, 'UTF-8', $that->getCharset());
                    }
    
                    $callback = function ($matches) use ($that) {
                        $char = $matches[0];                        // \xHH
                        if (!isset($char[1])) {
                            return '\\x' . substr('00' . bin2hex($char), -2);
                        }                        // \uHHHH
                        $char = $that->convertEncoding($char, 'UTF-16BE', 'UTF-8');
                        return '\\u' . substr('0000' . bin2hex($char), -4);
                    };
                }
            );
        }

    Typing Lessons PHP/Symfony https://typing.io/lesson/php/symfony/PhpEngine.php/9

    konmado, 25 Апреля 2017

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

    −22

    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
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    
    class Main {
        public static void main (String[] args){
        int year = Calendar.getInstance().get(Calendar.YEAR);
        System.out.println("<!DOCTYPE html>" +
        "<html lang=\"en\">" +
        "<head>" +
            "<title>Bootstrap Example</title>" +
            "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">" +
            "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js\"></script>" +
            "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>" +
    // и так  500 строк 
      "</head>" +
        "<body>" +
        "<footer class=\"container-fluid\">" +
            "<p>All right reserved " + String.valueOf(year) + " </p>" +
        "</footer>" +
    
        "</body>" +
        "</html>"
        );
        }
    }

    CGI для Java )
    server {
    listen 8080;
    server_name localhost;

    location /java {
    default_type 'text/html';

    content_by_lua_block {
    local handle = io.popen("cd /var/www/java/web; java Main " .. ngx.var.uri)
    local result = handle:read("*a")
    ngx.say(result)
    }
    }
    }

    konmado, 04 Апреля 2017

    Комментарии (2)
  5. 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)
  6. PHP / Говнокод #20221

    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
    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
    # https://www.fusionticket.org/ cms для продажи билетов 
    
    // файл includes/classes/class.router.php
    
        if(is_null($action)){
          if (isset($_POST['action'])) {
            $action=$_POST['action'];
          } elseif (isset($_GET['action'])) {
            $action=$_GET['action'];
          } else
            $action=false;
        }
    
        $_REQUEST['action'] = $action;
        $_GET['action']     = $action;
        $_POST['action']    = $action;
        //echo $controller,'-',$module, '-',$action;
    
    //  теперь с class.router.php попадаем сюда includes/template/web/shop.tpl
    
    {if  $smarty.post.action eq 'resendpassword'}
       {$user->forgot_password_f($smarty.post.email)}
    {/if}
    
    {if $smarty.request.action eq 'login' and $smarty.request.type != 'block'}
    	{include file="user_login.tpl"}
    
    {elseif $smarty.request.action eq 'register'}
      {if $smarty.request.register_user}
        {user->register ismember=true data=$smarty.post secure='user_nospam' login=true}
        {assign var='user_data' value=$smarty.post}
        {if $user_errors}
          {include file="user_register.tpl" ManualRegister=true}
        {else}
          {include file="user_activate.tpl"}
        {/if}
      {else}
        {include file="user_register.tpl" ManualRegister=true}
      {/if}
    
    {elseif $smarty.request.action eq 'activate'}
      {include file="user_activate.tpl"}
    
    {elseif $smarty.request.action eq 'resend_activation'}
      {include file="resend_activation.tpl"}
    {elseif $smarty.get.action eq "remove"}
      {$cart->remove_item_f($smarty.get.event_id,$smarty.get.cat_id,$smarty.get.item)}
      {include file="cart_view.tpl"}
    
    {elseif $smarty.request.action eq "addtocart"}
      {if $smarty.post.place}
        {assign var='last_item' value=$cart->add_item_f($smarty.post.event_id, $smarty.post.category_id, $smarty.post.place, $smarty.post.discount, 'mode_web')}
      {else}
        {assign var='last_item' value=$cart->add_item_f($smarty.post.event_id, $smarty.post.category_id, $smarty.post.places, $smarty.post.discount, 'mode_web')}
      {/if}
      {if $last_item}
        {redirect url="index.php?action=view_cart&event_id={$smarty.post.event_id}"}
      {else}
        {include file="event_ordering.tpl"}
      {/if}
    {elseif $smarty.request.action eq "buy"}
      {include file="event_ordering.tpl"}
     
    и т. д.  250 строк.

    https://www.fusionticket.org/.

    konmado, 17 Июня 2016

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

    −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
    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
    <?php
    namespace AppBundle\Command;
    
    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class InterpolationLabsCommand extends ContainerAwareCommand
    {
    
        /**
         * nodes for interpolation polynomial
         */
        protected $_nodes;
    
    
        protected function configure()
        {
            $this
                ->setName('app:interpolation:labs')
                ->setDescription('interpolation')
                ->addOption('nodes-count', null, InputOption::VALUE_REQUIRED, 
                    'Sets the number of nodes for interpolation.', null);
        }
    
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $intervalStart = -3;
            $intervalEnd  = 3;
    
            $nodesCount = $input->getOption('nodes-count');
            
            $this->generateSeries($nodesCount, $intervalStart, $intervalEnd, function($x) {
                return sin($x);
            });
    
            foreach (range($intervalStart, $intervalEnd, 0.1) as $value) {
    
                $result = $this->getLagrangeValue($value);
                $output->writeln("$value $result");
            }
        }
    
        /**
         * Find value for lagrange interpolation polynomial at n nodes
         * @throw \Exception
         * 
         * @return 
         */
        protected function getLagrangeValue($x)
        {
    
            $w = function($nodeKey) use ($x) {
    
                if (!array_key_exists($nodeKey, $this->_nodes)) {
                    throw new \Exception("The key is not exists to the array nodes");
                }
    
                $return = 1;
                foreach ($this->_nodes as $key => $node) {
                    if ($key == $nodeKey) {
                        continue;
                    }
    
                    $return *= ($x - $node->x)/($this->getNode($nodeKey)->x - $node->x);
                }
                return $return;
            };
    
            $result = 0;
            foreach ($this->_nodes as $nodeKey => $node) {
                $a = $w($nodeKey);
    
                $result += $w($nodeKey) * $node->fx;
            }
    
            return $result;
    
        }
    
        protected function getNode($i)
        {
            return $this->_nodes[$i];
        }
    
    
        private function generateSeries($num,  $intervalStart, $intervalEnd,  $fun)
        {
            for ($i=0; $i < $num; $i++) { 
    
                $x  = $intervalStart + ($intervalEnd - $intervalStart)/($num-1) * $i;
                $this->_nodes[] = (object) array('x' => $x, 
                    'fx' => $fun($x)); 
            }
        }
    }

    Лаба по методам численного анализа

    konmado, 19 Мая 2016

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