Skip to content

Instantly share code, notes, and snippets.

View netbrain's full-sized avatar
🤔

Kim Eik netbrain

🤔
View GitHub Profile
class Cell {
boolean alive = false;
public void setAlive(boolean alive){
this.alive = alive;
}
public boolean isAlive(){
return this.alive;
}
@netbrain
netbrain / gist:2224917
Created March 28, 2012 09:00
varnish config test
sub vcl_recv {
if(req.request == "PUT" && req.url ~ "^/api/0.1/userMedia"){
ban ("req.url == '/api/0.1/user'");
return(pass);
}
if(req.url ~ "^/api/0.1"){
return(lookup);
}
}
@netbrain
netbrain / mazestring
Last active September 9, 2015 12:06
/*
Converts a maze to a string of the format:
▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜▛▀▜
▌· · ·▐▌· ·▐▌· · · · ·▐▌· · · ·▐▌·▐
▙ ▟▙▄▟▙ ▟▙ ▟▙ ▟▙ ▟▙ ▟▙▄▟▙▄▟▙ ▟▙▄▟▙ ▟▙▄▟▙ ▟▙ ▟
▛ ▜▛▀▜▛ ▜▛ ▜▛ ▜▛ ▜▛ ▜▛▀▜▛▀▜▛ ▜▛▀▜▛ ▜▛▀▜▛ ▜▛ ▜
▌· ·▐▌· ·▐▌· ·▐▌·▐▌· ·▐▌· ·▐▌· ·▐▌· ·▐
▙▄▟▙ ▟▙▄▟▙▄▟▙▄▟▙ ▟▙▄▟▙ ▟▙ ▟▙▄▟▙ ▟▙▄▟▙ ▟▙▄▟▙ ▟
▛▀▜▛ ▜▛▀▜▛▀▜▛▀▜▛ ▜▛▀▜▛ ▜▛ ▜▛▀▜▛ ▜▛▀▜▛ ▜▛▀▜▛ ▜
▌· ·▐▌· ·▐▌· ·▐▌· ·▐▌· ·▐▌· ·▐▌· ·▐▌·▐
@netbrain
netbrain / .gitconfig.mergetool.example
Last active March 27, 2017 06:56
gitconfig intellij mergetool and diff setup for windows
[merge]
tool = intellij
[mergetool "intellij"]
cmd = cmd.exe //c "\"C:/Program Files (x86)/IntelliJ IDEA Community Edition 12.0/bin/idea.bat\" merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
trustExitCode = true
[diff]
tool = intellij
[difftool "intellij"]
cmd = cmd.exe //c "\"C:/Program Files (x86)/IntelliJ IDEA Community Edition 12.0/bin/idea.bat\" diff \"$LOCAL\" \"$REMOTE\""
@netbrain
netbrain / enc2geojson.sh
Created November 10, 2017 11:06
Convert enc files to geojson files
#!/bin/bash
ls *.000 | xargs -I @ bash -c "ogrinfo @ | awk '{if(NR>3)print \$2}' | xargs -I xxx ogr2ogr -f \"GeoJSON\" @_xxx.geojson @ xxx"
@netbrain
netbrain / retrans
Created February 8, 2018 10:54
retrans notes
/* RETRANSMISSION/FAST RETRANSMISSION/OUT-OF-ORDER
* If the segment contains data (or is a SYN or a FIN) and
* if it does not advance the sequence number, it must be one
* of these three.
* Only test for this if we know what the seq number should be
* (tcpd->fwd->nextseq)
*
* Note that a simple KeepAlive is not a retransmission
*/
@netbrain
netbrain / Bus.ts
Created December 12, 2018 08:00
Simple Typescript Event Bus
interface Subscription<T> {
id: number,
type: new () => T
fn: (event:T)=>any
}
class Bus {
private seq:number = 0;
private subscribers:Map<string,Array<Subscription<any>>> = new Map();
@netbrain
netbrain / spit-test-train.sh
Last active January 27, 2020 06:12
Create test/train set example
#!/bin/bash
find /path/to/JPEGImages | grep jpg$ | shuf > files.list
cat files.list | wc -l
#180 = 10%
cat files.list | head -n 180 > test.txt
#rest goes into train.txt
cat files.list | grep -v -f test.txt > train.txt
// A []C.int64_t slice backed by C memory.
// See: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices
// Using [1<<27] instead of [1<<30] so it works on 32-bit architecture
@netbrain
netbrain / gist:eca4bb501a0a4764833c705d6ebf0014
Last active January 27, 2020 06:09
various image oprations
//dump jpeg
curl "http://10.41.3.120/cgi-bin/faststream.jpg?stream=MxPEG&fps=0.1" | mxgconv_linux format=jpeg,of=img
//split images
find ./ | grep jpg |xargs -I@ convert -quality 100 -crop 640x480 @ @_cropped_%d.jpg
//preserve original filename in images
ls | xargs -I@ echo exiftool -Comment=@ @
//rename file to md5sum name