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
const request = require('request'); | |
export const HttpService = { | |
get: async (uri: string): Promise<any> => { | |
return await new Promise((resolve: any, reject: any) => { | |
request.get({ uri }, (error: Error, _response: any, body: any) => { | |
if (error) { | |
console.error(error); | |
reject(); | |
} |
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
# Stage 1 - building | |
FROM golang:1.13-alpine3.10 as build | |
WORKDIR /go/src/app | |
COPY . . | |
RUN go build | |
# Stage 2 - optimised container | |
FROM alpine:3.10 | |
COPY --from=build /go/src/app/main . | |
EXPOSE 8080 |
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
// Return JWT header using HS256 algorithm | |
func generateHeader() (s string) { | |
header := `{"alg": "HS256", "typ": "JWT"}` | |
encoded := b64.StdEncoding.EncodeToString([]byte(header)) | |
return strings.TrimRight(encoded, "=") | |
} | |
// Return JWT payload with some some example data e.g. expiration and username | |
func generatePayload(username string) (s string) { | |
exp := int(time.Now().Add(expThreshold).Unix()) |
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
// GET: Send the request | |
res, err := http.Get("http://example.com/api/someContext") | |
if err != nil { | |
log.Println(err) | |
} | |
// Read HTTP response into []byte | |
body, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
log.Println(err) |
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
import "github.com/gorilla/mux" | |
// Setup and create handlers | |
router := mux.NewRouter().StrictSlash(true) | |
router.HandleFunc("/api/example", getExample).Methods("GET") | |
// Able to set up a function to execute before each request | |
_ = http.ListenAndServe(":"+port, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
// Do something here | |
router.ServeHTTP(w, r) |
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
// JSON | |
type SomeData struct { | |
Id int `json:"id"` | |
Status string `json:"status"` | |
} | |
var data []SomeData | |
data = append(data, SomeData{1, "Hello World"}) |
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
// Removing: If you already know the index | |
someArray = append(someArray[:i], someArray[i+1:]...) | |
// Optional to remove multiple based on value | |
for i, value := range someArray { | |
if value == someOtherValue { | |
someArray = append(someArray[:i], someArray[i+1:]...) | |
} | |
} |
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
const data: ILiveData[] = await <any>MongoService.findOne('live', {}); | |
findOne: async (collection: string, query: any) => { | |
return new Promise((resolve: any) => { | |
database.collection(collection).findOne(query, (error: Error, res: any) => { | |
if (error) { | |
throw error; | |
} | |
resolve(res); | |
}); |
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
# Preferences | |
export ZSH="/Users/olafkotur/.oh-my-zsh" | |
# Plugins | |
ZSH_THEME="olafkotur" | |
plugins=(git tmux) | |
source $ZSH/oh-my-zsh.sh | |
# Alias: Directories | |
alias dev="cd && cd ~/Development" |
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
import nodemailer from 'nodemailer'; | |
export const EmailService = { | |
send: async (subject: string, to: string, body: string) => { | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.gmail.com', | |
port: 587, | |
secure: false, | |
auth: { |
NewerOlder