Skip to content

Instantly share code, notes, and snippets.

@osdrv
osdrv / main.go
Last active April 21, 2020 11:14
A basic binary tree deserializer: parses a binary tree structure from an input string like: (5(3(2(-123)())(4))(7(6)(9(8)())))
package main
import (
"bytes"
"errors"
"fmt"
"reflect"
"strconv"
"strings"
)
type KthLargest struct {
k int
items []int
}
func Constructor(k int, nums []int) KthLargest {
this := KthLargest{k: k, items: make([]int, 0, k)}
for _, num := range nums {
this.Add(num)
const fs = require("fs")
const DefaultBlockSize = 4096
function tail(fileName, nLines) {
return new Promise((resolve, reject) => {
fs.stat(fileName, (err, stat) => {
if (err != null) {
return reject(err)
}
@osdrv
osdrv / lisp-parser.go
Created November 24, 2019 18:42
Basic Lisp parser written in Golang. `add`, `mult` and `let` implemented only.
package main
import (
"bytes"
"fmt"
"strconv"
"strings"
)
type Scope map[string]int
@osdrv
osdrv / main.go
Created August 20, 2019 20:18
Archimedean spiral in golang using web server and png renderer
package main
import (
"image"
"image/color"
"image/png"
"io"
"math"
"net/http"
)
package main
import (
"encoding/json"
"io/ioutil"
"log"
@osdrv
osdrv / main.go
Created June 5, 2019 12:28
YAML.v2 parser attribute name case sensitivity
package main
import (
"fmt"
yaml "gopkg.in/yaml.v2"
)
type Foo struct {
@osdrv
osdrv / main.go
Created June 5, 2019 12:24
YAML parser attribute name case insensitivity
package main
import (
"fmt"
"github.com/ghodss/yaml"
)
type Foo struct {
Attr int32 `json:"attrFoo"`
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strings"
"time"
)
type TrieNode struct {
pool map[rune]*TrieNode
}
func NewTrieNode() *TrieNode {
return &TrieNode{pool: make(map[rune]*TrieNode)}
}
func (t *TrieNode) Insert(word string) {
ptr := t