Skip to content

Instantly share code, notes, and snippets.

View icholy's full-sized avatar
💥
breaking things

Ilia Choly icholy

💥
breaking things
View GitHub Profile
@icholy
icholy / gobreak.sh
Last active December 16, 2015 19:18
Shell script to simplify setting GDB breakpoints
# Demo http://ascii.io/a/3019
# build
gdbb () {
# build with debug flags
go build -gcflags "-N -l" -o out
# make sure the build didn't fail
if [ $? != 0 ]; then return; fi
@icholy
icholy / gow.sh
Last active December 16, 2015 20:59
gow can be used in place of go and will re-run the command every time a *.go file is modified.
# watch/re-run go command
# Demo http://ascii.io/a/3049
gow () {
while true; do
clear
echo "go $@"
go "$@"
if [ $? -eq 0 ]; then break; fi
inotifywait -e modify *.go 2> /dev/null
@icholy
icholy / generic.go
Last active December 16, 2015 23:59
i like to pretend sometimes
type Stream<T> chan T
func (c Stream<T>) Map<U>(f func(T) U) Stream<U> {
out := make(Stream<U>)
go func(){
for x := range c {
out <- f(x)
}
}()
return out
var loop = function (fn) {
var next = function () { setTimeout(recur, 0); };
var recur = function () { fn(next); };
recur();
};
loop(function (next) {
something_async(function (data) {
// ...
@icholy
icholy / gist:5593188
Last active December 17, 2015 10:18
generator idea
var generator = function (fn) {
var next_callback = null,
yield_callback = null,
yield_value = null;
var reset = function () {
next_callback = null;
yield_callback = null;
yield_value = null;
var callbacks = [1, 2, 3].map(function (x) {
return function () {
console.log(x);
};
});
var wrong_invoke = function () {
callbacks.forEach(function (callback) {
setTimeout(callback, 0);
});
@icholy
icholy / gist:5646429
Created May 24, 2013 20:50
this is the easiest way to move panes between windows in tmux
# add to your ~/.tmux.conf
bind-key @ command-prompt -p "send pane to window:" "join-pane -t ':%%'"
gdbb () {
# build with debug flags
go build -gcflags "-N -l" -o out
# make sure the build didn't fail
if [ $? != 0 ]; then return; fi
# extract debugger comments
gdbb-extract "*.go" > .breakpoints
set print element 0
set confirm off
add-auto-load-safe-path /usr/share/go/src/pkg/runtime/runtime-gdb.py
@icholy
icholy / gist:5715833
Last active December 18, 2015 03:08
better google earth style api.
var applyStyle = (function () {
var type_handlers = {
line: function (s) { return s.getLineStyle(); },
icon: function (s) { return s.getIconStyle(); },
poly: function (s) { return s.getPolyStyle(); },
list: function (s) { return s.getListStyle(); },
balloon: function (s) { return s.getBalloonStyle(); },
label: function (s) { return s.getLabelStyle(); }
};