Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@raineorshine
raineorshine / cake-vs-gulp.md
Last active August 29, 2015 13:56
Cake vs Gulp

Cake

  • Doesn't output stdout or stderr of task commands automatically, so you have to do something like this:

     {print} = require 'util'
     {spawn} = require 'child_process'
     
     task 'build', 'Build js/ from src/', ->
     	coffee = spawn 'coffee', ['-c', '-o', 'js', 'src']
     	coffee.stderr.on 'data', (data) ->
@raineorshine
raineorshine / serializeArrayToObject.js
Created March 12, 2014 18:26
Convert the results from jQuery's serializeArray to an object.
var formData = $('#myform').serializeArray();
_.merge.apply(_, formData.map(function(o) { var kvp={}; kvp[o.name] = o.value; return kvp; }))
@raineorshine
raineorshine / better-passport.js
Created March 12, 2014 18:37
Ideation for better PassportJS.
app.use(auth({
clientID: 'FACEBOOK_APP_ID',
clientSecret: 'FACEBOOK_APP_SECRET',
sessionSecret: 'SESSION_SECRET',
userCollection: 'User',
callback: '/callback',
login: '/login',
// login: function(done) {
// auth.login({
// role: req.query.role
@raineorshine
raineorshine / d3-gapminder-improved.js
Created March 13, 2014 16:04
Some suggestions for improving the asynchronous part of https://github.com/gdiboulder/d3-gapminder.
// NOTE: The below is pseudo-code. You may need to make some adjustments to
// function signatures to use an asynchronous library like async.js
// these functions can be made truly asynchronous by accepting a callback
// this is preferrably to daisy chaining them, which is too tight a coupling
dv.get.gdp = function(cb) {
d3.csv('data/gdp.csv', function(error, data) {
dv.setup.massage(data, 'gdp');
cb(error, data);
});
@raineorshine
raineorshine / async-example.js
Created March 17, 2014 20:56
A demonstration of asynchronous code that starts off broken (db.close is invoked before the db calls return) then is parallelized by only returning the results after all db calls have returned, then leverages async.js to abstract away some of the logic. The last example simplified it even further by avoiding the IIFE that was needed to bind i to…
// 1. BROKEN ASYNC CODE
var getDocuments = function(done) {
var ids = [1,2,3,4,5];
var results = [];
db.open()
for(var i=0; i<ids.length; i++) {
db.findById(ids[i], function(err, doc) {
@raineorshine
raineorshine / _usage.sh
Created March 18, 2014 23:37
A simple node script to convert a file of date strings to milliseconds.
./dateparse.js dates.txt out.txt
@raineorshine
raineorshine / tech-presentation-skills.md
Created March 19, 2014 16:35
Tech Presentation Skills: 5 DO's, 4 DON'Ts, and 3 things to NEVER FORGET.

DO

  1. DO project your voice
  2. DO make eye contact with your audience
  3. DO quietly move on if an error occurs
  4. DO have all logins predetermined
  5. DO make sure your site doesn't break when the font size increases

DON'T

  1. DON'T apologize (or say "whoops", "shoot", etc)
  2. DON'T be self-deprecating
@raineorshine
raineorshine / winter2014-demo-day-urls.md
Last active August 29, 2015 13:57
Winter2014 Demo Day URL's
@raineorshine
raineorshine / private-instance-methods1.js
Created March 26, 2014 14:16
Simulating private instance methods.
// This is probably the cleanest approach, but forces you to use
// privateMethod.call(this) syntax.
// MyClass module
(typeof module !== 'undefined' ? module.exports : window).MyClass = (function() {
// private
var sayHi = function() {
return 'Hi ' + this.name;
};
@raineorshine
raineorshine / callbacks-are-hard.md
Created March 29, 2014 21:18
why programming with callbacks is hard (jcoglan)

"null values returned by callback-based functions are the root of why programming with callbacks is hard: callback-based functions do not return anything, and so are hard to compose. A function with no return value is executed only for its side effects – a function with no return value or side effects is simply a black hole. So programming with callbacks is inherently imperative, it is about sequencing the execution of side-effect-heavy procedures rather than mapping input to output by function application. It is about manual orchestration of control flow rather than solving problems through value relationships. It is this that makes writing correct concurrent programs difficult."