Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / flask.html
Created April 18, 2019 04:28
for hackathon
<!doctype html>
<title>Hello from Flask</title>
<h1>{{project_name}}</h1>
<h2>Teams</h2>
<table>
{% for team in teams %}
<tr>
<td><a href=/team/{{team.name}}> {{team.name}}</a></td>
</tr>
@lkrych
lkrych / Symboltable.go
Last active August 11, 2018 18:55
symbol table abstraction
type SymbolTable struct {
data *BSTree
}
//adds or updates node with key "key"
func (st *SymbolTable) put(key string, val int) {
st.data.root = put(st.data.root, key, val)
}
//returns node with key "key"
@lkrych
lkrych / createFreqTableFunc.go
Created August 11, 2018 18:51
How to build a frequency table with a Symbol Table
func createFreqTable(arr []string) SymbolTable {
st := &SymbolTable{
data: &BSTree{},
}
r := regexp.MustCompile("[ .,123456789]")
//iterate through words
for _, word := range arr {
if r.Match([]byte(word)) {
//skip punctuation, spaces or numbers
continue
@lkrych
lkrych / createFreqTable.go
Created August 11, 2018 18:49
Main function of frequency table construction
package main
import (
"fmt"
"io/ioutil"
"log"
"regexp"
"strings"
flags "github.com/jessevdk/go-flags"
@lkrych
lkrych / BSTree.go
Created August 11, 2018 18:45
Binary Search tree implementation in go
//A binary search tree has reference to its node
type BSTree struct {
root *Node
}
func (btree *BSTree) isEmpty() bool {
return btree.root == nil
}
//search for the key recursively
@lkrych
lkrych / stack_linked_list.go
Created August 5, 2018 18:23
Linked list implementation of stack in go
type Node struct {
val int
next *Node
}
type LinkedList struct {
head *Node
}
func (ll *LinkedList) insert(n int) {
func reversePolish(arithmeticExpression string) int {
//create regexp for matching against operators
r := regexp.MustCompile("[+-/*]")
//split input by spaces
splitInput := strings.Split(arithmeticExpression, " ")
//init Stack
s := &Stack{}
for _, char := range splitInput {
if r.Match([]byte(char)) {
@lkrych
lkrych / reversePolish.go
Last active August 5, 2018 18:30
go implementation of a postfix calculator
package main
import (
"fmt"
"log"
"regexp"
"strconv"
"strings"
"github.com/Knetic/govaluate"
@lkrych
lkrych / quickSort.go
Created July 29, 2018 18:21
quickSort demo
func quickSort(strings []string) []string {
if len(strings) <= 1 {
return strings
}
pivot := strings[0]
left := []string{}
right := []string{}
for i := 1; i < len(strings); i++ {
@lkrych
lkrych / createFile.go
Created July 29, 2018 18:05
helper functions for sortList
//helper function for creating input for main func
func createFile(numWords int) {
if _, err := os.Stat("./generatedStrings.txt"); err != nil {
//if file does not exist
//create file
f, err := os.Create("./generatedStrings.txt")
checkErr(err)
defer f.Close()
for i := 0; i < numWords; i++ {