Skip to content

Instantly share code, notes, and snippets.

View pingles's full-sized avatar

Paul Ingles pingles

View GitHub Profile
@pingles
pingles / brew-doctor.txt
Created April 16, 2011 12:11
brew install emacs --cocoa
Your OS X is ripe for brewing.
Any troubles you may be experiencing are likely purely psychosomatic.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@pingles
pingles / protocols1.clj
Created April 18, 2011 19:21
Example taken from Clojure.org
(defprotocol P
(foo [x])
(bar-me [x] [x y]))
(deftype Foo [a b c]
P
(foo [x] a)
(bar-me [x] b)
(bar-me [x y] (+ c y)))
(defprotocol ToClojure
(to-clojure [x] "Convert hector types to Clojure data structures"))
(extend-protocol ToClojure
RowsImpl
(to-clojure [s]
(map to-clojure (iterator-seq (.iterator s))))
RowImpl
(to-clojure [s]
{:key (.getKey s)
@pingles
pingles / haproxy
Created May 3, 2011 18:39
Using HAProxy to balance Hive service requests across multiple backends
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 1000
daemon
user haproxy
group haproxy
defaults
log global
@pingles
pingles / 4clojure.clj
Created May 3, 2011 20:03
Working through some of the 4clojure.com examples
(ns four-clojure
(:use clojure.test))
(defn pen [coll]
(last (drop-last coll)))
(deftest penultimate-element
(is (= (pen (list 1 2 3 4 5)) 4))
(is (= (pen ["a" "b" "c"]) "b"))
(is (= (pen [[1 2] [3 4]]) [1 2])))
require 'rubygems'
require 'rbhive'
RBHive.connect('hive.server.address') do |connection|
connection.fetch 'SELECT * FROM cities'
end
# => [["London", "UK"], ["New York", "USA"], ["Mumbai", "India"]]
@pingles
pingles / hive1.conf
Created May 4, 2011 08:11
Hive upstart init script
start on runlevel [2345]
stop on runlevel [06]
respawn
script
export HOME="/home/deploy"
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
export HIVE_HOME="/usr/lib/hive"
export HADOOP_HOME="/usr/lib/hadoop"
@pingles
pingles / defnk.clj
Created May 4, 2011 19:38
Example using defnk to take optional params
(ns defnk-example
(:use [clojure.contrib.def :only (defnk)]))
(defnk some-fn
[x y :opt1 :a :opt2 :b]
(str "x: " x " opt1: " opt1 " opt2: " opt2))
defnk-example> (some-fn "x" "y" :opt1 5 :opt2 10)
"x: x opt1: 5 opt2: 10"
defnk-example> (some-fn "x" "y")
if @env['HTTPS'] == 'on'
'https'
elsif @env['HTTP_X_FORWARDED_SSL'] == 'on'
'https'
elsif @env['HTTP_X_FORWARDED_PROTO']
@env['HTTP_X_FORWARDED_PROTO'].split(',')[0]
else
@env["rack.url_scheme"]
end