Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
(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 / _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 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 / Dockerfile
Last active March 27, 2019 08:31
Install Python 3.4.2 + mod_wsgi on CentOS
FROM centos:centos6
MAINTAINER jmorton@usgs.gov
# Apache
RUN yum install -y httpd httpd-devel
RUN chkconfig httpd on
RUN apachectl start
# Dependencies
RUN yum groupinstall -y "Development tools"
@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:
*