Skip to content

Instantly share code, notes, and snippets.

View devstopfix's full-sized avatar

James Every devstopfix

View GitHub Profile
@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 / 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 / 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 / accrete.cljs
Created February 27, 2017 21:42
Generate a non-semantic version number [1 year day-of-year]
#!/usr/local/bin/planck -cp
(ns accrete
(:require [cljs-time.core :as t]
[cljs-time.format :as f]
[clojure.string :refer [join]]))
(def this-year (-> (t/now) (t/year)))
(defn day-of-year []
@devstopfix
devstopfix / roman.clj
Created March 12, 2017 09:20
Roman Numerals (Clojure)
(ns roman-numerals.roman)
(def digits {\I 1
\V 5
\X 10
\L 50
\C 100
\D 500
\M 1000})
@devstopfix
devstopfix / the_little_typer.exs
Last active January 18, 2019 15:19
Interpreter from Chapter 10 of The Little Typer implemented in Elixir
#! /usr/local/bin/elixir
defmodule TheLittleSchemer do
defmodule Toys do
@moduledoc "Chapter 1"
@doc """
The Law of Null?
The primitive null? is defined only for lists.
@devstopfix
devstopfix / chess960.exs
Created February 24, 2019 17:46
Elixir generator of Chess960 openings
defmodule Chess960 do
@moduledoc """
Generate all 960 starting positions for Chess960
https://en.wikipedia.org/wiki/Chess960#Starting_position_requirements
Run with
elixir chess960.exs
"""
@devstopfix
devstopfix / strings.exs
Created December 3, 2019 10:49
String processing
dataset =
[
[lang: "C", loc: 79, t: {4, :s}, mem: {40, :MB}],
[lang: "Python", loc: 11, t: {4, :s}, mem: {150, :MB}],
[lang: "Ruby", loc: 9, t: {17, :s}, mem: {3, :GB}],
[lang: "Elixir", loc: 11, t: {120, :s}, mem: {700, :MB}],
[lang: "Elixir ETS", loc: 17, t: {40, :s}, mem: {730, :MB}],
[lang: "Elixir Regex", loc: 17, t: {70, :s}, mem: {730, :MB}],
[lang: "Elixir String.split", loc: 11, t: {30, :s}, mem: {730, :MB}],
[lang: "Elixir String.split pre-compiled", loc: 17, t: {29, :s}, mem: {730, :MB}],
@devstopfix
devstopfix / ants.clj
Last active April 25, 2020 05:31 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
(ns ants.core)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) 2008 Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
@devstopfix
devstopfix / ants.clje
Last active May 14, 2020 15:53
Rich Hickey's ants simulator ported to Clojure on the BEAM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) 2008 Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;
; Original Clojure JVM code :- https://gist.github.com/michiakig/1093917