Skip to content

Instantly share code, notes, and snippets.

@danneu
danneu / 1-db.clj
Last active August 29, 2015 13:56
My Datomic boilerplate. (resources/schema.edn, resources/data-functions.edn, src/xxx/db.clj)
(ns xxx.db
(:require [clojure.java.io :as io]
[clojure.string :as str]
[datomic.api :as d])
(:import [datomic Util]
[java.util Date]))
;; Datomic utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn read-all
@danneu
danneu / core.clj
Last active August 29, 2015 14:00
Crazy vs. Psychic
(ns casino.core)
;; Strategies ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; A strategy is a function applied to a sequence of turns.
(defn crazy-strat1
"Random pick."
[_]
(rand-nth [true false]))
(ns mud.sandbox
(:require [schema.core :as s]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.set :as set]
[mud.ansi :as ansi])
(:import [java.net ServerSocket]
[java.io PrintWriter]))
(defn prompt
@danneu
danneu / hangman.clj
Last active August 29, 2015 14:02
my friend next to me at this coffee shop is learning python http://inventwithpython.com/chapter9.html
(ns scratch.hangman
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
(def hangman-frames
(str/split
(slurp (io/resource "data/hangmen.txt"))
#"\n\n"))
(ns daily.ch-163-fallout-hacking-game
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
(def all-words
"The entire dictionary of available words."
(str/split-lines (slurp (io/resource "enable1.txt"))))
(defn word-difference
@danneu
danneu / 0-reset-and-init-db.sql
Last active August 29, 2015 14:02
heroku db-spec -- the :sslmode/:ssl/:sslfactory trifecta were necessary for me to let my laptop connect to my remote heroku postgres db.
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users (
id serial PRIMARY KEY,
uname text NOT NULL UNIQUE,
digest text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
(ns drugcritic.slug
(:require [clojure.string :as str]))
;;Stop at '-<number>'
;;Stop at '.'
;;Stop at <number>
;;Stop at 'and'
;;Stop at ';'
;;Stop at '('
;;Stop at 'preservative free'

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
main :: IO ()
main = do
runGame []
runGame :: [Integer] -> IO ()
runGame nums = do
putStrLn "Give me a number (or 0 to stop):"
inputStr <- getLine
let inputNum = (read inputStr) :: Integer
if inputNum == 0
RestClient.post("http://localhost:3000/lol",
{:id => "peat", :label => "Peat Bakke", :attributes => [{:for => "attribute_name", :value => 1}, {:for => "something_else", :value => "wee"}]}.to_json,
:content_type => :json)