Skip to content

Instantly share code, notes, and snippets.

@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: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 / 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:5172119
Created March 15, 2013 18:50
Broken Ti 3
!ENTRY org.eclipse.ui 4 0 2013-03-15 14:49:54.964
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at com.appcelerator.titanium.mobile.cli.nodejs.NodeIOSInfo.convertToLegacyMap(NodeIOSInfo.java:28)
at com.appcelerator.titanium.mobile.cli.nodejs.NodeIOSInfo.<init>(NodeIOSInfo.java:22)
at com.appcelerator.titanium.mobile.cli.nodejs.IOSNodeJSCommandsHelper.runPackagePrereqCheck(IOSNodeJSCommandsHelper.java:437)
at com.appcelerator.titanium.mobile.cli.nodejs.NodeTitaniumSDKCommandsHandler.runPackagePrereqCheck(NodeTitaniumSDKCommandsHandler.java:398)
at com.appcelerator.titanium.mobile.iphone.IOSConfigurationHelper.runPackagePrereqCheck(IOSConfigurationHelper.java:285)
at com.appcelerator.titanium.mobile.iphone.IOSConfiguration.refreshPrereq(IOSConfiguration.java:202)
@robheittman
robheittman / gist:4001253
Created November 2, 2012 12:59
Redlist startup on my machine
Macintosh-2:iucnredlistwebsite robheittman$ rvm gemset create redlist
'redlist' gemset created (/Users/robheittman/.rvm/gems/ruby-1.9.3-p125@redlist).
Macintosh-2:iucnredlistwebsite robheittman$ rvm gemset use redlist
Using /Users/robheittman/.rvm/gems/ruby-1.9.3-p125 with gemset redlist
Macintosh-2:iucnredlistwebsite robheittman$ gem install bundler
Fetching: bundler-1.2.1.gem (100%)
Successfully installed bundler-1.2.1
1 gem installed
Installing ri documentation for bundler-1.2.1...
Installing RDoc documentation for bundler-1.2.1...
@robheittman
robheittman / gist:2898176
Created June 8, 2012 21:23
Make a Mooyah
killall node; rm -rf olo-mooyah-build && git clone git@github.com:rfc2616/olo-restaurant-apps.git olo-mooyah-build && cd olo-mooyah-build && sh caffeine.sh
@robheittman
robheittman / gist:2763207
Created May 21, 2012 16:44
Static tables for Red List publish
vacuum analyze;
drop table if exists st_countryoccurrencesubfield_countryoccurrencelookup;
create table st_countryoccurrencesubfield_countryoccurrencelookup as select * from vw_published.vw_countryoccurrencesubfield_countryoccurrencelookup ;
drop table if exists st_countryoccurrencesubfield_presence;
create table st_countryoccurrencesubfield_presence as select * from vw_published.vw_countryoccurrencesubfield_presence;
drop table if exists st_countryoccurrencesubfield_origin;
create table st_countryoccurrencesubfield_origin as select * from vw_published.vw_countryoccurrencesubfield_origin;
DROP TABLE IF EXISTS st_countryoccurrence;
CREATE TABLE st_countryoccurrence AS
SELECT country.taxonid, country.assessmentid, country.value, country.recordid, record."CODE" as code, record."DESCRIPTION" as country, pres."LABEL" as presence, origin."LABEL" as origin
@robheittman
robheittman / gist:2719532
Created May 17, 2012 15:08
Looks like a RL CSV export
create table redlist_csv_export (species_id int,kingdom text,phylum text, class text, "order" text, family text, genus text, species text, authority text, infrarank text, infraname text, infraauth text, stock text, synonyms text, common_en text, common_fr text, common_sp text, redlist_status text, redlist_criteria text, redlist_criteria_version text, year text, trend text, petitioned text);
@robheittman
robheittman / mime_types.rb
Created January 13, 2012 02:59
Tell Rack about your static file types, too
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
# For now, the xlsx type is missing from Rack
Rack::Mime::MIME_TYPES.merge!({'.xlsx'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
@robheittman
robheittman / pg_error_encoding_issue.rb
Created January 1, 2012 18:58
Demonstrate an issue with encoding of error messages
Created database encoding_test_1325444057
Error message encoding is: ASCII-8BIT
#<Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT>
pg_issue.rb:17:in `rescue in <main>'
pg_issue.rb:7:in `<main>'
Dropped database encoding_test_1325444057