Skip to content

Instantly share code, notes, and snippets.

@porjo
porjo / mcast_pub.go
Last active January 28, 2019 22:49
Simple PUB-SUB using multicast, written in Go. The publisher sends the string 'hello' every 2 seconds to IPv4 multicast 224.0.0.1 on UDP port 5000
package main
import (
"bufio"
"fmt"
"net"
"time"
)
func main() {
@porjo
porjo / docker_LAMP.md
Last active November 21, 2019 09:54
Minimal Centos 6.4 LAMP stack running on Docker (Ubuntu 13.04 host). End result is running httpd and port 80 is forwarded through from host to container.

Installation

sudo apt-get update
sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring
sudo apt-get install linux-image-extra-`uname -r`
sudo sh -c "curl http://get.docker.io/gpg | apt-key add -"
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker
@porjo
porjo / tasks.go
Last active December 23, 2015 14:29
Launch tasks and wait for finish
//
// Example thanks to DMorsing on #go-nuts Freenode channel
// http://play.golang.org/p/dmUfGKnbZ3
//
package main
import "fmt"
import "time"
import "math/rand"
import "sync"
@porjo
porjo / trk2gpx.sh
Created January 9, 2014 00:47
Convert .trk files from Go Cruise to GPX files suitable for OSM
#!/bin/bash
#
# Convert .trk files from Go Cruise to GPX files suitable for OSM
if [ $# -ne 1 ]
then
echo "Usage: $0 <input file>"
exit
fi
@porjo
porjo / reddit_oauth.go
Last active August 29, 2015 13:56
Go oauth client for Reddit
package main
import (
"fmt"
"github.com/codegangsta/martini"
"github.com/porjo/goauth2/oauth"
"io/ioutil"
"log"
"net/http"
)
@porjo
porjo / json.sql
Last active August 29, 2015 13:57
Postgresql: JSON operations cheatcheet
-- Select empty JSON field
select * from mytable where jsonfield::text = '{}'
-- Select 'title' within JSON field
select * from mytable where jsonfield->>'title' = 'Great Expectations'
select * from mytable where jsonfield->>'title' like 'Great Expectations%'
-- Update: Postgres 9.3 you must update whole field
update mytable set jsonfield = '{}' where id = 1
@porjo
porjo / autocomplete.go
Last active August 29, 2015 13:58
Autocomplete using Redis backend. Handles UTF8 strings. See this blog post on how to load the Redis data http://oldblog.antirez.com/post/autocomplete-with-redis.html
import (
"strings"
u8 "code.google.com/p/go.exp/utf8string"
"github.com/garyburd/redigo/redis"
)
// Based on code by Salvatore Sanfilippo
// http://oldblog.antirez.com/post/autocomplete-with-redis.html
func RedisComplete(prefix string, count int) (results []string, err error) {
@porjo
porjo / reminders
Last active August 29, 2015 14:00
Linux 'remind' utility
# Example reminders file
FSET _yr_num(yr) ORD(YEAR(TRIGDATE()) - yr)
# Trigger warning every 14, 7, 1, 0 days
FSET _warnfunc(x) choose(x, 14, 7, 1, 0)
# -------------------
# Birthday's
# -------------------
REM 3 Jan WARN _warnfunc MSG %"John's [_yr_num(1970)] Birthday%" is %k (%xd)
@porjo
porjo / vimrc
Created May 15, 2014 01:25
vimrc 2014-05-15
syntax on
nnoremap <C-n> :tabnext<CR>
nnoremap <C-p> :tabprevious<CR>
nnoremap <C-w>t :tabnew<CR>
set number
set smartindent
set autoindent
set ruler
@porjo
porjo / overpass.sh
Created June 20, 2014 04:05
osm overpass api - command line usage
# The following outputs .osm format suitable for JOSM (note 'out meta')
wget "http://www.overpass-api.de/api/interpreter?data=[out:xml];(way[name~\"[rR]ememberance\"];node[name~\"[rR]ememberance\"];relation[name~\"[rR]ememberance\"];);(._;>;);out meta;" -O remember.osm