Skip to content

Instantly share code, notes, and snippets.

View thomhos's full-sized avatar

Thom Hos thomhos

View GitHub Profile
@thomhos
thomhos / gist:34390134b41389414aa21fcd63b238c6
Last active September 27, 2018 10:22
public and private configurables
// You can create a ConfigurableValue which is either 'private' or 'public'.
// When creating the configuration, you pass in the context. Based on that some values are undefined or not.
// Typescript will tell you which ones are available and which ones aren't.
import R from "ramda";
export type Country = string;
export type Language = string;
export type Environment = "production" | "staging" | "branch" | "development";

Keybase proof

I hereby claim:

  • I am thomhos on github.
  • I am thomhos (https://keybase.io/thomhos) on keybase.
  • I have a public key ASDHiaz_KA0Cb26Jrs9PRwkvpfN_dMyoJSUT_rCRzNna6Qo

To claim this, I am signing this object:

@thomhos
thomhos / sort-find.js
Last active February 3, 2018 21:26
bubble sort and binary search
const testArray = [1,2,4,5,3,9,7,8,5,4,9,39,203,495,404,93,39]
const target = 93
const bubbleSort = (inArr) => {
const arr = [...inArr]
for(let i = 0; i < arr.length ; i++) {
for(let j = 0; j < arr.length ; j++) {
if(arr[j] > arr[j + 1]) {
const t = arr[j]
@thomhos
thomhos / push-based.js
Created December 13, 2016 15:45
Push based state change propagation
/*
* Each property has getters and setters with subscribers
*/
let subscribers = new Set()
let activeJob = null
let a = 3
const state = {
get a () {
@thomhos
thomhos / pull-based.js
Created December 13, 2016 15:39
pull-based state change propagation
/*
* State change mechanism
*/
let update
const onStateChange = _update => {
update = _update
}
const setState = newState => {
@thomhos
thomhos / autocomplete.js
Last active October 19, 2016 15:35
Autocomplete with RxJS
// Require libs
var Rx = require('rxjs/Rx');
var yo = require('yo-yo');
// Select dom elements
var inputField = document.querySelector('.input');
var suggestionsEl = document.querySelector('.suggestions');
// Create streams
var response$ = new Rx.BehaviorSubject({ query: '', results: []});
@thomhos
thomhos / destructuring.js
Last active October 17, 2016 12:37
Destructuring
// Basics
fn = ({name, color}) => console.log(name, color); // logs: foo bar
fn = ([name, color]) => console.log(name, color); // logs: foo bar -- in case it comes from an array (by index)
// Renaming
fn = ({ first: firstName }) => console.log(firstName); // logs: foo
@thomhos
thomhos / es6-array.js
Last active October 17, 2016 12:37
Array functions in ES6
const $buttons = document.querySelectorAll('button');
// Create array from an array-like object
const buttonLabels = Array.from($buttons, button => button.textContent) // ['text', 'text']
// Find something in an array
const arr = [1, 2, 8]
@thomhos
thomhos / array.js
Created October 17, 2016 09:31
Array functions
const arr = [1, 2, 3];
// Reduce to object
const obj = arr.reduce((all, item, index) => {
// do something with item and all
all[index] = item;
// return all
return all;
}, {});
@thomhos
thomhos / toggle.js
Last active October 17, 2016 12:37
Switch a boolean
let foo = false;
toggle = val => val = !val;
$thing.on('click', () => foo = toggle(foo));