Skip to content

Instantly share code, notes, and snippets.

(ns accept.core)
;; Content Type matters in a REST API.
(defrecord Accept [media-range quality accept-extension])
(defn accept [str]
"Parse a single accept string into a map"
; according to RFC2616, the "q" parameter must precede the accept-extension
@jmorton
jmorton / _katas.markdown
Last active August 29, 2015 14:18
My Clojure Katas

Counting Words

Get:

  • Ten most frequently occurring non-stop words in a text file (including how often they occur).
  • Alphabetized list of words occurring exactly three times.

Considerations:

  • Stop words
  • Stemming
  • Laziness
(ns shokunin.euler)
;; sum of multiples of 3 and 5 < 1000
;; https://projecteuler.net/problem=1
(defn multiple-seq [n]
(iterate (partial + n) n))
(let [x3 (take-while #(< % 1000) (multiple-seq 3))
x5 (take-while #(< % 1000) (multiple-seq 5))
@jmorton
jmorton / extents.py
Created May 15, 2015 19:17
Get extents from a scene (padded my 900m)
""" Moo.
"""
import gdal
import osr
import math
import subprocess
import time
class Task < ActiveRecord::Base
include Encoder
code :status do
Status::New = "N"
Status::Pending = "P"
Status::Finished = "F"
Status::OverDue = "O"
end
require 'rubygems'
require 'active_support'
class Foo
def talk(arg)
puts "talking about '#{arg}'"
end
end
class Bar
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
def localhost
reverse_lookup "127.0.0.1"
end
@jmorton
jmorton / github_require.rb
Created April 29, 2010 16:17
Load and evaluate gists
def gitget(uri)
# We look for very specific links within the page like:
# <a href="/raw/383785/5bcefcae03bbc40d6ce40591d93f278585e47950/example.rb">raw</a>
raw_uri_pattern = /\<a href="(.+)"\>raw\<\/a\>/
begin
# Load the referenced gist
gist_html = open(uri).read
# Playing with Thrift, Hbase, and Ruby (I created a table and added some values using Hbase shell earlier)
irb > transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost',9090))
=> #<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=nil, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">
irb > transport.open
=> #<Socket:0x10196a030>
irb > protocol = Thrift::BinaryProtocol.new(transport)
=> #<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=#<Socket:0x10196a030>, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">, @strict_write=true>
irb > client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
=> #<Apache::Hadoop::Hbase::Thrift::Hbase::Client:0x10195d448 @seqid=0, @oprot=#<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::Bu