Skip to content

Instantly share code, notes, and snippets.

@hn3000
hn3000 / gist:98ecc891c5588de6445bbe28016d78ad
Created February 16, 2017 07:08
tweetable JSON Pointer Implementation in modern JavaScript
/**
* p is pointer
* o is object
* returns value pointed at by p or undefined
*/
(p,o) => p.split("/").slice(1).map(s => s.replace(/~1/g,'/').replace(/~0/g,'~')).reduce((o,k) => o&&o[k], o)
( https://twitter.com/hn3000/status/744970555883925504 )
@hn3000
hn3000 / samldecode.js
Created April 12, 2017 23:06
real simplistic SAML request decoder
#!/usr/bin/env node
var { Buffer } = require('buffer');
var zlib = require('zlib');
var param = process.argv[2];
var raw = Buffer.from(decodeURIComponent(param), 'base64');
var decoded = zlib.inflateRawSync(raw);
console.log(decoded.toString());
@hn3000
hn3000 / gist:af9c0584a45f71c40b1ed48ce41fe057
Created June 1, 2017 22:28
so-so stuff to use with react
# List of state management libraries
https://github.com/mobxjs/mobx
https://github.com/mobxjs/mobx-react
https://github.com/reflux/refluxjs
https://github.com/mattdennewitz/universal-redux-boilerplate
https://github.com/olegakbarov/react-redux-starter-kit
@hn3000
hn3000 / gist:7b6a04105017010aecb8778e28dc4b03
Last active July 11, 2017 11:52
include images and other resources in a repo's wiki
1) add the resource into a folder of the wiki repository
1a) clone the wiki repo, it's git url can be found on the right hand side of wiki pages
1b) create folder, add resource, push to repo
2a) add link to resource: [link to pdf](../assets/Filename.pdf)
2b) image link: [[assets/image.png]]
@hn3000
hn3000 / gist:02d75ab05921701412cd4247f8e2e909
Created July 12, 2017 09:14
collection of typescript typing snippets
// make sure literal conforms to type
let var: Type = {
prop,
prop2: 123,
extra: 'value' // will give an error for extra properties
};
// make sure properties from type are spelled correctly
@hn3000
hn3000 / aggregation.ts
Created November 14, 2017 23:05
(pretty) generic aggregation / grouping function using reduce
function aggregate<I, V>(
items: I[],
valueFun: (i: I) => V,
groupingFun: (i: I) => string,
combineFun: (v1: V, v2: V) => V
): ({ [g:string]: V }) {
return items.reduce(
(r: { [g: string]: V }, i: I) => {
@hn3000
hn3000 / numbers-by-width-in-font.html
Last active July 7, 2018 10:20
Sort numbers by width in Helvetica, as suggested by XKCD 2016
<!doctype html>
<html>
<head>
<title>Numbers ordered by width in Helvetica</title>
<style>
body { font: 13px Helvetica; }
</style>
</head>
<body>
<h1>Sort numbers by Width</h1>
function roundToDigits(x,n) {
let digits = Math.ceil(Math.log(x) / Math.log(10));
let scale = Math.pow(10, n - digits);
return Math.round(x * scale)/scale;
}
@hn3000
hn3000 / shallowMerge.ts
Created November 13, 2018 11:56
shallow merge, one of my favourites
function shallowMerge(a:any, b:any):any {
let result:any = {};
let tmp:any = {};
Object.keys(a).forEach((x) => tmp[x]=x);
Object.keys(b).forEach((x) => tmp[x]=x);
let keys = Object.keys(tmp);
for (var k of keys) {
result[k] = null != b[k] ? b[k] : a[k];
}
@hn3000
hn3000 / gist:8ea3eab2910fa37a9e8321f106310947
Created November 19, 2018 13:30
my vscode (-insiders) extensions
$ code-insiders --list-extensions
GregorBiswanger.json2ts
Pivotal.vscode-boot-properties
abotteram.typescript-react-snippets
alefragnani.project-manager
alexcvzz.vscode-sqlite
Arjun.swagger-viewer
bajdzis.vscode-database
chrmarti.regex
cssho.vscode-svgviewer