Skip to content

Instantly share code, notes, and snippets.

View devstopfix's full-sized avatar

James Every devstopfix

View GitHub Profile
@devstopfix
devstopfix / evt_refs.clj
Last active March 2, 2017 15:43
Generate EVRYTHNG Refs for example data
; lein try org.clojure/test.check
(require '[clojure.test.check.generators :as gen])
;"abcdefghkmnpqrstwxyABCDEFGHKMNPQRSTUVWXY23456789"
(def prefix-u (partial into ["U"]))
(def chars-to-str (partial apply str))
@devstopfix
devstopfix / dinosaurs.cljs
Created January 3, 2017 21:30
Dinosaur names - Planck
(ns words
(:require [planck.core :refer [slurp]]
[clojure.string :refer [split-lines upper-case]]))
(def dinosaurs
(->> "/usr/share/dict/words"
(slurp)
(split-lines)
(map upper-case)
(filter #(re-find #"AURUS$" %))))
@devstopfix
devstopfix / get-json.cljs
Created December 17, 2016 15:12
ClojureScript/Planck HTTP GET as json
(require 'goog.json)
(->
(get "https://www.reddit.com/r/clojure/top/.json?count=20")
(:body)
(goog.json/parse)
(js->clj))
@devstopfix
devstopfix / binary.clj
Created December 15, 2016 20:36
Zuhlke UK coding night - parse binary string
(ns zuhlke.codingnight.binary)
;
; Coding night challenge - Binary
; Convert string of binary digits to int
;
(defn binary-str-to-int [s]
(loop [s (reverse s)
acc 0
pwr 1]
@devstopfix
devstopfix / scrabble.cljs
Created December 14, 2016 22:44
Zuhlke UK Coding Night - Scrabble word score in ClojureScript
#!/usr/bin/env planck
;
; Coding night challenge - Scrabble
; Generate a rack of tiles and find highest scoring word
;
; Written in ClojureScript running on Planck
; http://planck-repl.org/guide-all.html
;
; To run on OS X:
@devstopfix
devstopfix / midpoint-circle-algorithm.clj
Created August 18, 2016 13:59
Midpoint Circle Algorithm (Bresenham)
; https://en.wikipedia.org/wiki/Midpoint_circle_algorithm
(defn mirror-point [x0 y0 x y]
[[(+ x0 x) (+ y0 y)]
[(+ x0 y) (+ y0 x)]
[(- x0 y) (+ y0 x)]
[(- x0 x) (+ y0 y)]
[(- x0 x) (- y0 y)]
[(- x0 y) (- y0 x)]
[(+ x0 y) (- y0 x)]
; Neo4J CREATE
(defn- format-props [props]
"Format a map of {:symbol String} to Cypher format"
(->>
props
seq
(map (fn [[k v]] (format "%s: %s" (name k) (pr-str v))))
(clojure.string/join ", ")))
module RomanNumeral exposing (numeral_to_number)
type Digit = I | V | X | L | C | D | M
value : Digit -> number
value d =
case d of
I -> 1
V -> 5
defmodule RomanNumerals do
# Roman Numerals (Elixir)
@digits %{"I" => 1,
"V" => 5,
"X" => 10,
"L" => 50,
"C" => 100,
"D" => 500,
"M" => 1000}
@devstopfix
devstopfix / planets.clj
Created October 26, 2015 20:42
Elite planet names generated by Clojure's test.check generators
(require '[clojure.test.check.generators :as gen])
; Elite planet name letter pairs (http://www.iancgbell.clara.net/elite/text/index.htm)
(def pair (gen/elements [[ ] [\L \E] [\X \E] [\G \E] [\Z \A] [\C \E] [\B \I] [\S \O]
[\U \S] [\E \S] [\A \R] [\M \A] [\I \N] [\D \I] [\R \E] [\A ]
[\E \R] [\A \T] [\E \N] [\B \E] [\R \A] [\L \A] [\V \E] [\T \I]
[\E \D] [\O \R] [\Q \U] [\A \N] [\T \E] [\I \S] [\R \I] [\O \N]]))
; Generator of Elite-like planet names. Uses a similar algorithm but replaces the use
; of a seeded series of numbers with test.check generators.