Skip to content

Instantly share code, notes, and snippets.

View brendano's full-sized avatar

Brendan O'Connor brendano

View GitHub Profile
/////////////////////////////////////////
// Sample for Embedding C++ into R //
/////////////////////////////////////////
//
// I keep forgetting how to do this so here's an example.
// If you're willing to use R's most primitive FFI interface,
// things are incredibly simple and easy to get going.
// -Brendan O'Connor (brenocon@gmail.com)
//
// Compile with, e.g. on mac:
@brendano
brendano / jsontidy
Created August 12, 2008 00:20
jsontidy
#!/usr/bin/env ruby
# jsontidy
# POSSIBLE USAGE
# [[Shell]] cat data.json | jsontidy
# [[TextMate]] Cmd-A Cmd-Opt-R jsontidy
# [[Vim] :%!jsontidy
# alternate implementation: python -m simplejson.tool
@brendano
brendano / imageopen.rb
Created August 14, 2008 02:09
imageopen - mac commandline
#!/usr/bin/env ruby
# imageopen - # for mac, commandline open an image file without needing an extension, recognition via imagemagick
# brenocon@gmail.com (brendan o'connor)
require 'fileutils'
f = ARGV[0]
type = %x[identify #{f}].split[1].downcase
@brendano
brendano / htmlescape.pl
Created August 14, 2008 02:12
htmlescape
#!/usr/bin/env perl
while (<>) {
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
print $_;
}
@brendano
brendano / htmlunescape.pl
Created August 14, 2008 02:13
htmlunescape
#!/usr/bin/env perl
while(<>) {
s/&lt;/</g;
s/&gt;/>/g;
s/&amp;/&/g;
print $_;
}
@brendano
brendano / pskill
Created August 14, 2008 08:38
pskill
#!/usr/bin/env ruby
# USAGE: ps wwaux | grep badprocess | pskill
# Like awk '{print $2}' | xargs kill, except somewhat smarter
class Array
def map_if(&b)
map(&b).select{|x| x}
end
end
@brendano
brendano / mycgi.rb
Created August 16, 2008 00:25
mycgi
require 'cgi'
# trying to make cgi.rb suck a tad bit less.
# the main thing I care about is clean, error-free parameter input.
# brendan o'connor (brenocon@gmail.com)
class MyCGI < CGI
def initialize
super("html3")
@converted_opts = {}
end
#!/usr/bin/env ruby
# Parse a data table from pollster.com
# Get data via copy-and-paste from http://www.pollster.com/polls/us/08-us-pres-ge-mvo.php
# yields a messy tab-separated thingamajigger (i'm using firefox 3 on mac)
# This script normalizes, in an R-friendly way
require 'date'
def numclean(x)
x =~ /^-$/ ? "NA" : x.to_i
@brendano
brendano / blogger.php
Created October 8, 2008 21:03
blogger -> wordpress redirect code
<?
/**
* *** THIS NEEDS TO BE EDITED FOR A NEW INSTALLATION ***
*
* this is supposed to be called as e.g.
* http://anyall.org/blog/blogger/http://socialscienceplusplus.blogspot.com/2008/10/mydebatesorg-and-poten
tially-coolest.html
* and then redirect to e.g.
* http://anyall.org/blog/2008/10/mydebatesorg-online-polling-and-potentially-the-coolest-question-corpus-
ever/
@brendano
brendano / get.rb
Created October 10, 2008 08:03
network connectivity troubleshooting...
load '~/.irbrc' # dotfiles.org/~brendano/.irbrc
require 'hpricot'
sites=[]
for url in [
"http://www.alexa.com/site/ds/top_sites?ts_mode=lang〈=en"]
h = Hpricot open(url).read
sites += (h/'h3'/'a').map{|x| x['href']}
end