Skip to content

Instantly share code, notes, and snippets.

@Komosa
Komosa / accept_files.go
Created October 13, 2015 21:44
Simple file receiver
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
@Komosa
Komosa / gheap.go
Last active November 7, 2015 11:38
Golang doesn't need neither runtime type-assertion nor code generation to provide generics
// this package is mostly copy-pasted from golang's std container/heap
// I changed Interface, Pop and Push in order to get rid of type assertions
// usage can be found in test file, benchmarks show that we can get about 27% of speedup for 1000 elems, or 10% for 10M elems (tested on go1.4)
package gheap
type Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
}
@Komosa
Komosa / drawstring.go
Last active March 2, 2016 22:37
termbox: drawString
func drawString(s string, x, y int, fg, bg termbox.Attribute) {
// s = strings.Replace(s, "\t", " ", -1)
// s = strings.Replace(s, "\r", "^R", -1)
w, _ := termbox.Size()
for _, ch := range s {
if x+runewidth.RuneWidth(ch) >= w {
break
}
termbox.SetCell(x, y, ch, fg, bg)
x += runewidth.RuneWidth(ch)
@Komosa
Komosa / .Xdefaults
Created December 8, 2015 13:47
xdefault
URxvt.keysym.M-C-d: command:\033]11;#000000\007\033]4;0;#000000\007\033]4;1;#ad2323\007\033]4;2;#1d6914\007\033]4;3;#ffee33\007\033]4;4;#2a4bd7\007\033]4;5;#8126c0\007\033]4;6;#814a19\007\033]4;7;#a0a0a0\007\033]4;8;#575757\007\033]4;9;#ffcdf3\007\033]4;10;#81c57a\007\033]4;11;#e9debb\007\033]4;12;#9dafff\007\033]4;13;#29d0d0\007\033]4;14;#ff9233\007\033]4;15;#ffffff\007\033]10;#FFFFFF\007
URxvt.keysym.M-C-l: command:\033]11;#a0a0a0\007\033]10;#000000\007\033]4;7;#000000\007\033]4;1;#ad2323\007\033]4;2;#1d6914\007\033]4;3;#ffee33\007\033]4;4;#0000b2\007\033]4;5;#8126c0\007\033]4;6;#814a19\007\033]4;0;#a0a0a0\007\033]4;8;#575757\007\033]4;9;#ffcdf3\007\033]4;10;#64eb55\007\033]4;11;#ffe9a5\007\033]4;12;#0081ff\007\033]4;13;#00f7fa\007\033]4;14;#ff9233\007\033]4;15;#ffffff\007
! in light mode lightGray and black are swapped; fg: black(#0), bg:lt gray (#0a0a0a)
! {d,l} blue, lt green, tan and cyan adjusted to be more readable
URxvt*loginShell:true
@Komosa
Komosa / dkvp.go
Last active December 30, 2015 11:31
parse lines as dkvp
package main
import (
"fmt"
"regexp"
"strconv"
"strings"
)
type DKVP map[string]string
@Komosa
Komosa / unzip.go
Last active January 5, 2016 13:46
unzip (missing functionality of windows)
package main
import (
"archive/zip"
"errors"
"fmt"
"io"
"log"
"os"
"path/filepath"
@Komosa
Komosa / remote.bat
Last active February 16, 2016 14:51
"Remote" execution of commands on windows with ssh-over-cygwin access
:loop
if exist remote.done (
timeout 2
goto loop
)
call remote.recipe.bat
goto loop
@Komosa
Komosa / cookie.go
Created March 10, 2016 06:41
persistent cookie
func TestUpdate(t *testing.T) {
os.RemoveAll(TEST_DATA_DIR)
defer os.RemoveAll(TEST_DATA_DIR)
if err := os.MkdirAll(TEST_DATA_DIR, 0700); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(TEST_DATA_DIR+"/number_of_partitions", []byte("2"), 0600); err != nil {
t.Fatal(err)
}
db, err := OpenDB(TEST_DATA_DIR)
@Komosa
Komosa / _test.go
Created July 11, 2016 10:03
error handling in golang tests
func Test(t *testing.T) {
fatalIf := func(err error) {
if err != nil {
t.Fatal(err)
}
}
err := os.MkdirAll(TEST_DATA_DIR, 0700)
fatalIf(err)