Skip to content

Instantly share code, notes, and snippets.

@ericchiang
ericchiang / gist:11185326
Created April 22, 2014 16:19
Beer recommender
import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
df = pd.read_csv("data/beer_reviews.csv")
# let's limit things to the top 250
n = 250
top_n = df.beer_name.value_counts().index[:n]
df = df[df.beer_name.isin(top_n)]
@ericchiang
ericchiang / gist:07668b73c5837d97aaf8
Last active August 29, 2015 14:03
Golang pointers
// This is a Gist to try to help you understand go pointers.
// You can run it in an interactive environment over on the go
// playground at: http://play.golang.org/p/pYTsfo6uhz
package main
import (
"fmt"
)
import re, collections
def words(text): return re.findall('[a-z]+', text.lower())
def train(features):
model = collections.defaultdict(lambda: 1)
for f in features:
model[f] += 1
return model
@ericchiang
ericchiang / Dockerfile
Last active August 29, 2015 14:06
pup Dockerfile test
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y curl
RUN curl -L https://github.com/EricChiang/pup/releases/download/0.1.1/pup_linux_386 > pup
RUN chmod +x /pup
RUN wget http://www.pro-football-reference.com/years/2013/games.htm
RUN /pup < games.htm table#games 'a[href*=boxscores]' attr{href}
@ericchiang
ericchiang / shellshock.sh
Last active August 29, 2015 14:06
Shellshock Ubuntu patch
#!/bin/bash
env X="() { :;} ; echo shellshock" /bin/sh -c "echo completed"
env X="() { :;} ; echo shellshock" `which bash` -c "echo completed"
sudo apt-get update
# for /bin/bash
sudo apt-get upgrade -y bash
@ericchiang
ericchiang / streaming_pup.go
Created October 11, 2014 12:57
pup - Streaming parser test
package main
import (
"fmt"
"io"
"log"
"net/http"
"code.google.com/p/go.net/html"
)
@ericchiang
ericchiang / app.py
Created October 14, 2014 21:17
Flask hello world
import sys
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
@ericchiang
ericchiang / gotools.sh
Last active August 29, 2015 14:08
Some bash functions for go dependencies
# List all non-standard Go depencencies as a tree.
function gotree() {
level=${2:-'0'}
for package in `goimports $1`; do
printf "%${level}s$package\n"
gotree $package $[$level+2]
level=$[$level-2]
done
}
@ericchiang
ericchiang / lookup_module.py
Last active August 29, 2015 14:08
Find pip versions of modules
import types
import warnings
def lookup(obj):
"""Take a python object or class and determine the module it's imported
from and the version of that module.
"""
if type(obj) == types.ModuleType:
try:
module = obj.__name__
$ ssh -A vm
$ git config --global url."git@github.com:".insteadOf "https://github.com/"
$ cat ~/.gitconfig
[url "git@github.com:"]
	insteadOf = https://github.com/
$ go get github.com/private/repo && echo Success!
Success!