Skip to content

Instantly share code, notes, and snippets.

@mittenchops
mittenchops / add_pin_unpin.go
Created June 11, 2018 06:07 — forked from leerspace/add_pin_unpin.go
example of adding, pinning, and unpinning using IPFS as library
package main
import (
"context"
"log"
"net"
core "github.com/ipfs/go-ipfs/core"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
@mittenchops
mittenchops / testrpy2.py
Created June 4, 2014 21:14
Testing rpy2
import pandas as pd
import numpy as np
import rpy2
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
from pprint import pprint
import requests
req = requests.get('http://www.google.com')
pprint(req)
@mittenchops
mittenchops / noodlecount.sh
Created May 19, 2014 15:07
Count of noodle employees
wget -q -O- http://www.noodle.org/team | grep -c "member-bio"
@mittenchops
mittenchops / college-age-census.R
Created May 1, 2014 14:43
College-age-population from census
library(XML)
#url = paste("http://www.census.gov/population/international/data/idb/region.php?N=%20Results%20&T=15&A=separate&RT=0&Y=","1980","&R=-1&C=US", sep="")
years = seq(1980,2030,1)
urls = paste("http://www.census.gov/population/international/data/idb/region.php?N=%20Results%20&T=15&A=separate&RT=0&Y=",years,"&R=-1&C=US", sep="")
# INITIALIZING
dd <- readHTMLTable(urls[1],header=T, stringsAsFactors=F)[[1]]
x <- gsub(",", "", dd[dd$Age %in% c(18,19,20,21),3])
year <- dd[1,1]
@mittenchops
mittenchops / gist:11255681
Created April 24, 2014 14:01
emacs packages
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")
)
)
)
@mittenchops
mittenchops / randomspark.sh
Created April 21, 2014 15:51
random sparklines
$ for i in {1..100}; do echo $(($RANDOM/1000)); done | spark
@mittenchops
mittenchops / ma.py
Created April 15, 2014 14:00
Moving average from SO
http://stackoverflow.com/questions/21845124/python-simple-moving-average-class-based
@mittenchops
mittenchops / getfipsabbrev.py
Last active August 29, 2015 13:58
Get state FIPS codes from Gov
import requests
import bs4 as BeautifulSoup
def get_states():
page = requests.get("http://www.epa.gov/enviro/html/codes/state.html").content
soup = BeautifulSoup.BeautifulSoup(page)
def findstates(tr):
tds = tr.find_all('td')
for td in tds:
a = td.find_all("a")
@mittenchops
mittenchops / chunkit.py
Last active August 29, 2015 13:58
There are other ways of doing this, this is the one I used for where I was working with this for something that parallelized easily.
from __future__ import print_function
import numpy
import random
mylist = range(0,100)
random.shuffle(mylist)
myarray = numpy.array(mylist)
# via http://stackoverflow.com/questions/2130016/splitting-a-list-of-arbitrary-size-into-only-roughly-n-equal-parts
def chunkit(seq, N):
@mittenchops
mittenchops / amelia-test.R
Last active August 29, 2015 13:57
Testing Amelia for multiple imputation
# got some help here: http://stackoverflow.com/questions/22739070/function-of-a-list-of-data-frames-to-return-also-a-data-frame-in-r/
library(Amelia)
set.seed(1234)
myN <- 50
var1 <- runif(myN)
var2 <- 2*var1 + rnorm(myN, 0, 1)
var3 <- var1^2 + rnorm(myN, 0, 1)