Skip to content

Instantly share code, notes, and snippets.

@jmorton
jmorton / 01_setup.sh
Last active June 8, 2016 15:47
My LCMAP Setup Script [WIP]
## Preliminaries
apt-get install git curl
## Java
echo "Installing JDKs"
add-apt-repository ppa:webupd8team/java -y
apt-get update -qq
apt-get install oracle-java7-installer
@jmorton
jmorton / logger.clj
Created February 5, 2016 00:30
Setting log level example
(ns lcmap-data-clj.logger
(:require [clojure.logging.impl :as log-impl])
(:import [ch.qos.logback.classic Level]))
(comment "Usage example"
(set-level! 'lcmap-data-clj :debug)
(set-level! '[org.apache org.gdal] :info)
(set-level! '[com.datastax.driver co.paralleluniverse] :error))
@jmorton
jmorton / mailbag.rb
Last active December 18, 2015 03:59
require 'em-imap'
require 'logger'
require 'yaml'
#
# Watch IMAP mailboxes for messages and react however you like.
#
# Usage Example:
#
# Mailbag.run do |message|
@jmorton
jmorton / fizzerbuzzer.clj
Created January 11, 2013 16:28
I know it's silly....
(defn fizzer [n]
(if (= 0 (mod n 3)) "Fizz"))
(defn buzzer [n]
(if (= 0 (mod n 5)) "Buzz"))
(defn fizzerbuzzer [num]
(let [res [(fizzer num) (buzzer num)]]
(if (every? nil? res) num (apply str res))))
@jmorton
jmorton / augmenter.js
Created October 19, 2012 18:02
Augment yer DOM with Augmenter
/**
* Usage:
*
* <script src="augmenter.js" type="text/javascript"></script>
* <script>
* new Augmenter({ attr: 'data-employee', url: '/employee?id=' })
* </script>
*
* Any elements like this in your document:
*
@jmorton
jmorton / notifier.rb
Created October 12, 2012 14:28
Notifying with EventSource, Faye, EventMachine
require 'faye/websocket'
# Configuration:
#
# With rackup
# map '/notifier' do
# run Notifier.new
# end
#
# With Rails, add this to config/routes.rb
@jmorton
jmorton / accept.clj
Last active October 8, 2015 05:01
accept.clj
(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
(let [pattern #"([^;]+)\s*(?:;q=([0-9+\.]+))?\s*(;.+)*"
matches (re-find pattern str)
[_ media-range qvalue accept-extension] matches
quality (java.lang.Double/parseDouble (or qvalue "1"))]
(Accept. media-range quality accept-extension)))
@jmorton
jmorton / passive_record.rb
Created September 27, 2011 22:13
Passive Record
# PassiveRecord disables all of the mutable behaviors of a class that behaves like an ActiveRecord::Base
module PassiveRecord
module Base
extend ActiveSupport::Concern
module InstanceMethods
def passive_record_benign_method(*args, &block)
return false
end
end
$ du -sh .git
260K .git
@jmorton
jmorton / gist:983379
Created May 20, 2011 17:34 — forked from dhh/gist:981520
bulk api
# Bulk API design
#
# resources :posts
class PostsController < ApplicationController
before_filter :separate_bulk_ids
# GET /posts/1
# params[:id] => 1
# params[:ids] => [ 1 ]