Skip to content

Instantly share code, notes, and snippets.

Rico Kahler ricokahler

View GitHub Profile
ricokahler / index.js
Last active May 23, 2020
color2k in one file
View index.js
import parseToRgba from '@color2k/parse-to-rgba';
export { default as parseToRgba } from '@color2k/parse-to-rgba';
// taken from:
* Parses a color in hue, saturation, lightness, and the alpha channel.
* Hue is a number between 0 and 360, saturation, lightness, and alpha are
* decimal percentages between 0 and 1
ricokahler / memoIgnoringFunctions.js
Last active Sep 19, 2019
React.memo but it ignores functions changes
View memoIgnoringFunctions.js
import React, { memo, useMemo, useLayoutEffect, useRef } from 'react';
import objectHash from 'object-hash';
import _partition from 'lodash/partition';
import _fromPairs from 'lodash/fromPairs';
* an HOC that uses `React.memo` to memoize component expect it ignores changes
* to functions while also keeping those functions up-to-date somehow
function memoIgnoringFunctions(Component, propsAreEqual) {
ricokahler / Component.js
Created Sep 19, 2019
Only add the event listener once
View Component.js
import React, { useCallback } from 'react';
function usePullValue(value) {
const ref = useRef(value);
useLayoutEffect(() => {
ref.current = value;
}, [value]);
return useCallback(() => {
ricokahler / api.ts
Last active Jul 3, 2018
Retain Data API
View api.ts
interface Request {
queries: Array<Query>;
filters?: Filter;
interface Response extends Array<Result> {}
interface Result {
id: string;
results: Array<number>;
ricokahler / .gitignore
Last active Jun 7, 2018
Material-ui typescript bug
View .gitignore
ricokahler / map-reduce.ts
Created Apr 7, 2018
map - reduce in javascript
View map-reduce.ts
class Something {
foo: string;
bar: string;
x: number;
constructor(x: number) {
this.x = x; = 'foo'; = 'bar';
ricokahler / index.html
Last active Mar 9, 2018
simple web app
View index.html
<title>what up</title>
<h1 class="foo"></h1>
<div class="stuff"></div>
async function loadData() {
const response = await fetch('');
View map-promises.ts
export async function sequentially<T, R>(list: T[], asyncFunction: (t: T) => Promise<R>) {
const newList = [] as R[];
for (const i of list) {
newList.push(await asyncFunction(i));
return newList;
// then use like so:
View poly py
class Polynomial:
def __init__(self, coefficient, exponent, next = None):
self.coefficient = coefficient
self.exponent = exponent = next
def _add(term_a, term_b):
if term_a == None:
return term_b
View test.js
// Generated by JSIL v0.8.2 build 13182. See for more information.
'use strict';
var $asm00 = JSIL.GetAssembly("1dd27d7b, Version=, Culture=neutral, PublicKeyToken=null");
var $asm01 = JSIL.GetAssembly("mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089");
var $asm02 = JSIL.GetAssembly("System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089");
/* Generated by JSIL v0.8.2 build 13182. See for more information. */
'use strict';
var $asm00 = JSIL.DeclareAssembly("1dd27d7b, Version=, Culture=neutral, PublicKeyToken=null");
You can’t perform that action at this time.