Skip to content

Instantly share code, notes, and snippets.

View gmmorris's full-sized avatar

Gidi Meir Morris gmmorris

View GitHub Profile
@gmmorris
gmmorris / mergemaster.sh
Created October 16, 2019 13:03
Refresh Fork's master branch from upstream and merge into the current branch
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
git checkout master
git fetch upstream
git merge upstream/master
git checkout $branch_name
git merge master
@gmmorris
gmmorris / Operator definitions in Reason
Last active June 9, 2018 21:48
Reason cheat sheet
let (|>) v f = f v
let (<|) f v = f v
/*
Possible characters:
! $ % & * + - . / : < = > ? @ ^ | ~
But they can't all be used freely.
Read: http://blog.shaynefletcher.org/2016/09/custom-operators-in-ocaml.html
@gmmorris
gmmorris / TheAPIThatIWantToSupport.js
Created May 16, 2018 19:56
Bucklescript bindings approaches for complex Object based arguments
var CryptographyJs = require("./cryptography.js");
CryptographyJs.hash({ algorithm: 'md5', length: 10 }, "asd");
CryptographyJs.hash({ algorithm: 'md5' }, "asd");
CryptographyJs.hash({ length: 10 }, "asd");
CryptographyJs.hash({}, "asd");
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@gmmorris
gmmorris / setNPMDefaults.sh
Created October 31, 2017 11:10
NPM defaults
npm config set init.author.name "Gidi Meir Morris"
npm config set init.author.email gidi@gidi.io
npm config set init.author.url http://www.gidi.io
npm config set init.license MIT
@gmmorris
gmmorris / gist:0438291a9b31fdd223d44f2c88a5fc7e
Created February 10, 2017 23:30
Roman Numerals converter
const romanNumeral = (char, val) => {
return {
char: char,
val: val,
isBellow: comp => comp > val,
isAbove: comp => comp < val,
is: comp => comp === val,
times: repeat => {
return (new Array(parseInt(repeat))).fill(char).join('')
@gmmorris
gmmorris / diffObjects
Created December 21, 2016 22:06
Diffing of plain objects, assumes lodash
function diffObjects (left, right) {
const leftKeys = Object.keys(left)
const rightKeys = Object.keys(right)
const keyDiff = _.intersection(leftKeys, rightKeys)
.reduce((differentKeys, key) => {
if(_.isPlainObject(left[key]) && _.isPlainObject(right[key])) {
const diff = diffObjects(left[key], right[key])
if(diff !== true) {
differentKeys.push(key)
@gmmorris
gmmorris / conditional.js
Created December 15, 2016 09:00
Build a set of if-elseif-else switches using functions
const conditional = () => {
let elseThen = i => i;
const conditions = [];
function cond (val) {
const res = conditions
.find(condPair => condPair.test(val));
return res
? res.then(val)
: elseThen(val);
@gmmorris
gmmorris / doesntWork.js
Created December 14, 2016 11:34
Flow is failing to infer instanceof checks
/* @flow */
function Children (children : Iterable<any>) {
this.children = Array.from(children)
return this
}
Children.prototype = {
toArray () : any[] {
return this.children
@gmmorris
gmmorris / ComponentCompositionRelabeledLikeFunctionalComposition.js
Created November 28, 2016 16:27
Snippet for "The magical quest for Componentisation"
React.createElement(
parent,
props,
React.createElement( child, childProps )
)