Skip to content

Instantly share code, notes, and snippets.

View elmasse's full-sized avatar

Masse Fierro elmasse

View GitHub Profile
@joliss
joliss / gist:051a5cdcf7b57cf68feb
Last active August 29, 2015 14:13
Why it's hard to map ES6 modules 1:1 into CommonJS or AMD

Why it's hard to map ES6 modules 1:1 into CommonJS or AMD

Originally from an email, gisted here for posterity:

I was able to remember the example where "naive" 1:1 module transpilation fails:

npm version patch && git push --follow-tags
npm publish
@grgur
grgur / async-generator.js
Last active September 12, 2015 22:11
Demo of async/await with ES6 generators
function makeRequest(url) {
fetch(url)
.then(response => response.json())
.then(json => it.next(json))
.catch(error => console.error('Somthing shit the bed', error));
}
function *syncRequests() {
const redditUrl = 'https://www.reddit.com/controversial.json?count=1&limit=2';
const page1 = yield makeRequest(redditUrl);
@a0viedo
a0viedo / README.md
Last active January 20, 2017 20:09
Utility wrapper of D3.js that favors configuration to increase code reuse and gain simplicity to create charts.

I wrote a bunch of utility helpers for graphing data with pie charts, bar charts, scatter plots and histograms.

It reutilices many examples from [d3.org][d3.org], so many that I lost track of them all. I have only tested on d3's v3.

  • Bar charts:
    • Properties like width, height, X and Y axis domains, X and Y axis transforms, tips and margins can be passed through a configuration object
    • tips
    • helper to update graph from new data through animations
    • opt-in interpolation
  • Pie charts:
@neoeinstein
neoeinstein / Auth0.elm
Last active March 2, 2017 08:22
Elm Example for interoperating with Auth0. Note that much of this was culled out of an existing code-base, so may need some minor edits to work correctly for you. Presumes that Elm.Main is transpiled into elm.js
module Auth0
( AuthenticationState(..), AuthenticationError, AuthenticationResult
, Options, defaultOpts
, LoggedInUser, UserProfile, Token
, showLock, showLockSignal
, mapResult
) where
function* zip(...iterables) {
let iterators = iterables.map(i => i[Symbol.iterator]());
while (true) {
let entries = iterators.map(i => i.next());
let done = entries.some(entry => entry.done);
if (done) break;
yield entries.map(e => e.value);
}
}
@dansilivestru
dansilivestru / .bithoundrc
Last active March 25, 2019 12:23
default .bithoundrc file for ignoring project files (modify as needed and commit to the root of your project)
{
"ignore": [
"**/deps/**",
"**/node_modules/**",
"**/thirdparty/**",
"**/third_party/**",
"**/vendor/**",
"**/**-min-**",
"**/**-min.**",
"**/**.min.**",

Parens And Performance

Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.

JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.

Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.

So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function keyword was a (, because that usually m

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
/* So how does this work?
I'm using ANSI escape sequences to control the behavior of the terminal while
cat is outputting the text. I deliberately place these control sequences inside
comments so the C++ compiler doesn't try to treat them as code.*/
//
/*The commands in the fake code comment move the cursor to the left edge and
clear out the line, allowing the fake code to take the place of the real code.
And this explanation uses similar commands to wipe itself out too. */
//
#include <cstdio>