Skip to content

Instantly share code, notes, and snippets.

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')
@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

Simple data manipulations in R

Many years ago, I was introduced to R by Cam Webb . At the time, his website contained a list of common data manipulations (original here). This list dated from Cam's early experience with R, and contained the R-help mailing list responses to a series of data manipulations. For a long time, I kept this file as a handy reference. I printed it out. I recommended it to friends.

Now I have been using R for years, and the state of the art has advanced considerably. Particulary, Hadley Wickham's reshape2 and dplyr packages have transformed the way most useRs manipulate their data. I decided that it would be interesting to revisit my favourite resource and try my hand at solving these problems with tools from these two packages.

library(reshape2)
library(dplyr)
@scotthmurray
scotthmurray / README.md
Last active February 1, 2022 22:32
Fade to Front

Click each shape above to move it to the front.

SVG doesn’t include a concept of z-index, layering, or depth, except that elements that exist later in an SVG document are drawn “on top”. But when designing interactive pieces, we often want shapes that the user has selected / clicked / interacted with to be moved “on top,” to prevent occlusion and ensure visibility.

It’s easy to take an element and simply move it to the bottom of its parent container:

var moveToFront = function() { 
	this.parentNode.appendChild(this); 
}

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:

@mbostock
mbostock / .block
Last active March 30, 2021 06:17
New York Census Tracts
license: gpl-3.0
@spara
spara / scraper.js
Created September 27, 2013 14:38
Example node scraper, runs as cronjob every 15 minutes
var request = require('request');
cheerio = require('cheerio');
util = require('util');
http = require('http');
cronJob = require('cron').CronJob;
var data = new Array();
new cronJob('*/15 * * * * *', function(){
@mbostock
mbostock / .block
Last active February 9, 2016 02:03 — forked from mbostock/.block
Projected Choropleth
license: gpl-3.0
@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({
});