Skip to content

Instantly share code, notes, and snippets.

View cngkaygusuz's full-sized avatar

Cengiz Kaygusuz cngkaygusuz

  • Google
  • Seattle, WA
View GitHub Profile
@cngkaygusuz
cngkaygusuz / tests.go
Created August 20, 2014 19:44
Some tests I wrote for go and don't need anymore
func Test_read3(t *testing.T) {
var bstr ByteStream
bstr.length = 3
bstr.data = []byte { 0xdd, 0xaf, 0xaf }
readcnt, rb := bstr.read(3)
if readcnt != 3 {
t.Errorf("Readcnt; Expected 3, got %d", readcnt)
@cngkaygusuz
cngkaygusuz / argparse.py
Created August 21, 2014 14:52
Get arguments from command line using built-in argparse library and receive them in a dictionary.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--argument_one", help="This argument does nothing")
parser.add_argument("--argument_two", help="This argument is even more useless than other one.")
parsed = parser.parse_args() # By default, this uses sys.argv.
# This means the arguments doesnt have to be coming from CLI.
@cngkaygusuz
cngkaygusuz / dictfilter.py
Created August 21, 2014 15:01
Filter a dictionary by certain keys
# This code fails because you cannot change a dictionary's size during iteration.
bar = {1: "a",
2: None,
3: "c"
}
for key, value in bar.iteritems():
if value is None:
bar.pop(key)
@cngkaygusuz
cngkaygusuz / rmdocker.sh
Created August 22, 2014 11:53
Remove all docker containers
docker ps -a | awk '{print $1}' | grep ^[0-9a-f] | xargs docker rm
@cngkaygusuz
cngkaygusuz / docker.bash
Created February 12, 2015 11:48
Helpful bash functions for docker
# Copy and paste this code to your .bashrc and relog to your terminal
function dntr {
docker exec -ti $1 bash
}
function dstry {
docker stop -t 0 $1
docker rm $1
}
@cngkaygusuz
cngkaygusuz / DFS.go
Created August 23, 2015 09:36
DFS for some random struct.
func (bon* BONode) partition() ([]*BONode, []*BONode) {
// Partition a node, yielding her rank 0 children and rank >0 children.
// This should take O(logn) time, because every node except the root has at most 2 children, which one of those children has rank 0.
nodestack := make([]*BONode, 10) // this is to be used as stack
nodestack = appendList(nodestack, bon.children_head)
zeros := make([]*BONode, 10)
nonzeros := make([]*BONode, 10)
@cngkaygusuz
cngkaygusuz / BO_Pop.go
Created August 23, 2015 09:46
Pop method for Brodal-Okasaki Heap
func (bq *BOHeap) Pop() int {
// Pop for Brodal-Okasaki Heap.
// Root node is the return value.
// If the root happens to have a subqueue, merge those nodes using ordinary binomial heap procedure.
// Among the children of root, elect a new minimum node.
// Merge the children of the new root according to skew binomial pop procedure.
// Pop for skew binomial:
// Remove the minimum root
// Partition the gone roots children into 2 groups: Those with rank 0 and those with rank >0
@cngkaygusuz
cngkaygusuz / scr.sh
Last active August 31, 2015 09:59
Get the directory of executed script.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@cngkaygusuz
cngkaygusuz / helpers.sh
Last active May 20, 2016 06:46
Extra helpers for bashrc
function cd {
builtin cd $1
ls
}
alias cb="cd /base"
# Docker
function dntr {
docker exec -ti $1 bash
@cngkaygusuz
cngkaygusuz / .aliases.sh
Last active June 26, 2016 11:23
Aliases I use for various things. Meaningful with zsh.
alias cb="cd /base" # I use /base for various things. You can ignore this line.
alias edal="vim ~/.aliases" # To edit aliases.
alias gitc="git commit -m"
alias gita="git add ."
# Colored 'ls' from bash.
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"