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
getify / 1.md
Last active Jul 9, 2019
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts
View 1.md

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);
    
    p.then(console.log).then(q).then(console.log);
@cletusw
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: https://astexplorer.net/#/gist/5492d2b9850a451d8e8d532bc64f21ce/latest
*
* Converts:
@hallettj
hallettj / Makefile
Last active Mar 4, 2019
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
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, ...rest }) => (
<Match {...rest}>
{({ matched, ...props }) => (
<div style={{ display: matched ? 'block' : 'none' }}>
<Component {...props}/>
</div>
)}
</Match>
)
@btroncone
btroncone / ngrxintro.md
Last active Jul 16, 2019
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series
View ngrxintro.md

Comprehensive Introduction to @ngrx/store

By: @BTroncone

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

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

Table of Contents

@remojansen
remojansen / class_decorator.ts
Last active Jul 15, 2019
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
paulirish / what-forces-layout.md
Last active Jul 16, 2019
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

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()
@JamesMessinger
JamesMessinger / IndexedDB101.js
Last active Jul 10, 2019
Very Simple IndexedDB Example
View IndexedDB101.js
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
View secret-mouse.js
let animal = {
animalType: 'animal',
describe () {
return `An ${this.animalType} with ${this.furColor} fur,
${this.legs} legs, and a ${this.tail} tail.`;
}
};
let mouseFactory = function mouseFactory () {
You can’t perform that action at this time.