View goeventbus-final.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"sync" | |
"time" | |
) | |
type DataEvent struct { |
View vscode-extensions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code --install-extension 13xforever.language-x86-64-assembly | |
code --install-extension 42Crunch.vscode-openapi | |
code --install-extension aaron-bond.better-comments | |
code --install-extension AbhijoyBasak.nestjs-files | |
code --install-extension adpyke.vscode-sql-formatter | |
code --install-extension ahmadalli.vscode-nginx-conf | |
code --install-extension ahmadawais.shades-of-purple | |
code --install-extension akamud.vscode-theme-onedark | |
code --install-extension alefragnani.Bookmarks | |
code --install-extension amandeepmittal.pug |
View list.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyList do | |
def max([]), do: nil | |
def max([head | tail]), do: findmax(head, head, tail) | |
defp findmax(current, _next, [head | tail]) do | |
if head > current, do: findmax(head, current, tail), else: findmax(current, current, tail) | |
end | |
defp findmax(current, next, []) do | |
if current > next, do: current, else: next |
View hl7.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
_ "fmt" | |
"net" | |
"strings" | |
"time" | |
) | |
func main() { |
View Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.13 AS builder | |
WORKDIR /app | |
COPY . . | |
RUN CGO_ENABLED=0 GOOS=linux go build -o agent . | |
FROM alpine:latest | |
RUN apk --no-cache add ca-certificates | |
WORKDIR /root | |
COPY --from=builder /app/agent . | |
ENTRYPOINT [ "/root/agent" ] |
View APIError.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const httpStatus = require('http-status') | |
const errorCodes = require('./errorCodes') | |
module.exports = function APIError ( | |
message, | |
status = httpStatus.INTERNAL_SERVER_ERROR, | |
errorCode = errorCodes.UnkownError, | |
errors = null | |
) { |
View lb.snip7.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HealthCheck pings the backends and update the status | |
func (s *ServerPool) HealthCheck() { | |
for _, b := range s.backends { | |
status := "up" | |
alive := isBackendAlive(b.URL) | |
b.SetAlive(alive) | |
if !alive { | |
status = "down" | |
} | |
log.Printf("%s [%s]\n", b.URL, status) |
View lb.snip6.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isAlive checks whether a backend is Alive by establishing a TCP connection | |
func isBackendAlive(u *url.URL) bool { | |
timeout := 2 * time.Second | |
conn, err := net.DialTimeout("tcp", u.Host, timeout) | |
if err != nil { | |
log.Println("Site unreachable, error: ", err) | |
return false | |
} | |
_ = conn.Close() // close it, we dont need to maintain this connection | |
return true |
View lb.snip5.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lb load balances the incoming request | |
func lb(w http.ResponseWriter, r *http.Request) { | |
attempts := GetAttemptsFromContext(r) | |
if attempts > 3 { | |
log.Printf("%s(%s) Max attempts reached, terminating\n", r.RemoteAddr, r.URL.Path) | |
http.Error(w, "Service not available", http.StatusServiceUnavailable) | |
return | |
} | |
peer := serverPool.GetNextPeer() |
View lb.snip4.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) { | |
log.Printf("[%s] %s\n", serverUrl.Host, e.Error()) | |
retries := GetRetryFromContext(request) | |
if retries < 3 { | |
select { | |
case <-time.After(10 * time.Millisecond): | |
ctx := context.WithValue(request.Context(), Retry, retries+1) | |
proxy.ServeHTTP(writer, request.WithContext(ctx)) | |
} | |
return |
NewerOlder