Skip to content

Instantly share code, notes, and snippets.

View parvezmrobin's full-sized avatar

Parvez M Robin parvezmrobin

View GitHub Profile
package main
func main() {
println("Hello, darkness my old friend")
}
@parvezmrobin
parvezmrobin / mul-chan.go
Last active September 15, 2019 18:57
A Go program that will panic
package main
import (
"strconv"
"sync"
)
func main() {
channel := make(chan string, 20)
wg := sync.WaitGroup{}
const fs = require('fs');
const virusChecker = require('virus-checker') // some non-existing pseudo library
const getFilesForProcessing = function* () {
const dir = 'path/to/directory/';
const fileNames = fs.readdirSync(dir);
for(const fileName of fileNames){
yield fs.readdirSync(dir + fileName);
}
for(const superHero of superHeroes()){
console.log(superHero);
/*
Nick Fury
Stephen Strange
Thor Odinson
Clint Barton
Bruce Banner
Steve Rogers
Tony Stark
const superHeroes = function* () {
for(let node = head; node !== null; node = node.next) {
yield node.name;
}
}
const spiderMan = {name: "Peter Parker", next: null};
const ironMan = {name: "Tony Stark", next: spiderMan};
const captainAmerica = {name: "Steve Rogers", next: ironMan};
const hulk = {name: "Bruce Banner", next: captainAmerica};
const hawkEye = {name: "Clint Barton", next: hulk};
const thor = {name: "Thor Odinson", next: hawkEye};
const drStrang = {name: "Stephen Strange", next: thor};
const head = {name: "Nick Fury", next: drStrang};
for(const i of inOrder(fifty)) {
console.log(i); // 9 12 14 17 19 23 50 72 54 67 76
}
function* inOrder (node) {
if(node.left){
yield *inOrder(node.left);
}
yield node.value;
if(node.right){
yield *inOrder(node.right);
}
}
// 9, 12, 14, 17, 19, 23, 50, 72, 54, 67, 76
const nine = {value: 9, left: null, right: null};
const fourteen = {value: 14, left: null, right: null};
const twelve = {value: 12, left: nine, right: fourteen};
const nineteen = {value: 19, left: null, right: null};
const twentythree = {value: 23, left: nineteen, right: null};
const seventeen = {value: 17, left: twelve, right: nineteen};
const sixtyseven = {value: 67, left: null, right: null};
const fiftyfour = {value: 54, left: null, right: sixtyseven};
function* colors() {
const colors = ['red', 'blue', 'green'];
for(let i = 0; ; i = (i+1) % 3) {
yield colors[i];
}
}