Skip to content

Instantly share code, notes, and snippets.

@torgeir
torgeir / coercing.js
Last active Aug 29, 2015
js number coercing
View coercing.js
var n = Number(1);
var m = n;
n = null;
console.log(m); // 1
var o = new Number(1);
var p = o;
o = null;
console.log(p); // {}
@torgeir
torgeir / profile-proxy.js
Last active Aug 29, 2015
es6 proxy profile method example
View profile-proxy.js
function profile (o) {
for (var key in o) {
var field = o[key];
if (typeof field == 'function') {
o[key] = Proxy.createFunction({},
// call
function () {
var before = new Date;
var res = field.apply(o, arguments);
var spent = new Date - before;
@torgeir
torgeir / upgrade_openwrt_backfire_to_attitude_adjustment_rspro.sh
Last active Aug 29, 2015
Upgrading from openwrt backfire to attitude adjustment 12.09 on the routerstation pro
View upgrade_openwrt_backfire_to_attitude_adjustment_rspro.sh
# Upgrading from openwrt backfire to attitude adjustment 12.09 on the routerstation pro
# 1.
# download the sysupgrade file
# it can be used to upgrade from the luci ui
# it keeps your settings
wget http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/openwrt-ar71xx-generic-ubnt-rspro-squashfs-sysupgrade.bin
# 2.
# in luci, navigate to "backup / flash firmware"
@torgeir
torgeir / hogan-custom-function-access-nested-context--like-in-mustache-templates.html
Last active Aug 29, 2015
Hogan custom function access nested context -- like hogan does internally
View hogan-custom-function-access-nested-context--like-in-mustache-templates.html
<!doctype html>
<meta charset=utf-8>
<title>hogan custom function access nested context</title>
<script src="hogan-3.0.1.js"></script>
<script>
var data = {
site: {
heading: "Site heading",
@torgeir
torgeir / hogan-custom-function-access-nested-context.html
Last active Aug 29, 2015
Hogan custom function access nested context
View hogan-custom-function-access-nested-context.html
<!doctype html>
<meta charset=utf-8>
<title>hogan custom function access nested context</title>
<script src="hogan-3.0.1.js"></script>
<script>
var data = {
site: {
heading: "Site heading",
@torgeir
torgeir / hogan-internal-access-nested-context.html
Last active Aug 29, 2015
Hogan internal access nested context
View hogan-internal-access-nested-context.html
<!doctype html>
<meta charset=utf-8>
<title>hogan internal access nested context</title>
<script src="hogan-3.0.1.js"></script>
<script>
var data = {
site: {
heading: "Site heading",
@torgeir
torgeir / home-brew-link-all-programs-after-mavericks.sh
Last active Aug 29, 2015 — forked from lopopolo/gist:9427762
home-brew-link-all-programs-after-mavericks
View home-brew-link-all-programs-after-mavericks.sh
@torgeir
torgeir / testing-traceur-async-await-with-bluebird-promises.js
Last active Aug 29, 2015
Testing traceur async/await with bluebird promises.
View testing-traceur-async-await-with-bluebird-promises.js
var wait = (ms) => new Promise((resolve, reject) => {
setTimeout(function () {
reject("doh");
}, ms * 1000)
})
async function f () {
try {
await wait(2);
}
@torgeir
torgeir / quiescent-for-js.js
Last active Aug 29, 2015
Naive quiescent for js.
View quiescent-for-js.js
var React = require('react');
var EventEmitter = require("events").EventEmitter;
function component (fn) {
var Component = React.createClass({
render: function () {
return fn.call(this, this.props.value, this.props.statics);
},
shouldComponentUpdate: function (nextProps) {
return this.props.value != nextProps.value;
@torgeir
torgeir / omniscient-with-requestAnimationFrame.js
Last active Aug 29, 2015
Testing omniscient with requestAnimationFrame.
View omniscient-with-requestAnimationFrame.js
var React = require('react'),
component = require('../'),
immstruct = require('immstruct'),
Immutable = require('immutable'),
d3 = require('d3');
var d = React.DOM;
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0),