Skip to content

Instantly share code, notes, and snippets.

View gx0r's full-sized avatar

Grant Miner gx0r

View GitHub Profile
// Timer to continue counting while using bcrypt.
// Demonstrates that the bcrypt functions are asynchronous.
;(function() {
console.log('start timer');
var x = 1;
setInterval(function() {
console.log('Timer: ' + x);
x++;
}, 1000);
}());
var Promise = require('bluebird');
Promise.longStackTraces();
//var Promise = require('q');
Promise.reject('first thingy')
.then(function (a) {
console.log('then 1 ' + a);
})
.finally(function (x) {
console.log('finally 1');
@gx0r
gx0r / gist:4d79f72ea659bd73117c
Created November 18, 2015 20:23
Better requestWithFeedback
var m = require('mithril');
function requestWithFeedback(args) {
var completed = m.prop(false);
var complete = function() {
completed(true);
}
var data = m.prop();
args.background = true
@gx0r
gx0r / gist:7b38ed0edd390525d437
Created November 26, 2015 07:45
Mithril Route Monkeypatch
function mountWrapper(component) {
var origCtrl = component.controller;
component.controller = function () {
setImmediate(function () {
var orgid = m.route.param('orgid');
var org = m.prop(null);
var route = m.route();
var routeSplit = m.route().split('/');
if (orgid) {
@gx0r
gx0r / gist:73484233e4f33e1f24e6
Last active January 9, 2016 00:29
v8 vs bluebird
------
built in rejection:
Promise.reject(new Error('ether'))
(no error console output with V8 promise rejection, nothing shown on screen, no non-zero exit code on process, etc.)
--------
Promise = require('bluebird')
@gx0r
gx0r / gist:7b414a2377bb7e804d7d
Created January 20, 2016 16:20
Koa rendering template
const jade = require('jade')
app.use((req, res) => {
const locals = req.locals // get your template locals from where ever
locals.cache = process.env.NODE_ENV === 'production' // set the template cache
const html = jade.renderFile('templates/home.jade', locals) // render the template
res.setHeader('Content-Length', Buffer.byteLength(html))
res.setHeader('Content-Type', 'text/html; charset=utf-8') // set the content type header
res.end(html) // send the response
})
@gx0r
gx0r / gist:46f574412a7f5bc0790f
Created February 28, 2016 15:18
Routing with Mithril and Redux
var store = redux.createStore(function(state, action) {
var defaultState = {
view: LOGIN,
subview: '',
}
if (!state) {
return defaultState;
}
switch(action.type) {
@gx0r
gx0r / jqVsDOMContentLoaded.html
Last active February 28, 2017 16:49
DOMContentLoaded vs jQuery
<html>
<head>
<title>DOMContentLoaded vs jQuery</title>
</head>
<body>
<h1>
With jQuery (2.1.4) if a function throws in a $(document).ready listener, it will prevent subsequent
$(document).ready listeners from executing. This demonstrates that it does not happen with jQuery 3.1.1 or document.addEventListener.
</h1>
@gx0r
gx0r / qsparser.js
Last active March 26, 2019 20:51
One line QueryString parser - handles repeated parameters, initial question-mark is optional, handles null parameters, handles + in parameters, and decodes URI Components.
'use strict';
/**
"One line" QueryString parser
Initial question-mark optional
Handles repeated parameters (turns into array)
Handles null parameters
Handles + sign in parameters
@gx0r
gx0r / Bluebird Benchmark Node 8 vs Node 7.txt
Last active May 30, 2017 22:23
Bluebird Benchmark Node 8 vs Node 7
** Node 8 **
results for 10000 parallel executions, 1 ms per I/O op
file time(ms) memory(MB)
callbacks-baseline.js 156 31.35
callbacks-suguru03-neo-async-waterfall.js 189 39.54
promises-bluebird-generator.js 246 41.37
promises-bluebird.js 322 48.27
promises-cujojs-when.js 393 61.61
promises-tildeio-rsvp.js 503 78.96