Skip to content

Instantly share code, notes, and snippets.

View devstopfix's full-sized avatar

James Every devstopfix

View GitHub Profile
@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.
;
; Generate a table of the products of prime numbers
;
(defn √ [x]
"Integer square root of x"
(int (Math/sqrt x)))
(defn prime? [x]
"Return true if x is a prime number, using naïve trial division algorithm."
@devstopfix
devstopfix / elite-planet-names.rb
Created May 10, 2015 20:39
Ruby planet name generator
PAIRS="..LEXEGEZACEBISOUSESARMAINDIREA.ERATENBERALAVETIEDORQUANTEISRION"
planet = (3+rand(2)).times.map { PAIRS[rand(32) * 2,2] }.join.gsub('.', '').capitalize
@devstopfix
devstopfix / passwordy.rb
Created May 4, 2015 12:46
Dumb Ruby password generator
# Returns an enumerator that generates password from the standard dictionary
# Only parameter is the number of words to use.
# Example: passwordy(2).next -> "GarlicUngulp"
def passwordy(wc=4)
words = File.readlines('/usr/share/dict/words')
.select {|w| w.size>5 && w.size<=9}
.shuffle
Enumerator.new do |yielder|
yielder.yield(words