Skip to content

Instantly share code, notes, and snippets.

View moimikey's full-sized avatar
:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
View GitHub Profile

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
@danielmahal
danielmahal / Component.jsx
Last active June 7, 2017 19:47
Firebase/React decorator
import React, {PropTypes} from 'react';
import firebase from 'decorators/firebase';
@firebase({
items: '/items',
// or
// items: (props) => `/${props.id}/items`,
// items: (props) => ref.child('items'),
})
anonymous
anonymous / index.html
Created October 14, 2015 02:16
JS Bin // source http://jsbin.com/sesugedara
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div><div><p><p><span><input type="text" value=""></span></p></p></div></div>
<script src="https://code.jquery.com/jquery.js"></script>
@OlegIlyenko
OlegIlyenko / Event-stream based GraphQL subscriptions.md
Last active July 5, 2025 14:15
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.

@paulirish
paulirish / what-forces-layout.md
Last active August 2, 2025 07:28
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.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
'use strict';
var React = require('react');
var emptyFunction = require('../../jslib/emptyFunction');
var throttle = require('lodash.throttle');
var listening = false;
var instances = [];
@aq2bq
aq2bq / konami_command.js
Last active April 14, 2016 05:00
KONAMI Command
var konamiCommand = (function(i, commands){
function keyDown(e) {
e.keyCode == commands[i] ? i++ : i = 0;
if (i == commands.length) alert('KONAMI!');
}
window.addEventListener('keydown', keyDown);
})(0, [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]);
@moimikey
moimikey / coerce.js
Last active April 27, 2019 13:51
30 bytes to coerce "23" to Number, keep "apple" as String
/**
* function coerce(x) {
* return ''+x===x?(p=~~+x?r=+x:r=x):r=x
* }
* > undefined
* coerce(123)
* > 123
* coerce('123')
* > 123
* coerce('apple')
@gaearon
gaearon / ReduxUndoExample.js
Created July 30, 2015 14:46
Redux undo reducer factory example by @iclanzan
// Written by @iclanzan
// All credit goes to him!
// You create the reducer like this:
// var reducer = createTimelineReducer('someName', someReducer, ['foo', 'bar']);
// And then whenever an action of type `foo` or `bar` happens it calls `someReducer` and adds the result to the timeline.
// Then to undo/redo you trigger an action of type `someNameUndo`/`someNameRedo`.
var defaults = require('lodash/object/defaults');
var capitalize = require('lodash/string/capitalize');
@gaearon
gaearon / ReduxMicroBoilerplate.js
Last active March 26, 2020 00:35
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------