Skip to content

Instantly share code, notes, and snippets.

@torgeir
torgeir / coercing.js
Last active August 29, 2015 14:00
js coercion on property access and method calls on primitive values
var s;
s = "wtf";
s.split = function () {};
s.split("t"); // split() works
s = String("wtf");
s.split = function () {};
s.split("t"); // split() works
@torgeir
torgeir / profile-proxy.js
Last active August 29, 2015 14:02
es6 proxy profile method example
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 August 29, 2015 14:02
Upgrading from openwrt backfire to attitude adjustment 12.09 on the routerstation pro
# 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-internal-access-nested-context.html
Last active August 29, 2015 14:02
Hogan internal access nested context
<!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 / hogan-custom-function-access-nested-context.html
Last active August 29, 2015 14:02
Hogan custom function access nested context
<!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--like-in-mustache-templates.html
Last active August 29, 2015 14:02
Hogan custom function access nested context -- like hogan does internally
<!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 / home-brew-link-all-programs-after-mavericks.sh
Last active August 29, 2015 14:06 — forked from lopopolo/gist:9427762
home-brew-link-all-programs-after-mavericks
@torgeir
torgeir / testing-traceur-async-await-with-bluebird-promises.js
Last active August 29, 2015 14:06
Testing traceur async/await with bluebird promises.
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 August 29, 2015 14:07
Naive quiescent for 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 August 29, 2015 14:07
Testing omniscient with requestAnimationFrame.
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),