Skip to content

Instantly share code, notes, and snippets.

View btoo's full-sized avatar
🅱️
2️⃣

btoo

🅱️
2️⃣
View GitHub Profile
@jboner
jboner / latency.txt
Last active July 24, 2024 18:06
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@Stanback
Stanback / nginx.conf
Last active July 24, 2024 18:44 — forked from michiel/cors-nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@samgiles
samgiles / flatMap.js
Created June 20, 2014 11:32
Javascript flatMap implementation
// [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (:
Array.prototype.flatMap = function(lambda) {
return Array.prototype.concat.apply([], this.map(lambda));
};
@ericelliott
ericelliott / passing-values-to-generators.js
Created May 20, 2016 07:14
Passing values into generators through `.next()`
function* crossBridge() {
const reply = yield 'What is your favorite color?';
console.log(reply);
if (reply !== 'yellow') return 'Wrong!'
return 'You may pass.';
}
{
const iter = crossBridge();
const q = iter.next().value; // Iterator yields question
@msmfsd
msmfsd / es7-async-await.js
Last active February 4, 2024 17:38
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@egmontkob
egmontkob / Hyperlinks_in_Terminal_Emulators.md
Last active July 20, 2024 23:50
Hyperlinks in Terminal Emulators
@fgnass
fgnass / index.js
Created July 20, 2017 20:50
React E2E testing in Headless Chrome with unexpected.js and retractor
import webdriver from 'friendly-webdriver';
import unexpected from 'unexpected';
import unexpectedWebdriver from 'unexpected-webdriver';
import retractor from 'retractor';
const expect = unexpected.clone();
expect.use(unexpectedWebdriver());
/* @jsx retractor */
variables:
GIT_SSL_NO_VERIFY: "1"
USE_DOCKER: "1"
image: <KKBOX_DOCKER_IMAGE_NAME>
stages:
- e2e-test
e2e-test:
@JeremyRH
JeremyRH / event-delegation-performance.md
Last active April 2, 2024 18:43
Does event delegation actually improve performance?

Does event delegation actually improve performance?

Event delegation works by attaching a single event listener to a parent element to catch events bubbling up from the children. Many people believe this is more performant than attaching event listeners to each child. I am not convinced this is always true.

Let's start with a common example of event delegation. Here we have a list of elements:

<ul id="item-list">
  <li data-cost="12">Item 1</li>
  <li data-cost="18">Item 2</li>
  <li data-cost="6">Item 3</li>
 ...