Skip to content

Instantly share code, notes, and snippets.

View trigger.go
package main
// Trigger ensures a worker runs once after it has been triggered, no matter how many trigger events happened during
// its last run.
// Usage:
// trigger := NewTrigger()
// go func() {
// for _ = range trigger {
// do_work()
AndreKR / result_and_error_channel.go
Last active Mar 19, 2017
Returning result and error through a channel
View result_and_error_channel.go
// (I prefer "Two channels wrapped" and "Anonymous struct" over the other two)
// Two channels
resultCh := make(chan Result)
errorCh := make(chan Result)
go func(resultCh chan Result, errorCh chan errpr) {
errorCh <- errors.New("Does not compute")}
resultCh <- result
}(resultCh, errorCh)
View go_webdriver_comparison.go
package main
import (
agwd ""
tbwd ""
sgwd ""
// Helper for sourcegraph/go-selenium
AndreKR / detect_http_abort.go
Last active Mar 15, 2017
Detecting client closed connection
View detect_http_abort.go
func handleRequest(w http.ResponseWriter, r *http.Request) {
cn := w.(http.CloseNotifier)
cc := cn.CloseNotify()
go func() {
AndreKR / draw_text.go
Created Mar 14, 2017
Three ways of drawing text in go
View draw_text.go
// Initialize an empty image
dest := image.NewRGBA(image.Rect(0, 0, 800, 300))
// Draw a white background
draw.Draw(dest, dest.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
// Read the font
fontBytes, err := ioutil.ReadFile(exeDir + "/DejaVuSans.ttf")
if err != nil {
View test_postgres_enum.sql
DROP TABLE IF EXISTS public.with_enum;
DROP TABLE IF EXISTS public.with_text;
CREATE TYPE public.my_enum AS ENUM ('axyzxyz', 'bxyzxyz', 'cxyzxyz', 'dxyzxyz');
CREATE TABLE public.with_enum (
blah integer,
thecolumn my_enum
View mysql_to_postgresql.txt
To help you with the process of converting a MySQL app to PostgreSQL, I collected a list of differences between MySQL and PostgreSQL (PG).
Important changes:
* Strings are quoted with '...' or with $token$...$token$. Single-quotes are escaped with single-quotes.
* Identifiers are folded to lowercase, unless they are quoted with "..." which makes them case-sensitive
* The max identifier length is 63
* There are some system columns that cannot be used as an identifier (probably not a problem)
* Expressions are evaluated in arbitrary order, so WHERE x > 0 AND y/x > 1.5 can lead to a division by zero and has to be replaced with WHERE CASE WHEN y > 0 THEN y/x > 1.5 ELSE FALSE END
* SELECT CASE WHEN x > 0 THEN x ELSE 1/0 END would still lead to a division by zero because the constant 1/0 is evaluated even before the query starts
View wireshark_remote.bat
@echo off
set PLINK_PATH=C:\Program Files (x86)\PuTTY\plink.exe
set WIRESHARK_PATH=C:\Program Files\Wireshark\Wireshark.exe
if "%1" == "" goto :usage
"%PLINK_PATH%" -ssh %1 "tcpdump -ni %2 -s 0 -w - not port 22" | "%WIRESHARK_PATH%" -k -i -
goto :end
AndreKR /
Last active Dec 11, 2015
Elasticsearch notes

Elasticsearch notes

Things named "explain"

Three things can be explained in elasticsearch:

Explain for each hit how its score was computed (Docs: Explain)
GET <index>/<type>/_search?explain