Skip to content

Instantly share code, notes, and snippets.

@cnnrznn
cnnrznn / list_vs_dict.py
Created September 24, 2020 19:56
Timing comparison of membership lookup
import time
from random import randint
num_items = 1000000
num_iters = 1000
randoms_list = [randint(0, 1000000) for i in range(num_items)]
randoms_dict = {num: True for num in randoms_list}
randoms_set = {num for num in randoms_list}
package main
import (
"fmt"
"os"
"runtime"
"strconv"
"strings"
"sync"
package main
import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
func worker(line string) []string {
// do your phone# parsing
return []string{}
}
func main() {
fn := os.Args[1]
numWorkers := 10
srcChans := make([]chan interface{}, numWorkers)
outChan := make(chan []string, 1024)
@cnnrznn
cnnrznn / csv-job.go
Created May 5, 2020 13:10
An MR job using csv input/output
package main
import (
"fmt"
"github.com/cnnrznn/gomr"
"os"
"runtime"
"strings"
"sync"
)
@cnnrznn
cnnrznn / transport.js
Created March 5, 2020 23:30
Scope of "this"
/* Doesn't work */
class Transport extends EventEmitter.EventEmitter {
constructor() {
super();
this.connected = false;
this.ws = new WebSocket("ws://localhost:8081");
this.ws.onmessage = fromServer;
this.ws.onopen = function(event) {
this.connected = true;
}