Skip to content

Instantly share code, notes, and snippets.

View jdx's full-sized avatar

jdx

View GitHub Profile
@jdx
jdx / test.rb
Created September 24, 2014 14:06
get '/user/:id' do |user_id|
user = db.find_user(user_id)
return user
end
@jdx
jdx / express.js
Last active October 11, 2015 23:03
express example
app.get('/user/:id', function (req, res) {
db.get(req.params.userId, function (err, user) {
if (err) throw err;
res.json(user);
});
});
@jdx
jdx / install.sh
Last active August 29, 2015 14:05
digital ocean node installation and stuff
yum update -y
yum install -y git nodejs npm vim
npm install -g n
n stable
node --version
git --version
vim /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
yum update -y
yum install -y git nodejs npm vim
npm install -g n
n stable
node --version
git --version
vim /etc/yum.repos.d/mongodb.repo
#[mongodb]
#name=MongoDB Repository
yum update -y
yum install -y git nodejs npm vim
npm install -g n
n stable
node --version
git --version
vim /etc/yum.repos.d/mongodb.repo
#[mongodb]
#name=MongoDB Repository
#!/usr/bin/env bash
cd ~/src
@jdx
jdx / promises.md
Created August 1, 2014 20:54
promise error handling vs callback error handling

Error checking with callbacks:

dbFind('foo', function(err, data) {
  if (err) throw err;
  dbFind(data.id, function(err, data) {
    if (err) throw err;
    dbFind(data.id, function(err, data) {
      if (err) throw err;
 dbFind(data.id, function(err, data) {
@jdx
jdx / boot.js
Last active October 4, 2016 03:42
node cluster loader
'use strict';
var numCpus = require('os').cpus().length
var cluster = require('cluster')
cluster.setupMaster({exec: __dirname + '/server.js'})
// workerIds returns the node cluster index for each worker
function workerIds() { return Object.keys(cluster.workers) }
// Gets the count of active workers
var gulp = require('gulp')
var concat = require('gulp-concat')
var sourcemaps = require('gulp-sourcemaps')
var uglify = require('gulp-uglify')
var ngAnnotate = require('gulp-ng-annotate')
gulp.task('js', function () {
gulp.src(['src/**/module.js', 'src/**/*.js'])
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
@jdx
jdx / gulpfile.js
Last active August 29, 2015 14:03
var gulp = require('gulp')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var ngAnnotate = require('gulp-ng-annotate')
gulp.task('js', function () {
gulp.src(['src/**/module.js', 'src/**/*.js'])
.pipe(concat('app.js'))
.pipe(ngAnnotate())
.pipe(uglify())