Skip to content

Instantly share code, notes, and snippets.

@nwjsmith
nwjsmith / query_optim_core.clj
Last active May 31, 2016 14:42
A start on spec-ing Datomic queries
(ns query-optim.core
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.string :refer [starts-with?]]
[clojure.test.check.generators :as generators]))
(s/def ::query
(s/cat :find-spec ::find-spec
:with-clause (s/? ::with-clause)
@nwjsmith
nwjsmith / ancestors.sql
Created December 20, 2015 21:43
Recursive ancestors query for PostgreSQL
WITH RECURSIVE ancestors(id, name, created_at, updated_at) AS (
SELECT categories.id, categories.name, categories.created_at, categories.updated_at
FROM categories, categorizations
WHERE categorizations.subcategory_id = '667C9DF5-48C0-496B-922A-1B7D743B1A39'
AND categories.id = categorizations.category_id
UNION ALL
SELECT categories.id, categories.name, categories.created_at, categories.updated_at
FROM categories, categorizations, ancestors
WHERE categorizations.subcategory_id = ancestors.id
AND categories.id = categorizations.category_id
(ns categories.core
(:require [datomic.api :as d]))
(let [uri (str "datomic:mem://" (gensym))
conn (and (d/create-database uri) (d/connect uri))]
@(d/transact conn [{:db/id #db/id[:db.part/db]
:db/ident :category/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
(ns dropwarlock.reducers)
(defprotocol Reducee
(reduce-with-instructions [this inst f]))
(extend-protocol Reducee
clojure.lang.PersistentVector
(reduce-with-instructions [this [action acc] f]
(case action
:cont (if (empty? this)
@nwjsmith
nwjsmith / bugsnag_deploy.py
Created September 15, 2015 15:09
An Ansible Library for Bugsnag deploys
#!/usr/bin/env python
DOCUMENTATION = '''
---
module: bugsnag_deployment
short_description: Notifies Bugsnag of deploys.
options:
api_key:
description:
- The API Key associated with the project. Informs Bugsnag which project
@nwjsmith
nwjsmith / public_send_test.rb
Created May 14, 2015 20:20
Delegates can use `#public_send` even though they inherit from `BasicObject`
Run options: --seed 53381
# Running:
.
Finished in 0.000873s, 1145.2393 runs/s, 1145.2393 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
class Optional
private_class_method :new
def self.maybe(possible)
possible.nil? ? absent : of(possible)
end
def self.absent
None.new
end
require 'active_record'
require 'logger'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.connection.instance_eval do
create_table(:starting_goalies) do |t|
t.string :status
end
end
#!/bin/bash
set -e
cp previous.key intermediate.key
cp current.key previous.key
mv intermediate.key current.key
service nginx reload