Skip to content

Instantly share code, notes, and snippets.

View jlehtoma's full-sized avatar

Joona Lehtomäki jlehtoma

View GitHub Profile
@jlehtoma
jlehtoma / vaaliraapija_spider.py
Created May 17, 2011 18:39
vaaliraapija_spider.py
info = data[0].select('.//tr//td/text()').extract()
# Sukunimi ja etunimi on erotettu pilkulla, erottele nimet
names = info[0].split(',')
# Poistetaan välilyönnit nimistä
names = [name.strip() for name in names]
@jlehtoma
jlehtoma / items.py
Created May 17, 2011 18:41
items.py
puolue = Field()
puolue_lyh = Field()
etunimi = Field()
sukunimi = Field()
ammatti = Field()
kunta = Field()
vaalipiiri = Field()
@jlehtoma
jlehtoma / wms_proto.R
Created November 13, 2011 20:01
Prototype for accessing WMS from R
# Author: Joona Lehtomäki <[email protected]>
# Updated: 13.11.2011
# Version: 0.0.1
if (!require("rgdal")) {
install.packages("rgdal")
}
if (!require("raster")) {
install.packages("raster")
@jlehtoma
jlehtoma / plot_squares_example.R
Created November 29, 2011 14:40
R plotting with colorful squares
# Create some data
# Notice that all data is bound to specific range, you will have to adjust the
# polygon coordinates, the empty plot xlim/ylim and ablines according to your
# real data
# Polygon xy coordinates
x1 <- c(0, 2, 2, 0)
y1 <- c(2, 2, 0, 0)
@jlehtoma
jlehtoma / gist:1513613
Created December 23, 2011 08:47
Fetch Twitter archive from Twapperkeeper and preprocess and visualize content
require(stringr)
#A helper function to remove @ symbols from user names...
trim <- function (x) sub('@','',x)
twapperkeeperCSVParse=function(fp){
df = read.csv(fp, header=F)
df$from=sapply(df$V1,function(tweet) str_extract(tweet,"^([[:alnum:]_]*)"))
df$id=sapply(df$V1,function(tweet) str_extract(tweet,"[[:digit:]/s]*$"))
df$txt=sapply(df$V1,function(tweet) str_trim(str_replace(str_sub(str_replace(tweet,'- tweet id [[:digit:]/s]*$',''),end=-35),"^([[:alnum:]_]*:)",'')))
@jlehtoma
jlehtoma / gist:1554016
Created January 3, 2012 08:06
ggplot2, levels and legend
library(ggplot2)
data <- data.frame('Puolue'=factor(c('A', 'B', 'C')),
'Kannatus'=c(4, 6, 8))
p <- ggplot(data, aes(fill=Puolue, y=Kannatus, x=rev(Puolue)))
p + geom_bar(stat="identity") +
scale_x_discrete(breaks=data$Puolue, labels=rev(data$Puolue)) + coord_flip()
@jlehtoma
jlehtoma / gitcopy.py
Created January 9, 2012 20:45
GitCopy
#!/usr/bin/python
# coding=utf-8
from optparse import OptionParser
import os
import shutil
import sys
# Install GitPython (tested with 0.3.2.RC1)
# > easy_install GitPython
@jlehtoma
jlehtoma / melt_boxplot.R
Created January 27, 2012 17:04
Melt + Boxplot
library(reshape)
pop <- c("P","P","M","M")
C <- c(5,3,6,2)
Pr <- c(6,5,1,4)
Fr <- c(4,5,1,1)
Gr <- c(9,4,2,8)
mydata <- data.frame(pop=pop, C=C, Pr=Pr, Fr=Fr, Gr=Gr)
mdata <- melt(mydata, id=c("pop"))
@jlehtoma
jlehtoma / post-commit
Created February 2, 2012 21:38
soRvi-dev post-commit hook
#!/usr/bin/env python
# This goes to GIT_ROOT/.git/hooks
import os
import shutil
import sys
from ConfigParser import NoSectionError
try:
@jlehtoma
jlehtoma / config
Created February 2, 2012 21:40
soRvi-dev svn-mirror config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:louhos/soRvi-dev.git
[branch "master"]
remote = origin