Skip to content

Instantly share code, notes, and snippets.

View montanaflynn's full-sized avatar

Montana Flynn montanaflynn

View GitHub Profile
@montanaflynn
montanaflynn / promise-timeout.js
Last active January 26, 2021 03:52
Example of running all parallel promises with a race timeout promise in javascript
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 50, 'one');
});
const promise2 = new Promise((resolve, reject) => {
setTimeout(resolve, 60, 'two');
});
const promise3 = new Promise((resolve, reject) => {
setTimeout(resolve, 70, 'three');
@montanaflynn
montanaflynn / .eleventy.js
Created December 7, 2020 01:36
Eleventy config to rewrite links
const markdownIt = require("markdown-it");
const markdownItReplaceLink = require('markdown-it-replace-link');
module.exports = function(eleventyConfig) {
let markdownItOptions = {
html: true,
breaks: true,
linkify: true,
replaceLink: function (link, env) {
link = link.toLowerCase()
@montanaflynn
montanaflynn / aes.go
Last active December 23, 2023 14:39
Decrypt aes-256-ctr in Golang encrypted with node.js
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"strings"
)
@montanaflynn
montanaflynn / aes.js
Last active April 9, 2024 15:01
Encrypt and decrypt text using AES with a shared key in nodejs
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 June 30, 2020 03:38
Docker build example using go mod download --json | jq ... | xargs go get
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 June 30, 2020 03:29
Docker build example using go mod graph | ... | xargs go get
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 June 25, 2020 19:25
Userstyle to align GitHub's new design https://userstyles.org/
/*
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
*/
package main
import (
"fmt"
)
type number interface {
type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128
}
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 June 15, 2020 06:55
Check memory usage for an array of 1 million integers in Golang
package main
import (
"fmt"
"runtime"
)
// 1e7 is 1 million
var listLength int = 1e7