Skip to content

Instantly share code, notes, and snippets.

Raine Revere raineorshine

Block or report user

Report or block raineorshine

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cake-vs-gulp.md

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 / better-passport.js
Created Mar 12, 2014
Ideation for better PassportJS.
View better-passport.js
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 / serializeArrayToObject.js
Created Mar 12, 2014
Convert the results from jQuery's serializeArray to an object.
View serializeArrayToObject.js
var formData = $('#myform').serializeArray();
_.merge.apply(_, formData.map(function(o) { var kvp={}; kvp[o.name] = o.value; return kvp; }))
@raineorshine
raineorshine / d3-gapminder-improved.js
Created Mar 13, 2014
Some suggestions for improving the asynchronous part of https://github.com/gdiboulder/d3-gapminder.
View d3-gapminder-improved.js
// 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 Mar 17, 2014
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…
View async-example.js
// 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 Mar 18, 2014
A simple node script to convert a file of date strings to milliseconds.
View _usage.sh
./dateparse.js dates.txt out.txt
@raineorshine
raineorshine / tech-presentation-skills.md
Created Mar 19, 2014
Tech Presentation Skills: 5 DO's, 4 DON'Ts, and 3 things to NEVER FORGET.
View tech-presentation-skills.md

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 / private-instance-methods1.js
Created Mar 26, 2014
Simulating private instance methods.
View private-instance-methods1.js
// 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 Mar 29, 2014
why programming with callbacks is hard (jcoglan)
View callbacks-are-hard.md

"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."

You can’t perform that action at this time.