Skip to content

Instantly share code, notes, and snippets.

View prestonp's full-sized avatar
😍
you had me at hello world

Preston Pham prestonp

😍
you had me at hello world
View GitHub Profile
@prestonp
prestonp / bash_profile.md
Last active December 19, 2015 06:29
My .bash_profile for OSX

PS1 with Current Git Branch

Install git-completion to ~/.git-completion.sh and git-prompt to ~/.git-prompt.sh.

Then set up

~/.bash_profile

@prestonp
prestonp / controller.js
Created November 21, 2013 17:16
A db enums module
// An example of a controller that would require the enums
var enums = require('./enums')(); // Get a singleton
/**
* Assuming a page isn't served before the asynchronous data is returned
* this should give us cached data
*/
var get = function(req, res) {
res.render('page', { tags: enums.getTags() });
}
@prestonp
prestonp / quicksort.md
Last active August 29, 2015 13:56
underscore quicksort

Save and run as sort.js with a list of integers as arguments

node sort.js 1 3 2 9 3 22

output

[ 1, 2, 3, 3, 9, 22 ]
@prestonp
prestonp / gist:9535819
Last active August 29, 2015 13:57
unexepected timestamp handling
var models = require('./models');
var utils = require('./utils');
var config = require('./config');

models.Order.find({}, function(err, results) {
  console.log('models.Order.find type of datetime',results[0].attributes.datetime);
  console.log('type of datetime', typeof results[0].attributes.datetime);
});
@prestonp
prestonp / gist:9842745
Last active August 29, 2015 13:57
aggregate arrays in postgresql

Tables

Table restaurants
        Column         |           Type           
-----------------------+--------------------------
 id                    | integer                  
 
Table contacts
    Column     |            Type             
@prestonp
prestonp / example.md
Created April 14, 2014 17:27
scheduler example

Declare actions.js

var scheduler = require('../lib/scheduler');
scheduler.registerAction('make-call', function(job, done) {
  twilio.makeCall(job.data, function(error) {
    if (error) {
      logger.error('Could not place call for job #' + job.id, error);
      done('failed');
 } else {
@prestonp
prestonp / heapdump.js
Last active August 29, 2015 14:01
heapdump
// Step 1: npm install heapdump
// Step 2: Paste this snippet in your main
// app to create heap snapshots that you
// can view in the chrome profiler
require('heapdump');
setInterval(function() {
process.kill(process.pid, 'SIGUSR2');
}, 15000);
@prestonp
prestonp / readme.md
Last active August 29, 2015 14:01
stampy

Usage

Stampy is used to log time differences. You could use it to profile time-consuming operations.

Note that the first .log() begins the starting timestamp. Consecutive .log() just prints the diff from the last timestamp.

var stampy = require('stampy');
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
line-height: 1.5em;
@prestonp
prestonp / dirac-plugins.js
Last active August 29, 2015 14:03
dirac plugins
// monkey patches dirac with ./plugins folder
var dirac = require('dirac');
modules.exports = function(options) {
options = options || {};
// plugins folder contains table folders, each containing plugin definitions
fs.readDir(options.path || './plugins');
// pseudocode