Skip to content

Instantly share code, notes, and snippets.

source :rubygems
gem "aws-s3", :require => 'aws/s3'
@lstoll
lstoll / mongo.py
Created March 13, 2012 04:16
MongoHQ w/ pymongo on Heroku
import os
import pymongo
if os.environ['MONGOHQ_URL']:
# Get a connection
conn = pymongo.Connection(os.environ['MONGOHQ_URL'])
# Get the database
db = conn[urlparse(os.environ['MONGOHQ_URL']).path[1:]]
else:
@lstoll
lstoll / runpg.sh
Created March 14, 2012 14:45
Simple script to run an app local postgres instance
#!/bin/bash
PORT=5556
DB=gsv
if [ ! -d "db" ]; then
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
mkdir db
initdb db
postgres -D db -p $PORT &
PGPID=$!
@lstoll
lstoll / clojure.clj
Created March 19, 2012 11:50
Docstrings
$ clj
Clojure 1.3.0
user=> (defn fun "Docstring" [] ())
#'user/fun
user=> (meta (var fun))
{:arglists ([]), :ns #<Namespace user>, :name fun, :doc "Docstring", :line 4, :file "NO_SOURCE_PATH"}
user=>
@lstoll
lstoll / Play_job.md
Created March 26, 2012 01:58
Scheudling jobs on heroku with the play framework.

Jobs with the Play! Framework and Heroku

First thing, create a job that runs your task. Don't set a timer or anything on it, we will trigger it manually.

You will need to add two things to your app. First is an endpoint that uses authorisation (for your security) to trigger the job in the background. Something like this will do it:

public class JobEndpoint extends Controller{ 
    public static void runTheJob(){ 
        if( "jobuser".equals(request.username) && "jobpass".equals(request.password) ){ 

new WhateverYourJobClassIs().now();

@lstoll
lstoll / gist:2411499
Created April 18, 2012 06:41 — forked from lclarkmichalek/gist:1657284
Flymake mode for golang
(require 'flymake)
(defun flymake-go-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "go" (list "build" "-o" "/dev/null" temp-file))))
# On 10.7.3
/usr/bin/gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
@lstoll
lstoll / downloader.rb
Created April 30, 2012 03:34 — forked from chrisjm/s3-delete-bucket.rb
fork of s3-delete-files.rb -- Used for downloading a bucket with lots of files.
#!/usr/bin/env ruby
require 'rubygems'
require 'thread'
require 'fog'
# Ensure a bucket is specified
if ARGV.count < 4
raise "Specify a key, secret, bucket and output dir (eg ./downloader.rb key secret my-bucket '~/out')"
return
;; Totally untested, but should give an idea.
(ns mn
(:use lstoll.utils) ; https://github.com/lstoll/clj-utils
(:require [clj-http.client :as http])) ; https://github.com/dakrone/clj-http
(def test-concurrency 10)
(defn test-url
"Tests a URL, returning it's status code"
@lstoll
lstoll / gist:3039506
Created July 3, 2012 12:39
Wrapped Java API
;; Creates the wrapped object.
(def domain (JavaWrapper. (.domainLookupByID (conn "test:///default") 1))
;; Implements ILookup, so you can call getters by invoking a keyword
(:name domain) = (.getName domain)
;; Implements Associative, so you can invoke setters via assoc
(assoc domain autostart true) = (.setAutostart domain true)
;; Original Java object accessible via :o key