Part of my personal shortcuts for the usual pull-request-based workflow.
Given you have an "upstream" repository you need to work on:
- Fork it
- Clone your fork locally (repo "origin")
//##console.log bubble for nested iframes | |
//##by [Kyle Phillips](http://haptic-data.com) | |
//find each iframe recursively and bubble its logs up to the current window.console | |
(function( d, w ){ | |
function bubble( doc, win, msg ){ | |
Array.prototype.forEach.call(doc.getElementsByTagName('iframe'), function( frame ){ | |
if( !sameOrigin(frame.src) || !frame.contentWindow || !frame.contentWindow.console ){ | |
w.console.log('console of iframe ', frame.src, ' is unreachable'); | |
return; | |
} |
// pre-ES5 IE version | |
var dict = (function() { | |
var PROPERTY_KEYS = [ | |
"hasOwnProperty", | |
"isPrototypeOf", | |
"propertyIsEnumerable" | |
"valueOf", | |
"toString", | |
"toLocaleString", | |
"constructor" |
[My initial list:] | |
DRM | |
speed for superhi-perf games | |
app store placement | |
source-code secrecy | |
[list compiled from other people's twitter answers; thanks all!] | |
pushing native notifications when they're not in the "app" (several people said this) |
// ES6 destructuring as sweet.js macros. See bottom for examples. | |
// TODO: | |
// elision: var [,,,four] = arr; | |
// rest: var [foo, bar, ...rst] = arr; | |
// function args: function(foo, bar, { baz, poop }) {} | |
macro destruct__objassign { | |
rule { $declare ($prop:ident : $pattern:expr = $default:expr) $obj:expr } => { | |
next $declare ($obj.$prop || $default) $pattern |
TLDR: a React component should either manage its own state, or expose a callback so that its parent can. But never both.
Sometimes our first impulse is for a component to entirely manage its own state. Consider this simple theater seating picker that has a letter for a row, and a number for a seat. Clicking the buttons to increment each value is hardly the height of user-interface design, but never mind - that's how it works:
/* @flow */
var React = require('react');
var Letter: React.ReactClass = React.createClass({
getInitialState: function(): any {
#!/usr/bin/zsh | |
COMPRESSOR=$(whence -p yui-compressor) | |
[ -z $COMPRESSOR ] && exit 0; | |
function _compress { | |
local fname=$1:t | |
local dest_path=$1:h | |
local min_fname="$dest_path/${fname:r}.min.${fname:e}" | |
$COMPRESSOR $1 > $min_fname |
Title | Seen | Rating ★☆ |
---|---|---|
24 | ☑ | ★★☆☆☆ |
Ash vs Evil Dead | ☒ | ? |
Bates Motel | ☑ | ★★★☆☆ |
Battlestar Galactica | ☒ | ? |
Better Call Saul | ☑ | ★★★★★ |
Black Mirror | ☑ | ★★★★★ |
Black Sails | ☒ | ? |
Breaking Bad | ☑ | ★★★★★ |
// UPD: | |
// Now available as npm module! | |
// Check out https://github.com/RReverser/better-log for details. | |
console.log = (function (log, inspect) { | |
return function () { | |
return log.apply(this, Array.prototype.map.call(arguments, function (arg) { | |
return inspect(arg, { depth: 1, colors: true }); | |
})); | |
}; |
// all this `toJSON()` does is filter out any circular refs. all other values/refs, | |
// it passes through untouched, so it should be totally safe. see the test examples. | |
// only extend the prototype if `toJSON` isn't yet defined | |
if (!Object.prototype.toJSON) { | |
Object.prototype.toJSON = function() { | |
function findCircularRef(obj) { | |
for (var i=0; i<refs.length; i++) { | |
if (refs[i] === obj) return true; | |
} |