This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def coins [2 1 1 0.5 0.5 0.2 0.2 0.2 0.1 0.05 0.05 0.02 0.02 0.01 0.01]) | |
(defn square [x] | |
(* x x)) | |
(defn distance | |
[x y] | |
(square (- x y))) | |
(defn fix-coin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyquery import PyQuery | |
from AlchemyAPI import AlchemyAPI | |
from itertools import ifilter | |
import re | |
import lxml | |
url="http://www.kenyalaw.org/klr/index.php?id=441" | |
ao=AlchemyAPI() | |
ao.loadAPIKey("api-key.txt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scraperwiki | |
import itertools, re, csv | |
import lxml | |
# Configuration - file name and ranges for boys/girls here | |
filename="/home/mihi/Downloads/VN2p_2012.pdf" | |
# page numbers for boy and girl names | |
range_boys=[0,20] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "Scraping a PDF with Scraperwikis PDFtoXML" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(RCurl) | |
require(rjson) | |
topsuppl<-function (dataset,drilldown,year,q=c(0.75,0.9,0.99,0.999)) { | |
url=paste("http://openspending.org/api/2/aggregate?dataset=",dataset,"&cut=time.year:",year,"&drilldown | |
=",drilldown,sep="") | |
j=getURL(url) | |
data=fromJSON(j) | |
amounts<-as.vector(sapply(data$drilldown,function(x) { return (x$amount[[1]]) })) | |
labels<-as.vector(sapply(data$drilldown,function(x) { return (x$to$label) })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
turtles-own [xc xn] | |
to setup | |
;; (for this model to work with NetLogo's new plotting features, | |
;; __clear-all-and-reset-ticks should be replaced with clear-all at | |
;; the beginning of your setup procedure and reset-ticks at the end | |
;; of the procedure.) | |
;;__clear-all-and-reset-ticks | |
clear-all | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Formulas for Z scores | |
zscore <- function (d) { | |
return ((d-mean(d))/sd(d)) | |
} | |
# Read in data | |
d <- read.csv("Cleaned-20131016-1525.csv") | |
# The parties we want to use | |
parties<-colnames(d)[c(6,8,9,10,11,12,13,14,15,16)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Zero Pad a number in Javascript | |
// Takes e.g. zp(42,5) -> "00042" | |
var zp = function(n,c) { | |
var s = String(n); | |
if (s.length< c) { return zp("0" + n,c) } | |
else { return s } }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn zp "Zero Pad numbers - takes a number and the length to pad to as arguments" | |
[n c] | |
(loop [s (str n)] | |
(if (< (.length s) c) | |
(recur (str "0" s)) | |
s))) |