Skip to content

Instantly share code, notes, and snippets.

Avatar

Brendan O'Connor brendano

View GitHub Profile
View r_sample_extension.cc
/////////////////////////////////////////
// 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:
View 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 Aug 14, 2008
imageopen - mac commandline
View imageopen.rb
#!/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
View htmlescape.pl
#!/usr/bin/env perl
while (<>) {
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
print $_;
}
View htmlunescape.pl
#!/usr/bin/env perl
while(<>) {
s/&lt;/</g;
s/&gt;/>/g;
s/&amp;/&/g;
print $_;
}
View 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
View mycgi.rb
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
View clean.rb
#!/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 Oct 8, 2008
blogger -> wordpress redirect code
View blogger.php
<?
/**
* *** 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 Oct 10, 2008
network connectivity troubleshooting...
View get.rb
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