Skip to content

Instantly share code, notes, and snippets.

@statonjr
statonjr / remote.rake
Last active August 29, 2015 13:56
Rails hack for using databases running in a virtual machine
# Rails only allows databases local to your machine. If you run your databases in a VM
# (and you should), then you need to add this
namespace :db do
def local_database?(config, &block)
if config['host'].in?(['127.0.0.1', 'localhost', '172.16.12.102']) || config['host'].blank?
yield
else
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
end
@statonjr
statonjr / normalizer.clj
Last active December 31, 2015 08:09
Datomic/Immutant Error. ClassNotFoundException: com.amazonaws.retry.RetryPolicy
07:16:13,507 ERROR [immutant.runtime] (pool-15-thread-1) Unexpected error occurred loading immutant.init #<ExceptionInInitializerError java.lang.ExceptionInInitializerError>
07:16:13,508 ERROR [org.jboss.msc.service.fail] (pool-15-thread-1) MSC00001: Failed to start service jboss.deployment.unit."charon.clj".immutant.core.application-initializer: org.jboss.msc.service.StartException in service jboss.deployment.unit."charon.clj".immutant.core.application-initializer: java.lang.ExceptionInInitializerError
at org.projectodd.polyglot.core.AsyncService$1.run(AsyncService.java:52) [polyglot-core.jar:1.x.incremental.61]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_25]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
@statonjr
statonjr / datomic.clj
Last active December 30, 2015 08:38
Datomic helpers
(ns com.larrystaton.datomic
(:require [datomic.api :as d]))
;; (find-entity-id :person/name "Larry Staton" (d/db conn))
(defn find-entity-id
"Query Datomic for the entity ID with ATTR and VAL in DBVAL"
[attr val dbval]
(ffirst
(d/q '[:find ?e
:in $ ?a ?v
@statonjr
statonjr / crossword.tex
Last active December 30, 2015 05:09
A XeTeX crossword for Alexander's social studies project.
\documentclass[12pt]{article}
\usepackage[unboxed]{cwpuzzle}
\pagestyle{empty}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Scale=MatchLowercase,Mapping=tex-text]{HelveticaNeue}
\begin{document}
@statonjr
statonjr / gist:7719838
Created November 30, 2013 14:38
Slamhound error
$ lein slamhound src/charon/tasks/import_stuff.clj
Can't find 'slam.hound' as .class or .clj for lein run: please check the spelling.
Exception in thread "main" java.io.FileNotFoundException: Could not locate slam/hound__init.class or slam/hound.clj on classpath:
at clojure.lang.RT.load(RT.java:443)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5018.invoke(core.clj:5530)
at clojure.core$load.doInvoke(core.clj:5529)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5336)
at clojure.core$load_lib$fn__4967.invoke(core.clj:5375)
@statonjr
statonjr / gist:7610108
Created November 23, 2013 02:42
Command-line Hypermedia client using cURL, jsontool, and GNU parallel
curl -s http://www.youtypeitwepostit.com/api/ | json -a collection.items | json -a href | parallel curl -s {}
@statonjr
statonjr / gist:7609635
Created November 23, 2013 01:30
YouTypeItWePostIt GET representation
λ curl -v -H 'Accept: application/vnd.collection+json' http://www.youtypeitwepostit.com/api/
* About to connect() to www.youtypeitwepostit.com port 80 (#0)
* Trying 50.17.185.176...
* Connected to www.youtypeitwepostit.com (50.17.185.176) port 80 (#0)
> GET /api/ HTTP/1.1
> User-Agent: curl/7.33.0
> Host: www.youtypeitwepostit.com
> Accept-Encoding: deflate, gzip
> Accept: application/vnd.collection+json
>
@statonjr
statonjr / dealerships_resource.rb
Last active December 23, 2015 22:39
Musings on an API
class DealershipsResource < Webmachine::Resource
def encodings_provided
{"gzip" => :encode_gzip, "identity" => :encode_identity}
end
def allowed_methods
%W[GET]
end
require 'rubygems'
require 'mechanize'
FIRST_NAME = 'FIRST_NAME'
LAST_NAME = 'LAST_NAME'
PHONE = 'PHONE'
EMAIL = 'EMAIL@provider.com'
PARTY_SIZE = 2
SCHEDULE_RANGE = { :start_time => '19:00', :end_time => '20:30' }
@statonjr
statonjr / gist:6092758
Last active December 20, 2015 07:19
Calca example

mass of moon = 73.483E+21 kg

mass = 3,000 kg

mass of moon * mass => 22.0449e25kg^2