This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"net" | |
"net/http" | |
"net/smtp" | |
"regexp" | |
"strings" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function erato(n){ | |
let map = new Map((new Array(n-1).fill(1)).map((n,i)=>[i+2,true])); | |
for (let i = 2; i <= Math.sqrt(n);i++){ | |
if (!map.get(i)) continue | |
for (let j = i*2; j <= n; j += i) map.set(j,false) | |
} | |
return Array.from(map).filter(([n,b])=>b).map(([n])=>n); | |
} | |
console.log(erato(100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Implement regular expression matching with the following special characters: | |
* . (period) which matches any single character | |
* * (asterisk) which matches zero or more of the preceding element | |
That is, implement a function that takes in a string and a valid regular |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { strict as assert } from "assert"; | |
type Node<V> = { parent?: Node<V>; next?: Node<V>; value: V }; | |
class DoublyLinkedList<V> { | |
private _head?: Node<V>; | |
private _tail?: Node<V>; | |
get head() { | |
return this._head!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function typify(spec, reqParams) { | |
return walk(null, spec, new Set(reqParams)); | |
function walk(name, prop, req = new Set()) { | |
const { | |
name: propName, | |
type, | |
items, | |
required = [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monthDays(year){ | |
const m = (new Array(12)).fill(1).map((_,x)=>x%2?30:31); | |
if (year % 4) m[1] = 28; | |
else if (year % 100) m[1] = 29; | |
else if (year % 400) m[1] = 28 | |
else m[1] = 28; | |
return m; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function combine<T extends any[]>(...args: ((...fnArgs: T) => void)[]) { | |
return (...a: T) => args.forEach(fn => fn(...a)); | |
} | |
function foo(n: number, o: string){ | |
console.log(`string ${n} ${o}`); | |
} | |
function bar(n: number, o: string){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Graph { | |
constructor(){ | |
this.nodes = {}; | |
} | |
addNode(n){ | |
if (!this.nodes[n]) this.nodes[n] = []; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Graph { | |
constructor(){ | |
this.nodes = {}; | |
} | |
addNode(n){ | |
if (!this.nodes[n]) this.nodes[n] = []; | |
} | |
addDirEdge(a,b){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_json(jsonStr) { | |
let tokens = []; | |
for (let i = 0; i < jsonStr.length; i++) { | |
if (jsonStr[i] === '"') { | |
value = ''; | |
i++ ; | |
while (jsonStr[i] !== '"') { | |
value += jsonStr[i]; |
NewerOlder