Skip to content

Instantly share code, notes, and snippets.

Copying and pasting from StackOverflow

Cameron Nokes ccnokes

Copying and pasting from StackOverflow
Block or report user

Report or block ccnokes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
getify /
Last active Jul 9, 2019
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    var q = Promise.resolve(10);
View Infrastructure.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
if (pending.has(url)) {
throw pending.get(url);
cletusw / angular-injection-to-import.js
Last active May 16, 2019
Converts the given angular injected parameter into an explicit require statement
View angular-injection-to-import.js
* Converts the given angular injected parameter into an explicit require statement
* Run this with jscodeshift
* @example
* jscodeshift . --specifier='Auth' --source='application/Auth'
* Live demo:
* Converts:
rkbhochalya /
Created May 16, 2017
Recursively optimize PNG and JPEG images using convert command
# Recursively optimize PNG and JPEG images using convert command
# `convert` is part of ImageMagick ( You will need to install it first.
# Author: Rajendra Kumar Bhochalya (
# @see
# Optimize all JPEG images in current directory and subdirectories
find . -name "*.jpg" -exec convert "{}" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB "{}" \; -exec echo "{}" \;
hallettj / Makefile
Last active Jan 7, 2020
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
View Makefile
# Makefile for transpiling with Babel in a Node app, or in a client- or
# server-side shared library.
.PHONY: all clean
# Install `babel-cli` in a project to get the transpiler.
babel := node_modules/.bin/babel
# Identify modules to be transpiled by recursively searching the `src/`
# directory.
anaisbetts / stat-cache.js
Last active Apr 11, 2019
Make your Electron apps load faster, with this One Weird Trick
View stat-cache.js
// Include this at the very top of both your main and window processes, so that
// it loads as soon as possible.
// Why does this work? The node.js module system calls fs.realpathSync a _lot_
// to load stuff, which in turn, has to call fs.lstatSync a _lot_. While you
// generally can't cache stat() results because they change behind your back
// (i.e. another program opens a file, then you stat it, the stats change),
// caching it for a very short period of time is :ok: :gem:. These effects are
// especially apparent on Windows, where stat() is far more expensive - stat()
// calls often take more time in the perf graph than actually evaluating the
View gist:d7ecaf57d8518b0b969502928567c98a
const ToggleDisplayMatch = ({ component: Component, }) => (
<Match {}>
{({ matched, ...props }) => (
<div style={{ display: matched ? 'block' : 'none' }}>
<Component {...props}/>
btroncone /
Last active Jan 17, 2020
A Comprehensive Introduction to @ngrx/store - Companion to Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

remojansen / class_decorator.ts
Last active Jan 17, 2020
TypeScript Decorators Examples
View class_decorator.ts
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
paulirish /
Last active Jan 16, 2020
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.


Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
You can’t perform that action at this time.