Skip to content

Instantly share code, notes, and snippets.

function getAdder(a) {
return function(b) {
return a + b;
};
}
// Another way to write the same is this:
// const getAdder = a => b => a + b;
const addOne = getAdder(1);
@cowboy
cowboy / dispatch-reparse.js
Last active February 25, 2020 20:53
react-redux mapDispatchToProps helper
const reparse = require('../actions/reparse');
module.exports = function mapDispatchToPropsPlusReparse(fn) {
return function(dispatch, ownProps) {
function reparse() {
return dispatch(reparse(true));
}
return Object.assign({reparse: reparse}, fn ? fn(dispatch, ownProps) : {});
};
};
@cowboy
cowboy / heredoc.js
Last active February 25, 2020 20:53
WIP: ES2015 heredoc helper
function chainOptions(props, fn) {
function getWrapper(options = {}) {
const wrapper = (...args) => fn(options, ...args);
props.forEach(prop => {
Object.defineProperty(wrapper, prop, {
enumerable: true,
get() {
return getWrapper(Object.assign({}, options, {[prop]: !options[prop]}));
},
set() {},
@cowboy
cowboy / 0_reuse_code.js
Created November 30, 2015 15:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cowboy
cowboy / test.js
Last active October 22, 2015 14:34
While I like eslint's comma-dangle set to always-multiline
var noTrailingComma = {
example: 123,
test: 456,
sweet: 'thing',
yay: 'omg',
newthing: true
};
var trailingComma = {
example: 123,
@cowboy
cowboy / indentation.js
Last active February 25, 2020 20:54
JavaScript: chained method indentation
// Inspired by the eslint-plugin-react wrap-multilines rule
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
//
// I don't know why, but this is making me really happy right now.
// Instead of this
var someName = namespace.someObj.method1({
prop: 'value',
}).method2('foo', 'bar');
@cowboy
cowboy / files.txt
Last active August 29, 2015 14:25
Pizzicato Five ‎– The Band Of 20th Century
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 01 Intro.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 02 The Night Is Still Young.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 03 A New Song.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 04 Serial Stories.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 05 Triste.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 06 Sweet Soul Revue.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 07 To Our Children’s Children’s Children.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 08 Ma Vie, L’ete De Vie.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 09 Drinking Wine.mp4
Pizzicato Five - Happy End Of The Band (BS Fuji Studio Last Sessions) - 10 Goodbye Baby & Amen.mp4
@cowboy
cowboy / delayify.js
Created June 11, 2015 12:19
JavaScript: Does My Async Abstraction Work? Per https://twitter.com/ryanflorence/status/608841603956903937
Function.prototype.doesMyAsyncAbstractionWork = function() {
var fn = this;
var args = arguments;
setTimeout(function() {
fn.apply(null, args);
}, Math.random() * 5000);
};
@cowboy
cowboy / ctor-return-function.js
Last active July 8, 2018 03:23
JavaScript: Constructor returning a "function" instance.
var util = require("util");
function Thing() {
// The instance is also a proxy function for its __default method.
var instance = function() {
return instance.__default.apply(instance, arguments);
};
// The instance needs to inherit from Thing.prototype.
instance.__proto__ = Thing.prototype;
// Initialize the instance with the __ctor method.
@cowboy
cowboy / script
Last active August 29, 2015 14:20
Latest Gyazo.app, modified to upload to my server.
#!/usr/bin/env ruby
require 'net/http'
# get id
user = IO.popen("whoami", "r+").gets.chomp
program = ARGV[0].to_s
idfile = "/Users/#{user}/Library/Gyazo/id"
old_idfile = File.dirname(program) + "/gyazo.app/Contents/Resources/id"