Skip to content

Instantly share code, notes, and snippets.

View mertenvg's full-sized avatar
🤖
when in doubt, just use Go

Merten van Gerven mertenvg

🤖
when in doubt, just use Go
View GitHub Profile
<html>
<body>
<form action="" method="post">
<input type="hidden" name="userId" value="88a173b75668cb40fcd67a148c6f8918504c974a" />
</form>
<script>document.forms[0].submit();</script>
<h1>Thanks</h1>
</body>
</html>
@mertenvg
mertenvg / amend_static_env.sh
Created January 30, 2019 13:07
Replace all {{VAR_NAME}} tokens with their corresponding environment variable values into an `env.json` file
#!/usr/bin/env bash
APP_ROOT="${0%/*}/.."
APP_DIST="$APP_ROOT/build"
mkdir -p "$APP_DIST"
cp "$APP_ROOT/src/env.json.tpl" "$APP_DIST/env.json"
# replace all {{VAR_NAME}} tokens with their corresponding environment variable value
@mertenvg
mertenvg / humanTimeDiff.ts
Created January 29, 2019 15:55
Converts a time difference between a given time and the current time to a human friendly string (a.k.a timeago, moments)
const frames = [
{ name: "year", value: (d: number) => Math.floor(d / 29030400000) },
{ name: "month", value: (d: number) => Math.floor(d / 2419200000) },
{ name: "week", value: (d: number) => Math.floor(d / 604800000) },
{ name: "day", value: (d: number) => Math.floor(d / 86400000) },
{ name: "hour", value: (d: number) => Math.floor(d / 3600000) },
{ name: "minute", value: (d: number) => Math.floor(d / 60000) },
{ name: "second", value: (d: number) => Math.floor(d / 1000) },
];
function humanTimeDiff(date: Date, frame: number = 0) {
@mertenvg
mertenvg / merge.ts
Created January 24, 2019 12:48
Typescript deep merge function
function merge(a: any, b: any): any {
return (a !== Object(a) || b !== Object(b))
? b
: Object.keys(b).filter((k: string) => !a[k]).reduce(
(o: { [i: string]: any }, k: string) => {
o[k] = b[k];
return o;
},
Object.keys(a).reduce(
(o: { [i: string]: any }, k: string) => {
@mertenvg
mertenvg / animation.ts
Created September 3, 2018 10:58
TypeScript requestAnimationFrame polyfill
/*
* Resolve requestAnimationFrame and cancelAnimationFrame regardless of whether window exists.
*/
/*
* make window type index-able
*/
interface IndexableWindow {
[key: string]: any
}
// MergeValues merges multiple url.Values into a single url.Values result
func MergeValues(vs ...url.Values) url.Values {
result := url.Values{}
for _, values := range vs {
for k, v := range values {
result[k] = v
}
}
return result
}
@mertenvg
mertenvg / bash-snippets.sh
Last active November 11, 2016 10:43
Useful bash snippets
#
# Remove all but last subdirectories from all but last 2 directories in current directory
#
ls | head -n -2 | xargs -r ls | head -n -1 | xargs -r rm -rf
find . -mindepth 1 -maxdepth 1 -type d | \
sort | head -n -1 | xargs -r -I {} find {} -mindepth 1 -maxdepth 1 -type d | \
sort | head -n -1 | xargs -r rm -rf
@mertenvg
mertenvg / sorted-git-tag-list.sh
Created April 15, 2016 08:18
Show a list of git tags for a repository sorted by date
git tag --sort version:refname
@mertenvg
mertenvg / example.go
Created March 7, 2016 11:32
Another (simpler) example using a task list to handle errors
package main
import (
"errors"
"fmt"
)
// Task represents a callable task to be executed
type Task func() error
@mertenvg
mertenvg / example.go
Created March 6, 2016 18:37
Another example using a task list to handle errors
package main
import (
"errors"
"fmt"
)
// Task represents a callable task to be executed
type Task func()