Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gjorgji Kjosev spion

:shipit:
View GitHub Profile

Part 1: Why bubbling is good

We start with the following code

function startListening(server, cb) {
  server.listen(99999, 'localhost', cb)
}
24840 % node skynet.js
499999500000
regular: 378.414ms
499999500000
warmed-up: 262.341ms

Relationship between ES6 and TypeScript modules

Default export

The default export is special:

// foo.ts
export default function factoryFunction() {
}
#!/bin/bash
#----------------------------------------------------------------------------------
# Settings
#----------------------------------------------------------------------------------
#BANDN="Toggle,Freq,Band,Gain"
BAND1="1,150,1.3,-7"
BAND2="1,100,0.4,4"
BAND3="1,5400,0.9,-5"
@spion
spion / flowcart.ts
Last active November 27, 2018 00:16 — forked from unscriptable/flowcart.js
A typesafe shopping cart in typescript
// A typesafe shopping cart in typescript.
// Immutable map :)
declare class Map<T, U> {
set(t:T, u:U):Map<T, U>
has(t:T):boolean;
delete(t:T):Map<T,U>
count:number;
}
declare module "simple-router" {
function mkRouter():SimpleRouter
import express = require('express');
interface Obj {}
module mkRouter {
export interface Request extends express.Request {
@spion
spion / functional.js
Last active December 6, 2015 13:36 — forked from Arnavion/async-await.ts
Promise.any - async/await vs then()
let pending = new Promise((r,rj) => {})
let waitForever = () => pending
let reject = Promise.reject.bind(promise)
let identity = x => x
let promiseTransform = fns => p => p.then(fns.fullfilment, fns.rejection)
function any(promises) {
let fulfillments = promises.map(promiseTransform({fullfilment: identity, rejection: waitForever}))
let rejections = promises.map(promiseTransform({fullfilment: waitForever, rejection: identity}))
let firstFulfill = Promise.race(fulfillments);
#!/bin/bash
# Usage: ./timeout-alert.sh <time> "alert commands to execute" "main command to execute"
(sleep $1 && eval $2 ) &
ALERTPID=$!
eval $3
kill $ALERTPID > /dev/null 2>&1
#!/bin/bash
# Usage: ./timeout-alert.sh <time> "alert commands to execute" "main command to execute"
(sleep $1 && eval $2 ) &
ALERTPID=$!
eval $3
kill $ALERTPID > /dev/null 2>&1

interfaces

[Open in TypeScript playground][1]

interface Item {
	name: string
	created:Date
}