Skip to content

Instantly share code, notes, and snippets.

@dpick
dpick / copy
Last active August 27, 2016 00:51
Clojure postgres copy table
(ns backfill-spike.core
(:require [byte-streams :as bs]
[clojure.java.jdbc :as jdbc]
[clojure.string :as string]
[clojure.java.io :as io]
[environ.core :refer [env]])
(import org.postgresql.copy.CopyManager)
(import org.postgresql.copy.PGCopyInputStream)
(import org.postgresql.util.PSQLException)
(import java.io.IOException)
def delete(value, node = @root)
return if node.nil?
if x < node.value
node.left = delete(x, node.left)
elsif x > node.value
node.right = delete(x, node.right)
else
if node.left.nil?
return node.right
bonus: Stealthed
ability_score:
primary: dexterity
secondary:
- strength
- charisma
powers:
cloud_of_steel:
name: Cloud Of Steel
type: at_will
@dpick
dpick / gist:5071762
Created March 2, 2013 16:17
Anonymous users with friend
(defn credential-fn [guid]
(if-let [user (persistence/find-user-by-guid guid)]
(assoc user :roles #{:fashion.server/user})))
(defn guid [request]
(if (empty? (:session request))
(let [user (persistence/create-user {:guid (java.util.UUID/randomUUID) :password (str (java.util.UUID/randomUUID))})]
(workflows/make-auth (assoc user :roles #{:fashion.server/user} :identity (:guid user)) {:cemerick.friend/workflow :guid}))
(let [user (persistence/find-user-by-guid (get-in request [:session :cemerick.friend/identity :current]))]
(when user
(defn find-user
[id]
{:id id})
@dpick
dpick / gist:4704719
Last active December 12, 2015 03:09
(time (map #(score %) (take 10000 (range 144115222435594240 149551225103187968))))
; "Elapsed time: 0.107 msecs"
(time (sort (map #(score %) (take 10000 (range 144115222435594240 149551225103187968)))))
; "Elapsed time: 672.586 msecs"
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open(ARGV[0]))
title = doc.css('title').first.content.scan(/\r\n\t(.*) -/).first
puts title
image = doc.css('img#imgPhoto').first.attributes['src'].value
(define minimize-interval-list
(lambda (ls)
(if (null? ls)
'()
(if (equal? (length ls) 1)
ls
(if (interval-intersects? (car ls) (cadr ls))
(minimize-interval-list (append (interval-union (car ls) (cadr ls)) (cddr ls)))
(cons (car ls) (minimize-interval-list (cdr ls))))))))
board = ["m", "w", "e", "t", "p", "e", "q", "i", "x", "a", "h", "v", "f", "f", "y", "j", "n", "l", "j", "h", "w", "c", "e", "s", "r"]
all_words = File.open('/usr/share/dict/words').readlines.map! { |line| line.strip.chomp }
valid_words = all_words.reject { |w| w =~ /[^#{board.join}]/ }
valid_words = valid_words.select do |w|
bool = true
bool = false if w.size <= 2
split_word = w.downcase.split('')
6 (defn everyo
7 "A pseudo-relation that takes a coll and ensures that the goal g
8 succeeds on every element of the collection."
9 [g coll]
10 (if (seq coll)
11 (all
12 (g (first coll))
13 (everyo g (next coll)))
14 s#))
15