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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $query = "INSERT INTO news (title, img_url, subtitle, content, date, time, id) 
    	VALUES (\"" .
    	$_POST["title"] . "\", \"" .
    	$_POST["img_url"] . "\", \"" .
    	$_POST["subtitle"] . "\", \"" .
    	$_POST["content"] . "\", \"" .
    	date("Y-m-d") . "\", \"" .
    	time() . "\", " .
    	DEFAULT . ");";

    только начал php. уверень, есть решение поэлегантнее этого

    artembegood, 05 Января 2015

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

    +56

    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
    #include <iostream>
    #include <thread>
    #include <list>
    #include <functional>
    #include <chrono>
    using namespace std;
    
    void outputToSomeContainer(int val, list<int>& result){
       result.push_back(val);
    }
    
    class async{
      list<thread> a;
    public:
      async(){}
      async(async&& a): a(move(a.a))
      {}
      void addTask(function<void()>&&f){
        a.emplace_back(move(f));
      }
      void wait(){
        for(auto&& i: a)
          i.join();
      }
    };
    
    async async_O_n_Sort(const list<char>& unsorted, function<void(int)> outputToContainer){
      async a;
      for(int i: unsorted)//O(n)
        a.addTask([i, outputToContainer](){this_thread::sleep_for(chrono::milliseconds(5+i*10));outputToContainer(i);});
      return a;
    }
    
    int main() {
      list<char> unsorted {1, 0, 6, 3, 4};
      list<int> sorted;
      auto a = async_O_n_Sort(unsorted, bind(outputToSomeContainer, placeholders::_1, ref(sorted)));
      cout<<"А мы веселые пельменья, мы похоже на варенья"<<endl;
      a.wait();
      for(int i: sorted)
          cout<<i<<endl;
      return 0;
    }

    Тред:

    http://www.gamedev.ru/flame/forum/?id=196521
    http://coliru.stacked-crooked.com/a/c317bee4dbe183ab

    laMer007, 05 Января 2015

    Комментарии (91)
  3. JavaScript / Говнокод #17409

    +156

    1. 1
    document.write('Well, I broke your script');

    Я знаю что document.write это плохо, но использование document.write ломает jsfiddle :D
    http://jsfiddle.net/volter9/x29Lzvu6/

    volter9, 05 Января 2015

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

    +143

    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
    void ** __attribute__((noinline)) findVoidSortMap(void ** list,void *key)
    {
        if (!list) return 0;
        if (!*list) return 0;
        unsigned int count= **(unsigned int**)list;
        char *p=(char*)*list;
        p+=4;
        Element *b=(Element *)p;
     
        long long skey=(long long)key;
     
        while (count>0) {
            void** kt=(void**)&b[count>>1];
            long long rkey=(long long)kt[0];
            if (skey==rkey) return (void**)&kt[1];
            if (skey>rkey) {b+=(count>>1)+1;count--;}
            count=count>>1;
        }
     
        return (void**)-1;
    }

    гуру осемблира на этом коде доказывал, что Эльбрус сосёт
    http://www.gamedev.ru/flame/forum/?id=196722&page=33#m481

    TarasB, 05 Января 2015

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

    +136

    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
    GetDate(string dateTimeText){
                    DateTime date = new DateTime();
                    String[] parsedDate = dateTimeText.Split('/');
                    bool allNumbers = true;
    
                    foreach (string s in parsedDate)
                    {
                        int value;
                        if (!int.TryParse(s, out value) && allNumbers)
                        {
                            allNumbers = false;
                        }
                    }
                    if (parsedDate.Length == 3 && allNumbers)
                    {
                        String newDateText = parsedDate[1] + "/" + parsedDate[0] + "/" + parsedDate[2];
    
                        DateTime.TryParse(newDateText, out date);
                    }
     return date;
    }

    парсинг юзеринпута в датетайм пикере

    zxxc, 05 Января 2015

    Комментарии (3)
  6. Куча / Говнокод #17406

    +126

    1. 1
    2. 2
    3. 3
    <fileset dir="${basedir}" includes="**/*">
          <type type="dir"/>
    </fileset>

    Печаль заключается в том, что <type type="dir"/> никогда ничего не даст выбрать. fileset не может технически содержать папки.

    wvxvw, 05 Января 2015

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

    +135

    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
    private static string GetMultipartFileContentType(string file)
    {
        var ext = file.Split('.').Last().ToLower();
    
        var types = new[]
        {
            new[] {"application/envoy","evy"},
            new[] {"application/fractals","fif"},
            new[] {"application/futuresplash","spl"},
            new[] {"application/hta","hta"},
            new[] {"application/internet-property-stream","acx"},
            new[] {"application/mac-binhex40","hqx"},
            new[] {"application/msword","doc"},
            new[] {"application/msword","dot"},
            new[] {"application/octet-stream","*"},
            new[] {"application/octet-stream","bin"},
            new[] {"application/octet-stream","class"},
            new[] {"application/octet-stream","dms"},
            new[] {"application/octet-stream","exe"},
            new[] {"application/octet-stream","lha"},
            new[] {"application/octet-stream","lzh"},
            new[] {"application/oda","oda"},
            // Многобукв...
            new[] {"x-world/x-vrml","xof"}
        };
    
        var toReturn = types.FirstOrDefault(t => t[1] == ext);
    
        return toReturn != null ? toReturn[0] : "application/octet-stream";
    }

    pushistayapodmyshka, 05 Января 2015

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (!!window.Worker){
        var worker = new Worker('worker.js');
        worker.postMessage('Hellow World');
        worker.onmessage = function (e){
          alert(e.data);
        };
      }

    Из статьи на швабре: /post/132785/

    kingmonstr, 05 Января 2015

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

    +159

    1. 1
    2. 2
    3. 3
    if((!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/") && !$_SESSION['user']) {$smarty->display(dirname(__FILE__).'/system/template/index.html'); exit;}
    if ($_SESSION['user']['login'] && (!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/")) {require './system/modules/info/main.php';$smarty->assign('c',$_SESSION['user']); $smarty->display(dirname(__FILE__).'/system/template/home/index.html');}
    if((!$_SERVER["REQUEST_URI"]) || ($_SERVER["REQUEST_URI"] == "/") && !$_SESSION['user']) {$smarty->display(dirname(__FILE__).'/system/template/home/guest.html');}

    Вот как строится новая соцсеть

    yanislavb, 04 Января 2015

    Комментарии (5)
  10. Pascal / Говнокод #17402

    +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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    var a : int64;
     
    begin
      assign(input, 'input.txt'); reset(input);
      assign(output, 'output.txt'); rewrite(output);
      read(a);
      if a=25 then write ('2.7182818284590452353602875');
      if a=24 then write ('2.718281828459045235360288');
      if a=23 then write ('2.71828182845904523536029');
      if a=22 then write ('2.7182818284590452353603');
      if a=21 then write ('2.718281828459045235360');
      if a=20 then write ('2.71828182845904523536');
      if a=19 then write ('2.7182818284590452354');
      if a=18 then write ('2.718281828459045235');
      if a=17 then write ('2.71828182845904524');
      if a=16 then write ('2.7182818284590452');
      if a=15 then write ('2.718281828459045');
      if a=14 then write ('2.71828182845905');
      if a=13 then write ('2.7182818284590');
      if a=12 then write ('2.718281828459');
      if a=11 then write ('2.71828182846');
      if a=10 then write ('2.7182818285');
      if a=9 then write ('2.718281828');
      if a=8 then write ('2.71828183');
      if a=7 then write ('2.7182818');
      if a=6 then write ('2.718282');
      if a=5 then write ('2.71828');
      if a=4 then write ('2.7183');
      if a=3 then write ('2.718');
      if a=2 then write ('2.72');
      if a=1 then write ('2.7');
      if a=0 then write ('3') 
    end.

    Вывод числа e с заданной точностью

    AndreyZ, 04 Января 2015

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