Skip to content

Instantly share code, notes, and snippets.

@sulco
sulco / clown-formatter.js
Created December 10, 2018 19:11
A clown formatter
window.devtoolsFormatters = [{
header: function(obj){
if (!obj.__clown) {
return null;
}
delete obj.__clown;
const style = `
color: red;
border: dotted 2px gray;
border-radius: 4px;
// node --harmony-async-iteration async-iteration-test.js
// for-await-of converts sync iterables over Promises to async iterables over fulfillment values
// Iterable<Promise<T>> -> AsyncIterable<T>
// Roughly: { value: Promise.resolve(123), done: false } becomes Promise.resolve({ value: 123, done: false })
// Spec: https://tc39.github.io/proposal-async-iteration/#sec-createasyncfromsynciterator
function* gen() {
yield Promise.resolve(1);
@dfkaye
dfkaye / null.js
Last active March 23, 2018 21:41
Surprising lte (<=) and gte (>=) operator results in JavaScript for null, object, and undefined
// 9 Sep 2017, following
// https://twitter.com/AbinavSeelan/status/903935309871812610
// which explores the surprising `(null >= 0) == true`
// Not only is it surprising, it's bi-directional
console.log([
// zero case
null <= 0,
null >= 0,
/**
* Creates an asynchronous ReadStream for the file whose name
* is `fileName` and feeds it into an AsyncQueue that it returns.
*
* @returns an async iterable
*/
function readFile(fileName) {
const queue = new AsyncQueue();
const readStream = createReadStream(fileName,
{ encoding: 'utf8', bufferSize: 1024 });
@coderek
coderek / index.html
Last active March 26, 2018 02:48
Vue 2.0 - 2 way data binding deeper analysis
<!DOCTYPE html>
<html>
<head>
<title>Test 2 way data binding</title>
</head>
<body>
<div id="app">{{ abc }} - {{ def }} = {{ abc-def }} </div>
<button id='add'>add</button>
<button id='double'>double</button>
<script src='main.js'></script>
@CatTail
CatTail / proto.js
Last active February 1, 2024 15:59
Javascript prototype in a nutshell
var assert = require('assert')
var util = require('util')
function test (inherits) {
function Fruit () {
}
Fruit.prototype.round = false
Fruit.prototype.sweet = true
Fruit.prototype.eat = function () {}
@myshov
myshov / function_invocation.js
Last active January 21, 2024 15:14
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@csswizardry
csswizardry / README.md
Last active April 2, 2024 20:17
Vim without NERD tree or CtrlP

Vim without NERD tree or CtrlP

I used to use NERD tree for quite a while, then switched to CtrlP for something a little more lightweight. My setup now includes zero file browser or tree view, and instead uses native Vim fuzzy search and auto-directory switching.

Fuzzy Search

There is a super sweet feature in Vim whereby you can fuzzy find your files using **/*, e.g.:

:vs **/*<partial file name><Tab>
@paulirish
paulirish / server-timing-demo.js
Last active January 14, 2024 13:22
Demo of server timing values. visualized in chrome devtools
// see for screenshot:
// https://twitter.com/paul_irish/status/829090506084749312
const http = require('http');
function requestHandler(request, response) {
const headers = {
'Server-Timing': `
sql-1;desc="MySQL lookup Server";dur=100,
sql-2;dur=900;desc="MySQL shard Server #1",
@ljharb
ljharb / array_iteration_thoughts.md
Last active April 22, 2024 10:15
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu