Skip to content

Instantly share code, notes, and snippets.

View Qard's full-sized avatar
👨‍💻
In an epic battle with my keyboard.

Stephen Belanger Qard

👨‍💻
In an epic battle with my keyboard.
View GitHub Profile
@Qard
Qard / scripts.json
Created February 17, 2014 03:51
This would be several hundred lines in grunt.
{
"start": "node --harmony server.js",
"dev": "exec-parallel 'npm run watch' 'npm run watch:test' 'nodemon --harmony server.js'",
"test": "mocha --harmony",
"coverage": "npm run coverage:report",
"coverage:build": "rm -rf coverage && node --harmony istanbul cover _mocha",
"coverage:report": "npm run coverage:build && istanbul report",
"coverage:html": "npm run coverage && node-open coverage/lcov-report/index.html",
"build": "exec-parallel 'npm run build:js' 'npm run build:css'",
"build:js": "browserify assets/js/main.js -o public/js/bundle.js",
@Qard
Qard / evil.js
Created October 8, 2014 23:41
I am a monster.
var Emitter = require('events').EventEmitter
var evil = new Emitter
evil.on('foo', function (get) {
console.log('privateThing is', get('privateThing'))
})
function foo () {
var privateThing = 'secret'
evil.emit('foo', function (prop) {
function times (n, fn) {
return function () {
if (n > 0) {
n--
return fn.apply(this, arguments)
}
}
}
var hello = times(2, function () {
@Qard
Qard / test.rb
Last active August 29, 2015 14:14
run `npm test` against every node version! (requires nvm and ruby)
require 'openssl'
require 'net/http'
uri = URI.parse("https://semver.io/node/versions")
# uri = URI.parse("https://semver.io/iojs/versions")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # read into this
result = http.get(uri.request_uri)
@Qard
Qard / problems.md
Last active August 29, 2015 14:16
Framework-level tracing notes

Problems

  • Input events are difficult/impossible to hook into at framework level
    • Angular uses html data-binding without user-defined interactions, or sometimes ng-click attributes (but still bound to a private scope). This logic is all lost somewhere deep in the internals, completely inaccessible to outside code.
    • Ember uses an action filter in mustache (http://emberjs.com/guides/templates/actions/). Again, inaccessible internals...
    • React uses on* attributes in JSX. It's possible to intercept them via React.createElement(...), but associating the virtual DOM representation with the corresponding real DOM element is not possible without patching the DOM itself.
  • Scope inheritance in angular makes it impossible to know what controller a given thing in the scope is coming from without modifying the core itself. (https://docs.angularjs.org/guide/controller#scope-inheritance-example)
  • MV* approach between the different frameworks varies rather drastically.
  • Angular has controllers, but the
var algorithm = crypto.getHashes()[0]
var hash = crypto.createHash(algorithm) // crypto entry
hash.update('foo')
fs.readFile(__filename, function (err, data) {
hash.update('bar')
var hashed = hash.digest() // crypto exit
done()
})
@Qard
Qard / JSON.fstringify
Created April 9, 2011 10:36
JSON.stringify that retains functions. Simple, but handy.
JSON.fstringify = function(object) {
return JSON.stringify(object, function(key, value){
if (typeof value == 'function') {
return value.toString();
}
return value;
});
};
@Qard
Qard / Chainer
Created April 9, 2011 23:47
Build callback chains without ridiculous indentation!
function chainer(){
var chain = [];
function add(callback) { chain.push(callback); }
function next() { if (chain.length) { chain[0](); chain.shift(); } }
return { add: add, push: add, run: next, start: next, next: next };
}
// Make a new chain.
var chain = new chainer();
@Qard
Qard / gist:1086780
Created July 16, 2011 20:55
Vennly.js rewrite
/**
* Some basic rewriting to connect the functions via prototype.
* It's faster that way as the functions are only addressed to memory once.
*
* Also stores the canvas and context as instance properties rather than passing them through everything.
* Again, it is faster that way.
*/
/**
*
@Qard
Qard / backbone.behaviour.js
Created January 24, 2012 08:06
Behaviour abstraction system for backbone.js
!function (Backbone) {
// Store blank stuff here
var blankEl = $()
, blankModel = new Backbone.Model.extend()
, blankCollection = new Backbone.Collection.extend({
model: blankModel
})
, blankView = new Backbone.View.extend({
el: blankEl
})