Skip to content

Instantly share code, notes, and snippets.

Quick log of a refactoring pattern I've been using lately. Function.bind lets you curry methods, which is useful for throwing in more parameters to functions called outside of your control, like in functional Array methods or callbacks.

For instance:

window.setTimeout(function() {
  foo.bar(baz);
}, 10);
@mbostock
mbostock / .block
Last active February 9, 2016 02:03 — forked from mbostock/.block
Projected Choropleth
license: gpl-3.0
var Dispatcher = require('the-dispatcher'),
Immutable = require('immutable'),
NotificationConstants = require('../constants/notification_constants'),
UserConstants = require('../constants/user_constants'),
UploadConstants = require('../constants/upload_constants'),
StylesheetConstants = require('../constants/stylesheet_constants'),
makeStore = require('makestore');
/**
* The Notification Store does nothing but store recent actions
@mars
mars / rewire-module.js
Last active September 15, 2016 08:51
Manually mock React components; Jasmine helper to stub & teardown a bunch of a module's dependencies with Rewire. How-to: http://substantial.com/blog/2014/11/11/test-driven-react-how-to-manually-mock-components/
/*
Jasmine helper to stub & teardown a bunch of a module's dependencies.
describe("SomeModule", function() {
var SomeModule = rewire("some-module");
rewireModule(SomeComponent, {
ItsComponent: React.createFactory('div'),
AnotherComponent: React.createFactory('div')
@shawnbot
shawnbot / README.md
Last active October 17, 2017 05:55
Bar charts in Sketch? Yep.

This is a Sketch script to make bar charts.

bars

Here's how to run it:

  1. Make a selection of only shapes with names in the format:
(anything)value={number}
@nrn
nrn / react-internals.md
Last active April 1, 2018 18:02
Notes for react internals discussion.

react internals discussion

React: a robust functional view layer.

View code and templating are combined as JavaScript.

In JavaScript you create a virtual DOM, react diffs changes between the last virtual DOM and the next, mutating the real DOM only as necessary to reflect the changes. This has huge implications for cognitive

@ZJONSSON
ZJONSSON / README.md
Created October 19, 2012 13:59 — forked from mbostock/.block
d3.legend example

d3.legend

d3.legend is a quick hack to add a legend to a d3 chart. Simply add a g and .call(d3.legend). Any elements that have a title set in the "data-legend" attribute will be included when d3.legend is called. Each title will appear only once (even when multiple items define the same data-legend) as the process uses a set based on a existing names, not an array of all items.

Color

By default the color in the legend will try to match the fill attribute or the stroke attribute of the relevant items. Color can be explicitly defined by attribute "data-legend-color"

Order

The order of items in the legend will be sorted using the top of the bounding box for each included item. The order can be explicitly defined by attribute "data-legend-pos"

@imjared
imjared / scraping-with-casperjs.js
Created March 20, 2013 00:33
A CasperJS script that crawled a list of links on then scraped the relevant content on each page and output it to a nicely formatted XML file. Sure beats database dumps/SQL manipulation, in my opinion.
/*jshint strict:false*/
/*global CasperError console phantom require*/
/**
* grab links and push them into xml
*/
var casper = require("casper").create({
});
@jstcki
jstcki / .block
Last active August 10, 2018 04:37
Interpolate anything with React Motion
license: mit

Backing up a GPG private key to a QR code

Use at your own risk! As with any backup method, test out your backup by restoring from it before you trust it.

  1. Install qrcode to generate the QR code:

     pip install qrcode
    
  2. Export the key, piping the output to qr, and save this to a png file: