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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    $tempname = '__temp__.apk';
    copy($origname, $tempname);
    exec('C:\Android\android-sdk\build-tools\34.0.0\aapt.exe dump badging ' . '"'.$tempname.'"', $output);
    unlink($tempname);

    Понадобилось по-быстрому наговнякать переименоватор apk-файлов. Решил метушню из манифеста вытянуть с помощью «aapt» из официальных «Android build tools». Оказалось, что «aapt» не может открыть файл, если его имя содержит символы за пределами базового ASCII. CHCP не помогает вообще никак.

    При передаче в aapt имени в 866 выводится «asset... Asset path... is neither a directory nor file (type=1)», при передаче имени в других кодировках (1251, UTF-8) выводится сообщение «ziparchive... Invalid byte sequence». Так и не смог подобрать кодировку, в которой заработает.

    Шёл 2024-й год.

    nemyx, 04 Марта 2024

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

    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
    <?php
    
    $domains = [
    'edge-star-shv-%s-%s.facebook.com',      /* edge-chat.facebook.com, graph.facebook.com, mbasic.facebook.com, touch.facebook.com */ 
    'instagram-p42-shv-%s-%s.fbcdn.net',     /* www.instagram.com, b.i.instagram.com */
    'edge-sonar-mini-shv-%s-%s.fbcdn.net',   /* не знаю, для чего нужны edge-sonar-mini */
    'edge-star-mini-shv-%s-%s.facebook.com', /* www.facebook.com, m.facebook.com, fb.com */
    'instagram-p3-shv-%s-%s.fbcdn.net',      /* api.instagram.com, i.instagram.com, l.instagram.com, graph.instagram.com, edge-chat.instagram.com, */
                                             /* static.cdninstagram.com, scontent-hel3-1.cdninstagram.com, scontent.cdninstagram.com, */
                                             /* threads.net, www.threads.net */
    'xx-fbcdn-shv-%s-%s.fbcdn.net',          /* scontent-hel3-1.xx.fbcdn.net, static.xx.fbcdn.net, connect.facebook.net, scontent.xx.fbcdn.net */
    'edge-dgw-shv-%s-%s.facebook.com'        /* gateway.facebook.com, gateway.instagram.com, gateway.threads.net */
    ];
    
    $suffices = explode(',', 'akl1,ams2,ams4,arn2,atl3,bcn1,bkk1,bog1,bog2,bom1,bom2,bos5,bru2,ccu1,cdg4,cgk1,cph2,cpt1,del1,del2,den2,den4,dfw5,dub4,dus1,eze1,fco2,for1,fra3,fra5,gig4,gru1,gru2,ham3,hel3,hkg1,hkg4,hou1,hyd1,iad3,jnb1,jnb2,kul2,kul3,lax3,lga3,lhr6,lhr8,lim1,lis1,los2,maa2,mad1,mad2,man2,mct1,mia3,mnl1,mrs2,msp1,muc2,mxp1,mxp2,nrt1,ord5,otp1,pmo1,pnq1,prg1,qro1,scl2,sea1,sin6,sjc3,sof1,syd2,tpe1,vie1,waw1,xsp1,zrh1');
    
    foreach ($domains as $domain) {
      foreach (['01','02','03','04'] as $index) {
        foreach ($suffices as $suffix) {
            $url = sprintf($domain, $index, $suffix);
            $raw = gethostbynamel($url);
            if(!is_array($raw)) continue;
            $ips = implode(',', $raw);
            echo $ips,' ', $url, PHP_EOL;
        }
      }
    }

    Получение списка IP-адресов, используемых сервисами Ф*к, И*м и Threads.

    Myxa, 13 Января 2024

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

    0

    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
    <?php
    
    namespace App\Http\Controllers\api\v1;
    
    use App\Http\Controllers\Controller;
    use App\Http\Requests\StandartRequest;
    use App\Models\Attractions;
    use App\Models\AttractionSessionUpdates;
    use App\Models\Locations;
    use App\Models\SessionAttractionHistory;
    use App\Models\SessionsHistoryAttractions;
    use App\Models\SessionsHistoryGames;
    use App\Models\Statistic\CountEndAttractionSessions;
    use Illuminate\Http\Request;
    use Illuminate\Support\Carbon;
    use Illuminate\Support\Facades\Auth;
    use Illuminate\Support\Facades\Cache;
    use Illuminate\Support\Facades\Log;
    
    class AttractionEndSessionsCount extends Controller
    {
        public function endSessions(StandartRequest $request){
            $this->now_time = Carbon::now();
    
            $locations = Locations::where('user_id', '=', Auth::user()->id)->get();
            if (count($locations) == 0){
                return response()->json(['code' => "404", 'status' => 'error' , 'message'=> "locations not found"]);
            }
            try {
                $request_from = $request->input('date_from');
                $from = Carbon::parse($request_from."00:00:01");
    
                $date_to = $request->input('date_to');
                $to = Carbon::parse($date_to."11:59:59");
            } catch (\Exception $exception){
                return response()->json(['code' => "422", 'status' => 'error' , 'message'=> "dates have bad format, failed parse"]);
            }
    
            if ($from->timestamp > $to->timestamp){
                return response()->json(['code' => "422", 'status' => 'error' , 'message'=> "the start date is larger than the end date"]);
            }
    
            $is_detail = $request->input('detail', 'daily');
    
            $arr = $this->prepareLocationsAndAttrctions($locations, $from, $to, $is_detail);
    
            $locations_ids = [];
            foreach ($locations as $loc){
                $locations_ids[] = $loc->id;
            }
    
            $history = CountEndAttractionSessions::query()->whereIn('location_id', array_values($locations_ids))
                ->whereBetween('day_date', [$from->startOfDay()->format('Y-m-d H:i:s'), $to->endOfDay()->format('Y-m-d H:i:s')])
                ->get();
    
            $resp = $this->fillResults($arr ,$history, $is_detail);
            if ($this->is_today){
                $resp = $this->fillTodayResult($resp, $locations_ids, $is_detail);
            }
            return response()->json(['code' => "200", 'status' => 'success' , 'data'=> $resp]);
    
        }
    
        private function fillResults($arr ,$history, $is_detail){
            foreach ($history as $value){
                try {
                    if ($is_detail == 'hourly'){
                        $arr['locations'][$value->location_id]['attractions'][$value->attraction_id]['list'][$value->day_date->format('d-m-Y')][$value->day_date->format('H:00:00')] =
                            [
                                // общее количество игр
                                'total_count' => $value->total_count ?? 0,
                                //общее количество обновлений
                                'total_updates_count' => $value->total_updates_count ?? 0,
                                // количество пролонгейт обновлений
                                'add_time' => $value->add_time ?? 0,
                                // количество лет_гейм обновлений
                                'let_game_end' => $value->let_game_end ?? 0,
                                //средняя длина игры в секундах
                                'avg_duration' => [
                                    'sum_seconds' => $value->avg_duration_second_sum,
                                    'count_games' => $value->avg_duration_count_games,
                                ],
                                // минимальная игра в секундах
                                'min_duration' => $value->min_duration,
                                // максимальная игра в секундах
                                'max_duration' => $value->max_duration,
                    ];
                        for ($i = 1; $i <= 10; $i++){
                            $selector = 'max_players_'.$i;
                            $arr['locations'][$value->location_id]
                            ['attractions'][$value->attraction_id]
                            ['list'][$value->day_date->format('d-m-Y')]
                            [$value->day_date->format('H:00:00')]
                            ['max_players'][$i] = (int)$value->$selector;
                        }
                    }elseif ($is_detail == 'daily') {
                        $arr['locations'][$value->location_id]['attractions'][$value->attraction_id]
                        ['list'][$value->day_date->format('d-m-Y')]['total_count'] += $value->total_count;
    
                        $arr['locations'][$value->location_id]['attractions'][$value->attraction_id]

    расчет заранее посчитанной оффлайн и онлайн статистики

    tlen, 06 Октября 2023

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

    0

    1. 1
    За "PHP".

    DECAHTHblu_nemyx, 02 Августа 2023

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    1) Протухает сертификат
    2) С горящей жопой бежишь его обновлять
    3) Делаешь мониторинг: отправляешь письмо, если сертификат скоро протухнет
    4) Отправка письма ломается
    5) Go to 1

    3_dar, 29 Июня 2023

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

    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
    <?php
    
    function filter($var, $type)
    {
         switch ($type[0])
         {
             case 1: $var = 'intval('.$var.')';
             break;
             case 2: $var = 'trim('.$var.')';
             break;
         }
         switch ($type[1])
         {
             case 1: $var = 'intval('.$var.')';
             break;
             case 2: $var = 'trim('.$var.')';
             break;
         }
         return $var;
    }
    $var3 = 233;
    echo filter($var3, [1,2]);
    ?>

    Шедевр:
    https://php.ru/forum/threads/nuzhna-pomosch-po-kodu.101533

    MouseZver, 22 Июня 2023

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

    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
    /**
         * Hash a value according to FraudRecord specifications
         *
         * @param string $value
         * @param bool $prepare password is treated differently
         * @return string
         */
        function hash($value, $prepare = true)
        {
            if($prepare) {
                $value = trim($value);
                $value = strtolower($value);
                $value = str_replace(" ", "", $value);
            }
    
            for($i = 0; $i < 32000; $i++)
                $value = sha1("fraudrecord-".$value);
            return $value;
        }

    Безопасность в безопасности от безопасности

    https://github.com/splitice/fraudrecord-api/blob/master/src/Splitice/FraudRecord/FraudRecordApi.php#L58

    bot, 13 Марта 2023

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if (isset($args['filter']['birthdate'])) {
        $birthdate = $args['filter']['birthdate'];
    
        $filters['birthdate'] = [];
        if (!empty($birthdate['to'])) {
            $filters['birthdate']['$lte'] = $birthdate['to'];
        }
    
        if (!empty($birthdate['from'])) {
            $filters['birthdate']['$gte'] = $birthdate['from'] + 86399;
        }
    }

    нельзя описать то, что уже обоссано

    mahnat, 10 Марта 2023

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

    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
    include( 'includes/systems/header.inc' ); #Подключение Заголовка
    
    @list($wdth,$hght) = getImageSize( $_GET['photo'] );
    
    while( ( $wdth > $_SESSION['wdth']-100 ) || ( $hght > $_SESSION['hght']-100 ) ){
    $wdth = $wdth / 1.00001;
    $hght = $hght / 1.00001;
    }
    # echo $wdth . 'x' . $hght ;
    # $hghtP = $hght - 85;
    # $wdthP = $wdth - 85;
    $hghtP = $hght;
    $wdthP = $wdth;
    
    
    @$prms = ( $wdth > $hght )? 'width=' . (int)$wdthP: 'height=' . (int)$hghtP;
    # echo $wdth . 'x' . $hght;

    photo.php

    GAMER, 26 Декабря 2022

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function gk_nitter_filter($url) {
        $url = preg_replace('/https?:\/\/(?:mobile\.)?twitter\.com\/(\S*)/', 'https://nitter.kavin.rocks/$1', $url);
        $url = preg_replace('/https?:\/\/pbs\.twimg\.com\/(\S+)\?format=(\w+)(\S*)/', 'https://nitter.kavin.rocks/pic/$1.$2', $url);
        $url = preg_replace('/https?:\/\/pbs\.twimg\.com\/(\S*)/', 'https://nitter.kavin.rocks/pic/$1', $url);
        return $url;
    }

    НИТТЕР КАВИН РОКС!

    gostinho, 20 Декабря 2022

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