Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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 / ip6.sh
Last active August 29, 2015 14:03
linux ipv6 router
# ---------------
# Container
# ---------------
# Ensure that a default IPv6 route exists on the container (it should match the link-local address of the host running radvd)
ip -6 route
# ---------------
# Radvd Host
# ---------------
# Ensure that the host has IPv6 address and gateway *statically* assigned (don't rely on autoconf here)
@porjo
porjo / docker_postfix.md
Last active August 29, 2015 14:03
Docker and postfix

UPDATE: 2014/09/05

Looks like this is now fixed as of Docker v1.2.0


For the benefit of the interwebs I'm documenting this here as I've spent several hours pulling my hair out.

Postfix does not play well inside a docker container

@porjo
porjo / README.md
Last active August 29, 2015 14:03 — forked from mmoulton/README.md
Docker stats collection for collectd

Forked from: https://gist.github.com/mmoulton/6224509

Docker stats collection for collectd

This script can be used to feed collectd with cpu and memory usage statistics for running docker containers using the collectd exec plugin.

This script will report the used and cached memory as well as the user and system cpu usage by inspecting the appropriate cgroup stat file for each running container.

Usage

@porjo
porjo / golower.sh
Last active August 29, 2015 14:05
lowercase Golang error messages
# Look for instantiations of error using fmt.Errorf or errors.New, where first letter is upper-case. Convert that letter to lowercase.
# e.g.
# return fmt.Errorf("User...
# return errors.New("User...
# becomes
# return fmt.Errorf("user...
# return errors.New("user...
find -name '*.go' -exec sed 's/\(\(errors\.New\|fmt\.Errorf\)("\)\([A-Z]\)\(.*\)/\1\l\3\4/' {} \;
@porjo
porjo / vim_tips.md
Last active August 29, 2015 14:07
vim tips

Replace all occurrences of text block A with block B

visually select A "ay , visually select B "by then :s/<ctrl-r>a/<ctrl-r>b/g

Note: pasting in from register produces ^M and ^I in place of newlines and tabs. These need to be converted to \n and \t respectively.

(Technique also documented here: http://vim.wikia.com/wiki/Search_and_replace)