1. Go / Говнокод #28943

    +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
    package main
    
    import (
    	"io"
    	"fmt"
    	"log"
    	"bytes"
    	"strings"
    	"net/http"
    	"net/http/httputil"
    	"net/url"
    )
    
    func UpdateResponse(r *http.Response) error {
    	for k, v := range r.Header {
    		newValue := strings.Replace(v[0], "umnico.com", "umnico.*****.ru", -1)
    		r.Header[k][0] = newValue
    	}
    	b, err := io.ReadAll(r.Body)
    	if(err == nil) {
    		bodyText := strings.Replace(string(b), "://umnico.com", "://umnico.*****.ru", -1);
    		if(strings.Contains(bodyText, "</head><body>")) {
    			injectedStyle := `<style>
    			.nav-menu.hidden, .widget__preview-container--tech-support {
    				display: none !important;
    			}
    			</style>`
    			bodyText = strings.Replace(bodyText, "</head><body>", injectedStyle + "</head><body>", -1);
    		}
    		if(strings.Contains(bodyText, "</body></html>")) {
    			injectedScript := `<script>
    			fetch('/api/user').then((response) => { 
    				return response.json().then((data) => {
    					//alert(data.user.id);
    					if(data.user.id != 12345) {
    						const style = document.createElement('style');
    						style.textContent = '.im__chat-buttons{display:none!important;}';
    						document.head.appendChild(style);
    					}
    					return true;
    				}).catch((err) => {
    					console.log(err);
    				}) 
    			});
    			var currentDialogId = 0;
    			function checkDialogControls() {
    				if(location.pathname.indexOf('app/deals/inbox/details/') > 0 || location.pathname.indexOf('app/deals/active/details/') > 0) {
    					if(location.pathname.indexOf('app/deals/active/details/') > 0) {
    						var dialogId = location.pathname.split('app/deals/active/details/')[1];
    					} else {
    						var dialogId = location.pathname.split('app/deals/inbox/details/')[1];
    					}
    					var chatIndicator = document.querySelector('.im-aside-section.im-aside-section__toolbox');
    					if(chatIndicator != null) {
    						var injectedControls = document.querySelector('.im-aside-section.injected-controls');
    						if(injectedControls == null) {
    							chatIndicator.insertAdjacentHTML('afterend', '<div class="im-aside-section injected-controls"><div><button type="button" class="button" style="width:100%;" onclick="window.parent.postMessage(\'openBookingModalByUmnicoId('+dialogId+')\', \'*\');">Оформить бронь</button></div><div style="margin-top:5px;"><button type="button" class="button button_attention" style="width:100%;" onclick="window.parent.postMessage(\'openLeadTaskModalByUmnicoId('+dialogId+')\', \'*\');">Задача</button></div></div>');
    						} else {
    							if(currentDialogId != dialogId) {
    								injectedControls.remove();
    							}
    						}
    						currentDialogId = parseInt(dialogId);
    					}
    				}
    			}
    
    			setInterval(checkDialogControls, 100);
    			</script>`
    			bodyText = strings.Replace(bodyText, "</body></html>", injectedScript + "</body></html>", -1);
    		}
    		
    		if(strings.Contains(bodyText, "window.location.hostname != \"localhost\"")) {
    			bodyText = strings.Replace(bodyText, "window.location.hostname != \"localhost\"", "window.location.hostname != \"localhost\" && window.location.hostname != \"umnico.*****.ru\"", -1);
    		}
    		
    		buf := bytes.NewBufferString(bodyText)
    		r.Body = io.NopCloser(buf)
    		r.Header["Content-Length"] = []string{fmt.Sprint(buf.Len())}
    	}
    	return nil
    }
    
    func main() {
    	target, err := url.Parse("https://umnico.com:443")
    	if err != nil {
    		log.Fatal(err)
    	}
    	proxy := httputil.NewSingleHostReverseProxy(target)
    	proxy.ModifyResponse = UpdateResponse
    	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    		req.Host = req.URL.Host
    		proxy.ServeHTTP(w, req)
    	})
    	err = http.ListenAndServe("127.0.0.1:8803", nil)
    	if err != nil {
    		panic(err)
    	}
    }

    Мой код для проксирования одного из SaaS-сервисов, с целью встраивания в интерфейс последнего кастомных кнопок. Взглянул спустя пару месяцев и ужаснулся.

    rotoeb, 17 Мая 2024

    Комментарии (421)
  2. Go / Говнокод #28821

    +2

    1. 1
    var color bool

    3_dar, 15 Июля 2023

    Комментарии (45)
  3. Go / Говнокод #28590

    −2

    1. 1
    a := []string{"Yandex.ru","mos.ru","sberbank.ru"}

    kkk

    allalalall, 07 Февраля 2023

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

    −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
    package main
    
    import (
        "fmt"
        "log"
    )
    
    func square(x int) (int, error) {
        return x * x, fmt.Errorf("Какой багор )))")
    }
    
    func main() {
        var err error
        a := 10
        if a % 2 == 0 {
            res, err := square(a)
            if err != nil {
                err = fmt.Errorf("Какой багор 2 )))")
            }
            log.Printf("res=%v", res)
        }
        log.Printf("err=%v", err)
    }

    Какой багор )))

    https://github.com/dominikh/go-tools/issues/917

    3_dar, 23 Января 2023

    Комментарии (7)
  5. Go / Говнокод #28393

    −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
    // first is information about the first byte in a UTF-8 sequence.
    var first = [256]uint8{
    	//   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x00-0x0F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x10-0x1F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x20-0x2F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x30-0x3F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x40-0x4F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x50-0x5F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x60-0x6F
    	as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x70-0x7F
    	//   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
    	xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x80-0x8F
    	xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x90-0x9F
    	xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xA0-0xAF
    	xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xB0-0xBF
    	xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xC0-0xCF
    	s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xD0-0xDF
    	s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, // 0xE0-0xEF
    	s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xF0-0xFF
    }

    как вы уже догадались, это у тэ эф восемь

    "as" это as is
    xx -- хуйня хуёвая
    s1 -- size1 и пр

    Такое вот табличное программирование

    DypHuu_niBEHb, 03 Октября 2022

    Комментарии (6)
  6. Go / Говнокод #28342

    +1

    1. 1
    Конструктор по умолчанию?

    Не, не слышали.
    Рефлексией итерируемся по свойствам и вызываем функцию инициализации полей ))))))))))))))

    3_dar, 22 Августа 2022

    Комментарии (62)
  7. Go / Говнокод #28254

    +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
    package main
    
    import "log"
    
    func foo(x int) (int, error) {
        return x + 1, nil
    }
    
    func main() {
        x := 5
        if x % 2 == 1 {
            x, err := foo(x)
            if err != nil {
                log.Fatalf("Error")
            }
            log.Println(x)
        }
        log.Println(x)
    }

    Счастливой отладки, суки.

    https://godbolt.org/z/6GWsq7W7q

    3_dar, 29 Июня 2022

    Комментарии (47)
  8. Go / Говнокод #28193

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    package main
     
    func main() {
        var str = "Hello World"
        var length = len([]rune(str))
        println("Length of the string is :", length)
    }

    String Length in Golang

    To get the length of a String in Go programming, convert the string to array of runes, and pass this array to len() function.

    3_dar, 26 Мая 2022

    Комментарии (93)
  9. Go / Говнокод #28110

    +1

    1. 1
    2. 2
    math.Min(float64, float64) float64
    math.Max(float64, float64) float64

    В goвне нету math.Min для integer. Даже в анскильном "Си" это есть.

    https://www.pixelstech.net/article/1559993656-Why-no-max-min-function-for-integer-in-GoLang

    3_dar, 05 Апреля 2022

    Комментарии (39)
  10. Go / Говнокод #27924

    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
    func down(h Interface, i0, n int) bool {
    	i := i0
    	for {
    		j1 := 2*i + 1
    		if j1 >= n || j1 < 0 { // j1 < 0 after int overflow
    			break
    		}
    		j := j1 // left child
    		if j2 := j1 + 1; j2 < n && h.Less(j2, j1) {
    			j = j2 // = 2*i + 2  // right child
    		}
    		if !h.Less(j, i) {
    			break
    		}
    		h.Swap(i, j)
    		i = j
    	}
    	return i > i0
    }

    Какие же интерфейсы в Go скудные, что заставляют разработчиков использовать функции API внутри вспомогательных в пределах одной сущности. Взято из: https://github.com/golang/go/blob/master/src/container/heap/heap.go

    JaneBurt, 06 Января 2022

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