Skip to content

Instantly share code, notes, and snippets.

@nickpresta
nickpresta / gist:3188506
Created July 27, 2012 14:58
Python Fix for Mountain Lion

Python Fix for Mountain Lion

Install Xcode Command Line Tools

  1. Download from the Apple Site
  2. Install

Reinstall PIP

sudo easy_install pip

@nickpresta
nickpresta / git-tidy.sh
Created January 8, 2013 23:11
Clean merged branches.
#!/bin/sh
printf "\e[32mRemoving merged branches:\n\033[0m"
git branch --merged master | grep -v master
read -p "Are you sure? " -n 1
echo "\n"
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
@nickpresta
nickpresta / git-morning.sh
Created January 8, 2013 23:11
Show an overview of your activity.
git for-each-ref --sort=-committerdate --shell --format="echo %(refname:short) by %(authorname) && git log -n 1 --format=format:\" %%cd%%n %%B\" %(refname)" refs/heads/ | sh | less -R

Why I Like Go

I visited with PagerDuty yesterday for a little Friday beer and pizza. While there I got started talking about Go. I was asked by Alex, their CEO, why I liked it. Several other people have asked me the same question recently, so I figured it was worth posting.

Goroutines

The first 1/2 of Go's concurrency story. Lightweight, concurrent function execution. You can spawn tons of these if needed and the Go runtime multiplexes them onto the configured number of CPUs/Threads as needed. They start with a super small stack that can grow (and shrink) via dynamic allocation (and freeing). They are as simple as go f(x), where f() is a function.

Channels

@nickpresta
nickpresta / math.go
Last active December 17, 2015 13:09 — forked from mwarkentin/math.go
package math
import (
"errors"
m "math"
)
// Finds the minimum value in a slice of numbers
func Min(xs []float64) (float64, error) {
if len(xs) == 0 {
$ rethinkdb -j "172.16.42.218:28015"
info: Running rethinkdb 1.6.1 (CLANG 4.2 (clang-425.0.28))...
info: Running on Darwin 12.4.0 x86_64
info: Loading data from directory /Users/nickp/rethinkdb_data
info: Listening for intracluster connections on port 29015
info: Attempting connection to 1 peer...
## CALLING CODE
from django.conf import settings
def my_function():
foo = getattr(settings, 'foo', None)
if foo:
return foo.BAR
return BAZ
class MyRouter(object):
def db_for_read(self, model, **hints):
if model._meta.object_name == 'SpecialModel':
return 'special'
return False
def db_for_write(self, model, **hints):
return self.db_for_read(model, **hints)
def allow_syncdb(self, db, model):
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Method: %s\n", r.Method)
}
// trunecateString trunecates a string up to a maximum of length characters.
func truncateString(s string, length int) string {
l := utf8.RuneCountInString(s)
if l < length {
length = l
}
out := make([]string, length)
var ch rune
var size int
i, curr := 0, 0