Skip to content

Instantly share code, notes, and snippets.

@AABoyles
AABoyles / getPackage.R
Last active December 11, 2015 07:29
A simple, reliable, string-based package loader for packages on CRAN.
getPackage <- function(pkg){
if(!require(pkg, character.only=TRUE)){
install.packages(pkg, dependencies=TRUE)
library(pkg, character.only=TRUE)
}
return(TRUE)
}
getPackages <- function(pkgs){
for (pkg in pkgs){
@AABoyles
AABoyles / html2txt.py
Created October 5, 2012 20:54
Turn HTML files into text files
import nltk, glob
for filename in glob.glob( '*.htm*' ):
filein = open(filename)
html = filein.read()
raw = nltk.clean_html(html)
fileout = open(filename.rstrip('.html')+'.txt', 'w+')
fileout.write(raw)
@AABoyles
AABoyles / makeExt.php
Created October 4, 2012 16:02
Quick-creator for MediaWiki Extensions. Creates a project directory, main file, body file, and internationalization file, all adhering to the standards of extension design described in http://www.mediawiki.org/wiki/Manual:Developing_extensions
<?php
class makeExt{
protected $project = "<project>";
protected $name = "<you>";
protected $desc = "<insert a short description here>";
public function __construct(){
global $argv, $argc;
@AABoyles
AABoyles / RPolityHeatmap.R
Created October 3, 2012 05:08
R Script to create an Animated Gif of Polity Heatmap
## 213 YEARS OF POLITICAL EVOLUTION IN 60 SECONDS v4
# Created:
## Jay Ulfelder
## October 1, 2012
# Modified:
## Tony Boyles[[email protected]]
## March 20, 2014
@AABoyles
AABoyles / Stata2CSV.R
Created June 3, 2011 21:20
Converts a Stata .DTA file to a Comma-separated variable file
library(foreign)
write.table(read.dta(file.choose()), file="output.csv", quote = FALSE, sep = ",")
@AABoyles
AABoyles / laggr.R
Last active September 25, 2015 04:08
Returns a Vector x lagged by y steps
laggr <- function(x,y){return(c(rep(NA, y),x[-((length(x)-y+1):length(x))]))}