Skip to content

Instantly share code, notes, and snippets.

View AABoyles's full-sized avatar

Tony Boyles AABoyles

View GitHub Profile
@gluc
gluc / app.R
Last active November 23, 2022 10:14
Shiny CRUD
library(shiny)
library(shinyjs)
# Get table metadata. For now, just the fields
# Further development: also define field types
# and create inputs generically
GetTableMetadata <- function() {
fields <- c(id = "Id",
@andybega
andybega / archigos-polity.r
Created December 15, 2014 11:32
Descriptive look at Archigos leader entry/exit and tenure length for different regime types, using the Polity IV data and scheme for the latter.
# Archigos transitions and tenure by regime type
#
# Andreas Beger
# 15 December 2014
setwd("~/Desktop/archigos-polity")
library(foreign)
library(gdata)
@tomhopper
tomhopper / PRESS.R
Last active November 6, 2022 00:46
Functions that return the PRESS statistic (predictive residual sum of squares) and predictive r-squared for a linear model (class lm) in R
#' @title PRESS
#' @author Thomas Hopper
#' @description Returns the PRESS statistic (predictive residual sum of squares).
#' Useful for evaluating predictive power of regression models.
#' @param linear.model A linear regression model (class 'lm'). Required.
#'
PRESS <- function(linear.model) {
#' calculate the predictive residuals
pr <- residuals(linear.model)/(1-lm.influence(linear.model)$hat)
#' calculate the PRESS
@AABoyles
AABoyles / table2CSV.js
Last active December 27, 2015 12:29
*Don't use this Gist!* If you're looking to work with CSVs in Javascript, give [Tabular.js](http://aaboyles.com/Tabular.js/) a try. It was designed after this gist to provide a more complete solution to CSV handling in Javascript. Given a table element (or jQuery-selected table), returns a string which can be used as download URL for the table i…
function table2CSV(table, delim){
var csv = "data:application/csv;charset=utf-8,";
if(table instanceof HTMLElement){
table = $(table);
}
if(table instanceof jQuery){
var regex = /,/g;
if(delim){
regex = new RegExp(delim, 'g');
delim = encodeURIComponent(delim);
@AABoyles
AABoyles / jquery.spin.js
Last active December 16, 2015 07:29 — forked from tsgautier/jquery.spin.js
A simpler, slightly more efficient, less customizable jQuery Spinner plugin.
/*
You can create a spinner using either of the variants below:
$("#el").spin(true); //Starts the spinner.
$("#el").spin(false); // Kills the spinner.
*/
(function($) {
$.fn.spin = function(opts) {
@xmarquez
xmarquez / List-of-variables-ccp.csv
Last active December 12, 2015 09:39
Code for post on the Normativeness of Democracy
variable Question
cowcode Correlates of War country code (www.correlatesofwar.org).
country Country name.
systyear Year in which the constitutional system was promulgated.
systid Unique identification number for the constitutional system.
evntyear Year of promulgation of the most recent constitutional event.
endyear Year through which the data for the event is guaranteed valid.
evntid Unique identification number for the constitutional event.
evnttype Event type (e.g. amendment, new, etc.).
source What is the source for the text of the Constitution?
@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;
@drewconway
drewconway / noticeEMail.py
Created April 12, 2011 20:42
Sends an email message through GMail once the script is completed. Developed to be used with AWS (or other system) so that instances can be terminated once a long job is done. Only works for those with GMail accounts.
#!/usr/bin/env python
# encoding: utf-8
import smtplib
from datetime import datetime
def noticeEMail(starttime, usr, psw, fromaddr, toaddr):
"""
Sends an email message through GMail once the script is completed.