Skip to content

Instantly share code, notes, and snippets.

View jasonneylon's full-sized avatar

Jason Neylon jasonneylon

View GitHub Profile
@jasonneylon
jasonneylon / blackjack.re
Created February 4, 2021 14:54
Blackjack functional domain modelling example team 2
type rank = Ace | Two | Three| Four | Five | Six | Seven| Eight | Nine | Ten | Jack | Queen | King ;
type suit = Spade | Hearts | Diamond | Club
type card = { rank, suit }
type deck = list(card)
/* type deck = List(card) | EmptyDeck */
/* draw card(s) (don't forget the effect on the deck)
ensure the deck is shuffled
@jasonneylon
jasonneylon / address.rb
Created December 29, 2012 16:27
Uk postcode validation with rails/activerecord
class Address < ActiveRecord::Base
attr_accessible :postcode
validates_format_of :postcode, :with => /^([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s?[0-9][ABD-HJLNP-UW-Z]{2}|(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\ )?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$$/i, :message => "invalid postcode"
end
@jasonneylon
jasonneylon / passphrases.clj
Created November 30, 2016 10:10
Generate passphrases (and DNA!) using clojure.spec
(require '[clojure.spec :as s])
(require '[clojure.spec.gen :as gen])
;; PASSPHRASES - generate a random 5 word passphrase
;; naive approach was to generate a random string and contrain to match a five word pattern
;; however this hit 100 generation limit imposed by clojure.spec
(defn words [str] (clojure.string/split str #" "))
(def five-words? (comp (partial = 5) count words))
(gen/generate (s/gen (s/and string? five-words?)))
@jasonneylon
jasonneylon / recent.sh
Created August 23, 2017 10:40
Everything I have done since a specfic date in all the git subfolders
for i in *; do ( cd $i; pwd; git --no-pager log --since="2016-02-12T16:36:00-07:00" --author jason --format=oneline; pwd ); done | less
(defn timeout [ms]
(let [c (chan)]
(js/setTimeout (fn [] (close! c)) ms)
c))
(defn run-kmean
[]
(go
(dotimes [iteration 10]
(<! (timeout 1000))
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every second NextRunTicktions : Model -> Sub Msg
randomPoints : Generator (List(Point))
randomPoints =
Random.list 200 (Random.map (\(x, y) -> Point x y) (Random.pair (int 1 999) (int 1 399)))
-- here we create a command that the elm runtime will execute and then pass the results back via the Update function
initialModel : (Model, Cmd Msg)
initialModel =
(Model [] [] 6 0 False, (Random.generate DrawPoints randomPoints))
(defn random-point []
{:x (rand-int 1000) :y (rand-int 500)})
@jasonneylon
jasonneylon / gist:5652217
Last active May 16, 2016 22:28
Javascript to render AirQualityEgg data from Xively using RIckshaw JS
xively.setKey( "YOUR API KEY HERE" );
var startOfYesterday = moment().subtract("day", 1).startOf('day');
var endOfYesterday = moment().startOf('day');
console.log(startOfYesterday);
console.log(endOfYesterday);
var query = {
start: startOfYesterday.toJSON(),