Skip to content

Instantly share code, notes, and snippets.

View cancel2.go
package main
import (
"context"
"log"
"sync"
"time"
)
var wg sync.WaitGroup
@gerep
gerep / main.go
Created Nov 24, 2017 — forked from hnakamur/main.go
A go example to stop a worker goroutine when Ctrl-C is pressed (MIT License)
View main.go
package main
import (
"fmt"
"os"
"os/signal"
"time"
"golang.org/x/net/context"
)
View cancel_goroutines.go
package main
import (
"context"
"log"
"sync"
"time"
)
var wg sync.WaitGroup
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
View server.go
package main
import (
"fmt"
"log"
"net/http"
"html/template"
"github.com/gorilla/sessions"
View gist:67e7a258c3b9d9ca4a5a93f379c76978
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@gerep
gerep / httpbenchmark.go
Last active May 6, 2016 — forked from luisbebop/httpbenchmark.go
http benchmark tool
View httpbenchmark.go
import (
"flag"
"fmt"
"net/http"
)
var (
n = flag.Int("n", 100, "number of GETs to run")
s = flag.Bool("s", false, "whether to use HTTPS")
c = flag.Bool("c", false, "whether to run concurrently")
View cut_the_hope.rb
f = IO.binread("avatar.gif")
@parts = []
f.each_char.each_slice(10000).each do |s|
@parts << s.join
end
@text = ""
@parts.each { |chunk| @text << chunk }
View server.go
package main
import (
"fmt"
"bufio"
"net"
"io"
)
func main() {
View weird.rb
def foo(a=:default, b)
puts "a=#{a}, b=#{b}"
end
foo(:value)
foo(:x, :y)