Skip to content

Instantly share code, notes, and snippets.

@solomonhawk
solomonhawk / gist:1628b1ce459bba3ad7f0
Last active August 29, 2015 14:11
return void callback()
function(callback) {
if (someCond) return void callback();
// do things
return "some value";
}
@solomonhawk
solomonhawk / data.json
Last active August 29, 2015 14:12
Simple Object Sorting
{
"name": "Ashe's Pokedex",
"sort": "byName",
"order": "descending",
"pokemon": [
{
"id": 4,
"name": "Charmander",
"types": "fire",
"species": "lizard",
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
@solomonhawk
solomonhawk / example.js
Last active August 29, 2015 14:16
EZ Store Listening
// some pieces of this file have been omitted
let React = require('react')
let notesStore = require('../../stores/notesStore')
let monitorMixin = require('../../mixins/monitorMixin')
let Notes = React.createClass({
mixins: [monitorMixin(notesStore)]
// this gets called whenever `notesStore` emits a change event
let validActions = {
[GameConstants.GAME_CREATE]: null,
[GameConstants.GAME_JOIN]: null,
[GameConstants.GAME_EXIT]: null,
[GameConstants.USER_JOINED]: null,
[GameConstants.USER_LEFT]: null
}
GameDispatcher.register( ({actionType, data}) => {
if (actionType in validActions) {
/**
* Ref $elector Mixin
*/
export default {
$(ref) {
return this.refs[ref].getDOMNode()
}
}
/**
* Somewhere in an app module, pull in the app specific translator
*/
import t from 'util/translate'
t("Edu_bs")
// => "Bachelor's"
@solomonhawk
solomonhawk / bookmarklet.js
Last active August 29, 2015 14:27
GitHub PR Toggling
javascript:(function(){function t(){this.types={}}function e(t,e){this.el=t,this.registry=e,this.init()}t.prototype={register:function(t){var e=t.type;this.types[e]=this.types[e]||[],this.types[e].push(t)},createNavigation:function(){var t=document.createElement("div");t.className="table-of-contents clearfix";var e=document.createElement("div");e.className="btn-group right",i.parentNode.insertBefore(t,i.nextSibling),t.appendChild(e),Object.keys(this.types).forEach(function(t){var i=!0,n=document.createElement("button");n.textContent=t,n.className="btn btn-sm selected",e.appendChild(n),n.addEventListener("click",function(e){i=!i,n.classList.toggle("selected",i),this.types[t].forEach(function(t){t.toggle(i)},this),e.preventDefault()}.bind(this))},this)}},e.prototype={init:function(){this.visible=!0,this.cacheElements(),this.addToggleButton(),this.bindEvents(),this.registerType()},cacheElements:function(){this.header=this.el.querySelector(".file-header"),this.actions=this.el.querySelector(".file-actions"),this.c
@solomonhawk
solomonhawk / what-forces-layout.md
Created October 8, 2015 14:14 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@solomonhawk
solomonhawk / info.md
Created May 26, 2016 17:38
viget footer

Viget Footer