Skip to content

Instantly share code, notes, and snippets.

Avatar

Montana Flynn montanaflynn

View GitHub Profile
@montanaflynn
montanaflynn / aes.go
Last active Jul 17, 2020
Decrypt aes-256-ctr in Golang encrypted with node.js
View aes.go
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"strings"
)
@montanaflynn
montanaflynn / aes.js
Last active Jul 16, 2020
Encrypt and decrypt text using AES with a shared key in nodejs
View aes.js
const crypto = require('crypto');
const password = 'password';
function encrypt(password, text) {
const algorithm = 'aes-256-ctr';
const key = Buffer.concat([Buffer.from(password), Buffer.alloc(32)], 32);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text);
@montanaflynn
montanaflynn / Dockerfile
Created Jun 30, 2020
Docker build example using go mod download --json | jq ... | xargs go get
View Dockerfile
FROM golang:1.14-alpine AS build
WORKDIR /go/src/app
ENV CGO_ENABLED=0
RUN apk add --no-cache jq
COPY go.mod go.sum ./
RUN go mod download --json | jq -r '"\(.Path)@\(.Version)"' | xargs go get -v
COPY . .
RUN go build -o /go/bin/app
FROM gcr.io/distroless/base
@montanaflynn
montanaflynn / Dockerfile
Created Jun 30, 2020
Docker build example using go mod graph | ... | xargs go get
View Dockerfile
FROM golang:1.14-alpine AS build
WORKDIR /go/src/app
ENV CGO_ENABLED=0
RUN apk add --no-cache jq
COPY go.mod go.sum ./
RUN go mod graph | cut -d '@' -f 1 | cut -d ' ' -f 2 | sort | uniq | tr '\n' ' ' | xargs go get -v
COPY . .
RUN go build -o /go/bin/app
FROM gcr.io/distroless/base
@montanaflynn
montanaflynn / github.userstyle.css
Last active Jun 25, 2020
Userstyle to align GitHub's new design https://userstyles.org/
View github.userstyle.css
/*
You can add this with the stylish extension using this regex:
https:\/\/github\.com/(?!notifications)(.+)
Stylish for chrome: https://chrome.google.com/webstore/detail/stylish-custom-themes-for/fjnbnpbmkenffdnngjfgmeleoegfcffe
Stylish for firefox: https://addons.mozilla.org/en-US/firefox/addon/stylish/
Based off https://gist.github.com/healingbrew/acc65ad439379eabdbb276e86975275e
*/
View main.go
package main
import (
"fmt"
)
type number interface {
type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128
}
View main.go
package main
import (
"fmt"
)
func Contains(type T comparable)(elems []T, target T) bool {
for _, elem := range elems {
if elem == target {
return true
@montanaflynn
montanaflynn / main.go
Created Jun 15, 2020
Check memory usage for an array of 1 million integers in Golang
View main.go
package main
import (
"fmt"
"runtime"
)
// 1e7 is 1 million
var listLength int = 1e7
@montanaflynn
montanaflynn / github.css
Last active May 28, 2020 — forked from tuzz/github.css
Github Markdown Stylesheet
View github.css
/*
Copyright (c) 2017 Chris Patuzzo
https://twitter.com/chrispatuzzo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@montanaflynn
montanaflynn / main.go
Last active Apr 26, 2020
Example of using Golang errgroup with context.WithTimeout()
View main.go
package main
import (
"context"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
You can’t perform that action at this time.