Skip to content

Instantly share code, notes, and snippets.

@robheittman
robheittman / gist:654288
Created October 29, 2010 20:00
Ruby snippet in PostLaunch #1
you = $GoGoEgo.getPlugin("Identity").getId
if you == nil then
$document.write "Please <a href='/portals'>log in</a> to use this page."
else
mode = you[-2,2]
you = you[0..-2]
if you != $base.getCollectionID and mode != "+a" then
$document.write <<-END
Your account is not allowed to use this page.
@robheittman
robheittman / reptilescan.rb
Created November 11, 2010 21:02
Copies assessments from an old working set to a new working set
require 'rubygems'
require 'find'
require 'rainbow'
require 'nokogiri'
require 'fileutils'
def lsl (dir)
Find.find dir do |path|
if File.directory?(path)
next
@robheittman
robheittman / api_index.sql
Created November 13, 2010 20:35
View for Red List API Index
create view api_index as
select
CASE WHEN y.infra_rank is null THEN
y.genus_name || ' ' || y.species_name
ELSE
trim(trailing from y.genus_name || ' ' || y.species_name || ' ' || y.infra_rank || ' ' || y.infra_name)
END as scientific_name,
not(is_synonym) as primary,
class_name as class,
order_name as order,
@robheittman
robheittman / how-threatened-is.html
Created November 14, 2010 04:39
Examples of consuming the IUCN Red List HTML5 API
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
function check(){
var species = $('#how_threatened_is').get(0).value;
species = species.replace(' ','-');
$.ajax({
dataType: "jsonp",
url: 'http://api.iucnredlist.org/index/species/'+species+".js",
@robheittman
robheittman / gist:701288
Created November 16, 2010 01:26
Resource streaming status trick
// Inside a Restlet Resource's represent(...) method
PipedInputStream pi = new PipedInputStream();
PipedOutputStream po = new PipedOutputStream(pi);
Representation ir = new OutputRepresentation(MediaType.TEXT_PLAIN){
@Override
public void write(OutputStream realOutput) throws IOException {
byte[] b = new byte[8];
int read;
while ((read = pi.read(b)) != -1) {
@robheittman
robheittman / google_doc_style_builder.rb
Created December 7, 2010 07:37
Overrides Formtastic::SemanticFormBuilder to render hints below labels like Google Docs Forms. It's really a 3-line patch, but we need to override three whole methods to get the effect.
class GoogleDocStyleBuilder < Formtastic::SemanticFormBuilder
# Overrides the input generator to suppress the normal hint
# Track source: https://github.com/justinfrench/formtastic/raw/master/lib/formtastic.rb
def input(method, options = {})
options[:required] = method_required?(method) unless options.key?(:required)
options[:as] ||= default_input_type(method, options)
html_class = [ options[:as], (options[:required] ? :required : :optional) ]
html_class << 'error' if has_errors?(method, options)
@robheittman
robheittman / gist:734023
Created December 8, 2010 22:19
Stuff a Zerigo Ubuntu 10.04 LTS server needs
sudo apt-get install python-software-properties
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install sun-java6-jdk
apt-get install git-core
apt-get install ntp
apt-get install vim
module Jekyll
require 'haml'
class HamlConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /haml/i
end
@robheittman
robheittman / jsforms.md
Created January 3, 2011 21:50
Javascript anti-form-spam recipe

This recipe puts a trivial speed bump in the way of form spammers. By forcing them to actually evaluate the page with a Javascript engine (or do extra processing to figure out what is needed), you raise the amount of effort required above that which most form spammers are likely to spend.

Step 1

Pick a nice random number. The SHA1 of some Git commit would be a good one. I picked this one:

5187b6aec9b0607858a7c032d2c9ded04b050f31

Step 2

@robheittman
robheittman / gist:768524
Created January 6, 2011 20:34
A .bashrc on Ubuntu with rvm support
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
if [[ -n "$PS1" ]] ; then
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace