Skip to content

Instantly share code, notes, and snippets.

View hardboiled's full-sized avatar

Daniel Ege hardboiled

View GitHub Profile
@hardboiled
hardboiled / docker-multi-stage-behaviors.md
Last active July 12, 2022 13:27
Description of what occurs with multi-stage docker builds

Multi-stage docker builds

I thought this would help dispell confusion with multi-stage docker builds and how environment variables and build-arguments function with them.

This example file is similar to many multi-stage builds.

FROM alpine:3.16.0 as builder
ARG BUILDTIME_VAR
ENV RUNTIME_VAR "default_runtime_value"
@hardboiled
hardboiled / corsheaders.conf
Created June 7, 2022 20:34
base nginx cors config I copied somewhere for local dev
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
/**
* Convenience method for creating not rigorously random uuids to help with testing staging and development APIs
* Definition based off this answer: https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid#answer-105074
*/
function createFakeUuid () {
return 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx'.split('').map(x => {
const chars = '0123456789abcdef';
const seed = Math.random();
switch (x) {
case 'M':
> npm i -g jwt-decode
> JWT=<your_token> NODE_PATH=$(npm get prefix)/lib/node_modules node
> require('jwt-decode')(process.env.JWT)
// claims will print
@hardboiled
hardboiled / single-file-pr-example-using-github-api.md
Last active February 18, 2020 22:19
An example of how to use github's api to create a PR with a single file change.

How to make a single file PR using github API

(Note this is using github's v3 API. They have a new v4 version that uses graphql. Haven't tried that at the time of writing.)

Using github API is a bit weird at first, because uses the same lower-level git commands that are abstracted away to the normal user. However, this is actually a good thing to some degree, because it means you can do things like changing a single file without copying out an entire branch or repo to your disk.

I will be referencing git objects (blobs, trees, refs, etc.) in this short tutorial, but not covering them in gory detail. You can learn more about them here.

Step 1 Upload a Blob

{
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"compilerOptions": {
"outDir": "dist"
}
{
"name": "example-package-json",
"version": "1.0.0",
"description": "",
"dependencies": {
"csv-parse": "^4.4.1",
"typescript": "^3.4.4"
},
"devDependencies": {
"@types/chai": "^4.1.7",
@hardboiled
hardboiled / example-tslint.ts
Last active June 7, 2019 21:06
Derivative of Google's tslint file
{
"rules": {
"array-type": [true, "array-simple"],
"arrow-return-shorthand": true,
"ban": [true,
{"name": ["it", "skip"]},
{"name": ["it", "only"]},
{"name": ["it", "async", "skip"]},
{"name": ["it", "async", "only"]},
{"name": ["describe", "skip"]},
function serializeParamsIntoUrl(baseUrl: string, params: any) {
let queryParams = []
for (let key in params) {
queryParams.push(`${key}=${params[key]}`)
}
baseUrl += (baseUrl.indexOf('?') < 0) ? '?' : ''
return baseUrl + queryParams.join('&')
}
/*
* Quick Sort implementation in JS, using stack instead of recursion
*/
function quickSort(arr) {
let stack = [[0, Math.floor(Math.random() * arr.length), arr.length - 1]];
while(stack.length > 0) {
let vals = stack.pop();
let startingIndex = vals[0];
let pivot = vals[1];