Skip to content

Instantly share code, notes, and snippets.

View moimikey's full-sized avatar
:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
View GitHub Profile
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
const hashCode = (s) => {
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
};
const memoizeObservable = (fn) => {
let cache = {};
return (...args) => {
let entryKey = hashCode(JSON.stringify(args));
@max-mapper
max-mapper / test.js
Last active August 29, 2015 14:24
tape + http local server test scaffolding
// the two testing modules I like
var test = require('tape')
var spawn = require('tape-spawn')
var execspawn = require('npm-execspawn') // can spawn from require() scope, check it out!
// put this in outer scope so we can kill the local server at the end
var server
test('start test server', function (t) {
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@gaearon
gaearon / actionsactionsactionsactions.js
Created June 16, 2015 12:06
Basic action monitoring for Redux
// App.js
import { Provider, Connector } from 'redux/react';
import monitor from './monitor/index';
const store = composeStores(stores);
const { dispatcher, ActionLog } = monitor(createDispatcher(store));
const redux = createRedux(dispatcher);
export default class App {
@max-mapper
max-mapper / index.js
Created June 14, 2015 00:14
bytebeat studio.substack.net
var fns = [function (t) { return ((t*t)/(t^t>>8))&t },
function (t) { return (t>>4 & t>>8)*(t>>16&t) },
function (t) { return (t>>4 & t>>8)/(t>>16&t) },
function (t) { return ((2*(t&1)-1)*t)-(t>>8) },
function (t) { return (t>>5)*((t&1)+(t>>16)) },
function (t) { return (((Math.sin(t*t/10000000))>0.5)-1)*t },
function (t) { return (((-t&t>>12)/32)-1)*t },
function (t) { return (((-t&128)/64)-1)*t },
function (t) { return Math.sin(t/5+(Math.sin(t/5))+t/1000)*64+t/2500 },
function (t) { return Math.sin(t/5+((Math.sin(t/5)/(t/(4000*(t>>8^t>>4))))))*64+128 },
@therealklanni
therealklanni / README.md
Last active January 27, 2020 17:07
Infinitely repeating arrays in JavaScript ... kind of

repeat(a) -> [a]

Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat function:

repeat :: a -> [a]

So as you can see in repeat.js, I have done exactly that. However there are some caveats.

@ohanhi
ohanhi / frp.md
Last active May 6, 2024 05:17
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Editorial note

@dandelany
dandelany / gist:1ff06f4fa1f8d6f89c5e
Last active March 27, 2024 10:06
Recursively cloning React children
var RecursiveChildComponent = React.createClass({
render() {
return <div>
{this.recursiveCloneChildren(this.props.children)}
</div>
},
recursiveCloneChildren(children) {
return React.Children.map(children, child => {
if(!_.isObject(child)) return child;
var childProps = {someNew: "propToAdd"};
@gaearon
gaearon / combining.js
Created June 3, 2015 18:03
Combining Stateless Stores
// ------------
// counterStore.js
// ------------
import {
INCREMENT_COUNTER,
DECREMENT_COUNTER
} from '../constants/ActionTypes';
const initialState = { counter: 0 };
@johanobergman
johanobergman / 1. Info.md
Last active February 7, 2019 21:01
Laravel-style DI in JavaScript

Laravel-style DI in JavaScript

Honestly, coming from PHP, I really don't like the way dependencies are handled in JavaScript. Using require() or import either gives me a singleton object, or a class that I have to instantiate myself.

The DI container in Laravel is wonderful, and allows you to basically just ask for a dependency in a class constructor and it hands it to you. You can bind things to the container, but you can also resolve things without explicitly binding them, which I think is awesome.