This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| // fibonacci is a function that returns | |
| // a function that returns an int. | |
| func fibonacci() func() int { | |
| fib := 0 | |
| return func() int { | |
| first, second := 0, 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "io" | |
| "os" | |
| "strings" | |
| ) | |
| type rot13Reader struct { | |
| r io.Reader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run job in background, redirect its output to a non-blocking pipe, | |
| # and leave the rc and stdout/stderr to be handled by attach_wait_jobs() | |
| jobs_tmp_dirs="" | |
| function run_job() { | |
| local dir=$(mktemp -d -t gearXXXXXX) | |
| jobs_tmp_dirs="$jobs_tmp_dirs $dir" | |
| mkfifo $dir/pipe | |
| mkfifo $dir/pipe_nonblock | |
| "$@" &>$dir/pipe_nonblock & | |
| echo $! >$dir/pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "reflect" | |
| ) | |
| type Map map[string]string | |
| type Object struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sourceURL := "http://example.com" | |
| // Resolve URL up to 12 redirects. | |
| client := &http.Client{ | |
| CheckRedirect: func() func(req *http.Request, via []*http.Request) error { | |
| redirects := 0 | |
| return func(req *http.Request, via []*http.Request) error { | |
| if redirects > 12 { | |
| return errors.New("stopped after 12 redirects") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "net/http" | |
| "github.com/pressly/chi" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export new_user="your_user" | |
| export dbname="your_db_name" | |
| cat <<EOF | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname" | grep ALTER | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname" | |
| SELECT 'ALTER TABLE '||schemaname||'.'||tablename||' OWNER TO $new_user;' | |
| FROM pg_tables WHERE schemaname = 'public'; | |
| SELECT 'ALTER SEQUENCE '||relname||' OWNER TO $new_user;' FROM pg_class WHERE relkind = 'S'; | |
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package zlib | |
| import ( | |
| "bytes" | |
| "io" | |
| "testing" | |
| ) | |
| type zlibTest struct { | |
| desc string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| slice := make([]int, 159) | |
| // Split the slice into batches of 20 items. | |
| batch := 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*' | |
| git fetch | |
| git checkout -t origin/pr/12 | |
| # Based on https://gist.github.com/piscisaureus/3342247 |
OlderNewer