Skip to content

Instantly share code, notes, and snippets.

Ben Ng ben-ng

Block or report user

Report or block ben-ng

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
@ben-ng
ben-ng / gist:297cc283f04638005048
Last active Aug 29, 2015
setTimeout without setTimeout
View gist:297cc283f04638005048
/**
* Just call __PBSJC_drain at the end of your code
*/
var __PBSJC_funcHandles = []
, __PBSJC_funcHandleCount = 0
, __PBSJC_drain = function __PBSJC_drain () {
var extracted, i, ii, cur
while (__PBSJC_funcHandles.length) {
extracted = __PBSJC_funcHandles
@ben-ng
ben-ng / server.js
Created Jun 4, 2015
A simple, slow server for testing deis' zero downtime deploys
View server.js
setTimeout(function () {
require('http').createServer(function (req, res) {
res.end('yo!')
}).listen(process.env.PORT)
}, 45000)
@ben-ng
ben-ng / shared.js
Last active Dec 14, 2015
Debugging Logical OR on multiple object IDs
View shared.js
var utils = require('utilities')
, assert = require('assert')
, currentId
, tests
, testItems
, Zooby = require('../fixtures/zooby').Zooby
, User = require('../fixtures/user').User
, Profile = require('../fixtures/profile').Profile
, Account = require('../fixtures/account').Account;
@ben-ng
ben-ng / gist:5026870
Last active Dec 14, 2015
Standalone models
View gist:5026870
var model = require('model');
var Adapter = require('../node_modules/model/lib/adapters/mongo').Adapter;
var User = require('../app/models/user.js').User;
var Reel = require('../app/models/reel.js').Reel;
var Video = require('../app/models/video.js').Video;
var modelAdapter = new Adapter({
dbname:config.mongo.path,
host:config.mongo.host,
port:config.mongo.port,
@ben-ng
ben-ng / gist:5219464
Created Mar 22, 2013
Test case for offset dates
View gist:5219464
var utils = require('utilities')
, assert = require('assert')
, currentId
, tests
, testItems
, Zooby = require('../fixtures/zooby').Zooby
, User = require('../fixtures/user').User
, Profile = require('../fixtures/profile').Profile
, Account = require('../fixtures/account').Account;
View test-adapters-shared.js
var utils = require('utilities')
, assert = require('assert')
, currentId
, tests
, testItems
, Zooby = require('../fixtures/zooby').Zooby
, User = require('../fixtures/user').User
, Profile = require('../fixtures/profile').Profile
, Account = require('../fixtures/account').Account;
View gist:5223411
User.verifyPassword = function (password, hash, callback) { //You need a callback because bcrypt.compare is async
bcrypt.compare(password, hash, function(err, isMatch) {
callback(err, isMatch);
});
}
//Usage:
exports.User.verifyPassword(password, user.password, function(err, isMatch) {
if(err) {
console.log("Error!");
@ben-ng
ben-ng / BaseModel.js
Created Jun 10, 2013
A short example of integrating Backbone.js with Geddy.js
View BaseModel.js
/*
* Extend your own models from BaseModel from now on
* e.g. `MyApp.Models.Zooby = BaseModel.extend({etc:etc})`;
*
* TODO: Don't forget to override `parse()` in your model.
* It should be something like `return data.modelName;`
* TODO: Don't forget to handle errors! Check data.errors for them.
*/
var BaseModel = Backbone.Model.extend({
methodUrl: function(method) {
@ben-ng
ben-ng / output.txt
Last active Dec 18, 2015
Weird Test
View output.txt
*** Running tests/adapters.js ***
test dummy ctor
test dummy before
test dummy put
A
B
C
D
test dummy get
E
View Jakefile
var build = path.relative(__dirname, '_shared')
, src = path.relative(__dirname, '_shared_sources')
, buildLessFile = path.join(build, 'css', 'styles.css')
, lessFiles = [
"css/video-js.css"
, "css/elastislide.css"
, "css/jquery.fancybox.css"
, "css/jquery.fancybox-buttons.css"
, "css/jquery.fancybox-thumbs.css"
, "css/bootstrap.css"
You can’t perform that action at this time.