Skip to content

Instantly share code, notes, and snippets.

View kaid's full-sized avatar
🎯
Focusing

Kaid Wong kaid

🎯
Focusing
  • Beijing, PRC
View GitHub Profile
type Char = string;
type Decimal = number;
type NextArgs<I, O, C> = (input: I, accumulation: O, context?: C) => { input: I, accumulation: O };
class RecursiveIterator<I, O, C=unknown> {
private context: C;
private next: NextArgs<I, O, C>;
private shouldReturn: (i: I) => boolean;
private initializeAccumulation: () => O;
@kaid
kaid / week2.js
Created March 4, 2019 15:59
BFE学习小分队习题
class NestedIterator {
constructor(iteratee = []) {
this.stack = [[iteratee, 0]];
}
getTop() {
const topIndex = this.stack.length - 1;
if (topIndex < 0) {
return null;
@kaid
kaid / tcp-echo.go
Last active November 25, 2016 05:17
package main
import (
"bufio"
"fmt"
"io"
"net"
"strings"
"sync"
)
@kaid
kaid / mkr.sh
Created September 28, 2016 07:57
mkr() {
local ret=0
local out
while [[ $ret -ne 127 ]] do
out=$(make)
if [[ $out != *"Nothing to be done"* ]] then
echo $out
fi
@kaid
kaid / README.md
Created March 17, 2016 07:03 — forked from sycobuny/README.md
A problem I'm encountering with pgTAP (http://pgtap.org/)

The Problem

I'm hoping to test a function that I will eventually use in a DOMAIN to verify that any given JSONB object adheres to a certain loose set of constraints (other JSONB types will be built on constraints specified in this DOMAIN).

As the DOMAIN will already fail anything that doesn't pass the function, I did not write the function to raise exceptions, but rather to raise warnings,

(tempo! 120)
(quant! 90)
piano:
V1: o5 c8 d4 < a2 > c8 d4 < a2 > c8 d4 < g2.
o5 c8 d4 < a2 > c8 d4 < a2 > c8 d4 < g2.
o4 g4 > d4 e4 f2 g4 e2 e4 d4 c8 d8 e8 c8 < a2.
o4 g4 > d4 e4 f2 g4 e2 e8 e8 d4 c2.
function asyncPrefix() {
const prefix = "Your IP is:";
return new Promise(function(resolve, reject) {
try {
let timer;
timer = setTimeout(function () {
resolve(prefix);
clearTimeout(timer);
}, 4000);
@kaid
kaid / Req.js
Created August 5, 2015 11:01
Req.js simple fetch API wrapper with request and response processors.
export default class Req {
constructor({headers = {}, preProcessors = [], postProcessors = []} = {}) {
this.options = {};
this.options.headers = headers;
this.options.mode = "cors";
this.preProcessors = preProcessors;
this.postProcessors = postProcessors;
Object.freeze(this.options);
@kaid
kaid / currentBlock.js
Created April 23, 2015 09:36
get current surrounding block in context
get currentBlock() {
let anchor = this.selected.anchor
, context = this.context;
if (!anchor) return;
return (function traverseUp(node) {
let block = node
, parent = node.parentNode;
@kaid
kaid / moveCursorTo.js
Created April 23, 2015 09:27
move cursor to beginning of element
function moveCursorTo(el) {
let selection = getSelection()
, range = document.createRange();
range.setStart(el.childNodes[0], 0);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
}