Skip to content

Instantly share code, notes, and snippets.

Avatar

Aluan Haddad aluanhaddad

View GitHub Profile
@robertleeplummerjr
robertleeplummerjr / dch.ts
Created Oct 28, 2017
Dynamic Class Hierarchy in Typescript
View dch.ts
class Item {
public static async get<Options extends { id: string }>(o: Options, api: Api): Promise<Item> {
return new Promise<Item>((accept, reject) => {
console.log(api);
accept(new Item());
});
}
public static async search<Options extends { query: string }>(o: Options, api: Api): Promise<Item[]> {
return new Promise<Item[]>((accept, reject) => {
View parens-and-perf.md

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

@maggiben
maggiben / typeahead.html
Created Jan 25, 2016
Aurelia typeahead
View typeahead.html
<template>
<require from="/styles/type-ahead.css"></require>
<div class="ui icon input">
<input type="text" class="form-control" placeholder.bind="options.placeholder" value.bind="value">
<i class="search link icon"></i>
</div>
</template>
@domenic
domenic / promises.md
Last active May 19, 2022
You're Missing the Point of Promises
View promises.md

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.