1. Java / Говнокод #23509

    −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
    import java.io.*;
    import java.security.*;
    import java.nio.file.*;
    
    class mdsumall
    {
    	static long bytes = 0;
    
      public static void main(String[] args)
      {
        System.out.println("Программа начинает работу...");
        findAndStore cEtc = new findAndStore("/etc");
        Thread etc = new Thread(cEtc);
        findAndStore cUsr = new findAndStore("/usr");
        Thread usr = new Thread(cUsr);
        findAndStore cHome = new findAndStore("/home");
        Thread home = new Thread(cHome);
        etc.start();
        usr.start();
        home.start();
        try {
        	etc.join();
        	usr.join();
        	home.join();
        }
        catch(InterruptedException e) {
          System.out.println("Прерывание основного потока");
        }
        System.out.println("Итого байт: "+bytes);
      }
    }
    
    class findAndStore implements Runnable
    {
    	String name;
    
    	findAndStore(String name)
    	{
    		this.name = name;
    	}
    
    	public void run()
    	{
    		System.out.println("Начат сбор в папке "+name);
    		storeRecursive(name);
    	}
    
    	void storeRecursive(String folder)
    	{
    		File f = new File(folder);
    		File[] list = f.listFiles();
    		for(File item : list) {
    			if(item.isDirectory())
    				storeRecursive(item.getPath());
    			try {
    				mdsumall.bytes += Files.size(item.toPath());
    			}
    			catch(IOException e) {
    				System.out.println(e);
    			}
    		}
    	}
    }

    Зацените пасаны!!! Это реально нагружает процессор до 80 градусов греет

    samopisiets, 09 Ноября 2017

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

    −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
    class MoreThreads
    {
      public static void main(String[] args)
      {
        println("Запуск основного потока");
        
        MyThread mt1 = new MyThread("Child #1");
        MyThread mt2 = new MyThread("Child #2");
        MyThread mt3 = new MyThread("Child #3");
        MyThread mt4 = new MyThread("Child #4");
        MyThread mt5 = new MyThread("Child #5");
        MyThread mt6 = new MyThread("Child #6");
        MyThread mt7 = new MyThread("Child #7");
        MyThread mt8 = new MyThread("Child #8");
        MyThread mt9 = new MyThread("Child #9");
        MyThread mt10 = new MyThread("Child #10");
        MyThread mt11 = new MyThread("Child #11");
        MyThread mt12 = new MyThread("Child #12");
        MyThread mt13 = new MyThread("Child #13");
        MyThread mt14 = new MyThread("Child #14");
        MyThread mt15 = new MyThread("Child #15");
        MyThread mt16 = new MyThread("Child #16");
        MyThread mt17 = new MyThread("Child #17");
        MyThread mt18 = new MyThread("Child #18");
        
        for(int i=0; i<50; i++) {
          print(".");
          try {
            Thread.sleep(100);
          }
          catch(InterruptedException e) {
            println("Прерывание основного потока");
          }
        }
        
        println("Завершение основного потока");
      }
      
      static void print(String text)
      {
        System.out.print(text);
      }
      
      static void println(String text)
      {
        System.out.println(text);
      }
    }
    
    class MyThread extends Thread
    {
      
      MyThread(String name) {
        super(name);
        setName(name);
        start();
      }
      
      public void run() {
        System.out.println(getName()+" - запуск");
        try {
          for(int count=0; count<10; count++) {
            Thread.sleep(400);
            System.out.println("В "+getName()+", счётчик: "+count);
          }
        }
        catch(InterruptedException e) {
          System.out.println(getName()+" прерван");
        }
        System.out.println(getName()+" - завершение");
      }
    }

    samopisiets, 09 Ноября 2017

    Комментарии (0)
  3. Java / Говнокод #23483

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static byte[] hexStringToByteArray(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                                 + Character.digit(s.charAt(i+1), 16));
        }
        return data;
      }

    Какой-то пидор написал эту функцию, к InetAddress.getByAddress не подходит нихуя!!

    pawn-master, 04 Ноября 2017

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

    +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
    private SharedPreferences longCache;
    private String email;
    
    public void updateEmail(String newLogin) {
        if(newLogin != null) {
            email = newLogin;
            if(longCache.contains("email")) {
                longCache.edit().remove("email").apply();
            }
            longCache.edit().putString("email", email).apply();
        }
    }

    Проект под Android.
    Стаж разработчика - 5 лет.

    ausichenko, 25 Октября 2017

    Комментарии (0)
  5. Java / Говнокод #23429

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    List<Address> addresses = loadFromDatabase();
    
    Map<Integer, Address> sortMap = new HashMap<>();
    for (Address address : addresses) {
        if (address.getLatitude() != null && address.getLongitude() != null) {
            sortMap.put(new Coords(address.getLatitude(), address.getLongitude()).hashCode(), address);
        }
    }
    addresses = new ArrayList<>(sortMap.values());
    
    ...
    class Coords {
        ...
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + latitude.hashCode();
            result = prime * result + longitude.hashCode();
            return result;
        }
    }

    Автор так решил рандомизировать список что-ли? Не понимаю.

    moonson, 18 Октября 2017

    Комментарии (0)
  6. Java / Говнокод #23416

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if(keys.b && !keys.n) //ГЛЮЧИТ АЛГОРИТМ
            {
              if(old_ch != '\n' && ch == '\n') System.out.format("%6d  ", ++line);
              System.out.format("\nLINE: %d\told_ch=='%c' \t ch='%c'\n", line, old_ch, ch); //дебаг
            }

    Нихуя так read использовать

    KoderOT-Boga, 17 Октября 2017

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

    +4

    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
    <form>
         <input name=userid type=text>
         <input name=password type=text>
         <input name=email text=text>
         <input type=submit>
      </form>
    
    public class User {
         private String userid;
         private String password;
         private String email;
         private boolean isAdmin;
       
         //Getters & Setters
       }
    
    
    
     @RequestMapping(value = "/addUser", method = RequestMethod.POST)
      public String submit(User user) {
         
         userService.add(user);
      
         return "successPage";
      }

    Here is the typical request:

    POST /addUser

    userid=bobbytables&password=hashedpass&[email protected]


    And here is the exploit:
    POST /addUser

    userid=bobbytables&password=hashedpass&[email protected]&isAdmin=true


    https://www.owasp.org/index.php/Mass_Assignment_Cheat_Sheet

    Я вообще охуел, когда узнал что такие уязвимости существуют. А вы говорите PHP говно.

    inho, 14 Октября 2017

    Комментарии (33)
  8. Java / Говнокод #23389

    +4

    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
    public TkApp(final Base base) throws IOException {
            super(
                new TkWithHeaders(
                    new TkVersioned(
                        new TkMeasured(
                            new TkFlash(
                                new TkAppFallback(
                                    new TkAppAuth(
                                        new TkForward(
                                            new TkFork(
                                                new FkHost(
                                                    "relay.jare.io",
                                                    new TkFallback(
                                                        new TkRelay(base),
                                                        req -> new Opt.Single<>(
                                                            new RsWithType(
                                                                new RsWithBody(
                                                                    new RsWithStatus(req.code()),
                                                                    new Sprintf(
                                                                        "Please, submit this stacktrace to GitHub and we'll try to help: https://github.com/yegor256/jare/issues\n\n%s",
                                                                        ExceptionUtils.getStackTrace(
                                                                            req.throwable()
                                                                        )
                                                                    )
                                                                ),
                                                                "text/plain"
                                                            )
                                                        )
                                                    )
                                                ),
                                                ...

    Взято отсюда: https://github.com/yegor256/jare/blob/master/src/main/java/io/jare/tk/TkApp.java#L70

    mazoxox, 06 Октября 2017

    Комментарии (10)
  9. Java / Говнокод #23369

    −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
    class UPR
    {
      public static void main(String[] args)
      {
        //упражнение еба!
        f check = (i)-> {
                        if(i>=10 && i<=20) return true;
                        return false;
                        };
        if(check.check(13)) println("Да");
        else println("Нет");
      }
      
      static void print(String text)
      {
        System.out.print(text);
      }
      
      static void println(String text)
      {
        System.out.println(text);
      }
    }
    
    interface f {
      boolean check(int n);
    }

    Сливаю говно, унитаз засорился(((

    GOVNOCODER-SYKA, 28 Сентября 2017

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

    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
    class Functions //здесь функции
    {
      static void PrintInfo(String[] args) //инфа из стандартного ввода
      {
        try( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) )
        {
          int lines=0;
          int words=0;
          int symbols=0;
          String s;
          while( (s=br.readLine()) != null )
          {
            lines++;
            words+=Functions.NumberWords(s);
            symbols+=Functions.NumberSymbols(s);
          }
          if(args.length == 0) {
            System.out.format("%7d%7d%7d\n", --lines, words, --symbols);
          }
        }
        catch(IOException e) {
          System.out.println("Ошибка: "+e);
        }
      }
    
      static int NumberWords(String s) //количество слов в строке
      {
        char c='-';
        int num=0;
        boolean change=false; //сделано чтобы пустые строки не прибавляли значение num
        
        for(int i=0; i<s.length(); i++) {
          if( s.charAt(i)==' ' && (c!=' ' && c!='\t')
              || s.charAt(i)=='\t' && (c!=' ' && c!='\t') ) num++; //новое слово
          c = s.charAt(i);
          if(!change ) change=true;
        }
        if(change && c!=' ') num++; //последнее слово
        return num;
      }
      
      static int NumberSymbols(String s)
      {
        int count=0;
        for(int i=0; i<=s.length(); i++)
          count++;
        return count;
      }
      
      static void getInfo()
      {
        try( BufferedReader b = new BufferedReader(new FileReader("help")) )
        {
          String s;
          while( (s=b.readLine()) != null )
            System.out.println(s);
        }
        catch(IOException e) {
          System.out.println("Файл справки отсутствует");
        }
      }
    }

    Переписываю все программы из linux на java, это говно-наработки

    GOVNOCODER-SYKA, 28 Сентября 2017

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