Skip to content

Instantly share code, notes, and snippets.

View jmoiron's full-sized avatar

Jason Moiron jmoiron

View GitHub Profile
@jmoiron
jmoiron / bongo.sh
Created June 30, 2012 21:58
export and import all collections from a mongodb database into/outof a single tarball
#!/bin/bash
LOADING=false
usage()
{
cat << EOF
usage: $0 [options] dbname
OPTIONS:
@jmoiron
jmoiron / masquerade.sh
Created August 1, 2012 18:39
Toggle masquerading as a domain, forwarding configurable port to 80 (OSX and Linux)
#!/bin/bash
PORT="8000"
usage() {
cat << EOF
usage: $0 host [port]
EOF
}
@jmoiron
jmoiron / autogobuild.sh
Created August 2, 2012 23:27
Run this script in your directory to auto build whenever you modify a golang file
#!/bin/bash
cur=`pwd`
inotifywait -mqr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e modify ./ | while read date time dir file; do
ext="${file##*.}"
if [[ "$ext" = "go" ]]; then
echo "$file changed @ $time $date, rebuilding..."
go build
@jmoiron
jmoiron / livescores.py
Created September 11, 2012 02:19
scrape livescores.com
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" """
import json
from urllib2 import urlopen
from lxml.html import document_fromstring
from lxml.cssselect import CSSSelector as cs
@jmoiron
jmoiron / gist:3995399
Created November 1, 2012 18:00
xml wrapping functions for lxml-ish css selection
// Selectable implements a simple interface which allows to get the inner text
// of some element as well as run a CSS select on it and get a list of nodes
type Selectable interface {
CssSelect(selector string) []Node
Text() string
}
// A node wrapper, in order to provide a similar interface in the future
// possibly without gokogiri
type Node struct {
package main
import (
"bytes"
"fmt"
"github.com/moovweb/gokogiri"
"github.com/moovweb/gokogiri/css"
"github.com/moovweb/gokogiri/html"
"github.com/moovweb/gokogiri/xml"
"github.com/moovweb/gokogiri/xpath"
@jmoiron
jmoiron / color.go
Last active December 14, 2015 19:29
very simple console color escapes for python & go
const (
white = iota + 89
black
red
green
yellow
blue
purple
)
@jmoiron
jmoiron / blargparse.py
Created September 12, 2013 21:02
allow certain arguments to short circuit required positional arguments and other argparse errors
#!/usr/bin/env python
# I had a script which I wanted to have a special option that short-circuited the normal
# argument parsing error handling behavior so that it could be run without thenormal
# required arguments. This option would work similar to how `--help` or `--version`
# works, except that the parser would return a valid args object in its presence
# rather than exiting the program.
import argparse
@jmoiron
jmoiron / valuer.go
Created October 14, 2013 18:03
Example uses of sql.Scanner and driver.Valuer
package main
import (
"bytes"
"compress/gzip"
"database/sql/driver"
"errors"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
+++ Statistics Dump +++ (1393879884)
++ Incoming Requests ++
7122195 QUERY
1 IQUERY
4 STATUS
1 NOTIFY
++ Incoming Queries ++
5189989 A
81035 NS
1754 CNAME