Skip to content

Instantly share code, notes, and snippets.

View mikeflynn's full-sized avatar
🥪
A little hungry, but overall OK.

Mike Flynn mikeflynn

🥪
A little hungry, but overall OK.
View GitHub Profile
@rcampbell
rcampbell / s3.clj
Created May 11, 2011 10:14
Storing and retrieving Clojure data structures as GZIP compressed JSON in Amazon S3
(ns aws.s3
(:refer-clojure :exclude [get])
(:use [clojure.walk :only (keywordize-keys stringify-keys)]
[clojure.contrib.def :only (defonce-)]
[clojure.contrib.json :only (read-json write-json)])
(:import [java.io PrintWriter InputStreamReader ByteArrayInputStream ByteArrayOutputStream]
[java.util.zip GZIPInputStream GZIPOutputStream]
[com.google.common.base Charsets]
[com.amazonaws.services.s3 AmazonS3Client]
[com.amazonaws.services.s3.model Region CreateBucketRequest ObjectMetadata
function toJSON(object) {
var json = new Array();
for(var index in object) {
type = typeof(object[index]);
if(type == 'object'){
json.push('"'+index+'":' + toJSON(object[index]));
} else if(type == 'string') {
json.push('"'+index+'":' + '"'+object[index].replace(/\"/g,'\\"')+'"');
} else if(type == 'boolean' || type == 'number') {
json.push('"'+index+'":' +object[index]);
@woods
woods / tinyurl.rb
Created April 11, 2009 15:43
A complete URL-shortening web application, written in Ruby/Sinatra.
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application