Skip to content

Instantly share code, notes, and snippets.

View awostenberg's full-sized avatar

Alan Wostenberg awostenberg

View GitHub Profile
@awostenberg
awostenberg / gist:2514008
Created April 27, 2012 22:40
prime factors kata clojure
;;today's timed kata from https://github.com/hoodja/practice-to-learn
;;down to 15 minutes today from 30 minutes previously
(ns com.pillartechnology.practice
(:use clojure.test midje.sweet))
(defn factors
([n] (factors n 2))
([n c]
(if (= n 1)
[]
@awostenberg
awostenberg / gist:2514719
Created April 28, 2012 00:45
happy primes Clojure Dr. Who
;;Happy primes: inspired by watching Dr. Who episode 7 season 3 with my youngest son, John, on netflix
;;"don't they teach recreational mathematics any more?" -- Dr. Who, "42"
;;http://en.wikipedia.org/wiki/42_(Doctor_Who)
;;http://www.wolframalpha.com/input/?i=happy+numbers
;;Code was written in just the order you see things here,
;;in the bottom-up style of programming typical of Lisp and Smalltalk
;;In this recreational style I don't write tests,
;; but leave commented expressions you could evaluate near each function.
@awostenberg
awostenberg / circle_calc.rb
Created May 1, 2012 01:14
calculate points on the circumference of a circle
# -*- coding: utf-8 -*-
# A simple class to calculate approximately any point on a circle defined by the radius
class Circle
def initialize(radius) # Might be actually the diameter; just whipping up some quick code
@radius = radius
end
def [](theta)
# π
# You must multiply --- to convert theta from degrees to radians
@awostenberg
awostenberg / gist:3353175
Created August 14, 2012 21:27
Trying to run Purugin with Craftbukkit 1.3.1
195 recipes
27 achievements
15:18:38 [INFO] Starting minecraft server version 1.3.1
15:18:38 [INFO] Loading properties
15:18:38 [INFO] Default game type: SURVIVAL
15:18:38 [INFO] Generating keypair
15:18:38 [INFO] Starting Minecraft server on *:25565
15:18:38 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.1-R1.0-b2320jnks (MC: 1.3.1) (Implementing API version 1.3.1-R1.0)
15:18:38 [SEVERE] Could not load 'plugins/Purugin.jar' in folder 'plugins'
@awostenberg
awostenberg / rle
Last active August 29, 2015 14:16
run length encoding
// from rosettacode
let encode data =
// encodeData : seq<'T> -> seq<int * 'T> i.e. Takes a sequence of 'T types and return a sequence of tuples containing the run length and an instance of 'T.
let rec encodeData input =
seq { if not (Seq.isEmpty input) then
let head = Seq.head input
let runLength = Seq.length (Seq.takeWhile ((=) head) input)
yield runLength, head
yield! encodeData (Seq.skip runLength input) }
@awostenberg
awostenberg / boxo
Created March 19, 2015 21:42
my boxstarter
Set-ExplorerOptions -showHidenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
Enable-RemoteDesktop
#nowarn "40"
module exploreProgressBar =
type Progress = BeginScope of string | SetProgress of float | EndScope
let dialogAgent = MailboxProcessor.Start(fun inbox ->
let rec messageLoop = async {
// read a message
let! msg = inbox.Receive()
// process a message
match msg with
| BeginScope title -> printfn "Begin Scope %s - open dialog here" title
// bchop kata to spec http://codekata.com/kata/kata02-karate-chop/ (not idiomatic)
type Comparision = Less|Equal|Greater
let compare (a:int) b =
match sign (a-b) with
| 0 -> Equal
| -1 -> Less
| _ -> Greater
compare 3 3 = Equal
// bchop kata more idiomatic http://codekata.com/kata/kata02-karate-chop/
// replacing that -1 with an option type flushed a bug at compile time
type Comparision = Less|Equal|Greater
let compare a b = if a = b then Equal else if a < b then Less else Greater
compare 3 3 = Equal
compare 2 3 = Less
compare 3 2 = Greater
// compare poker hands
type Value = Number of int|Jack|Queen|King|Ace
type Suit = Clubs|Spades|Hearts|Diamonds
type Card = Value*Suit
// tests - card comparisons
[
(Ace,Hearts) > (King,Spades)
(Number 7,Hearts) < (Jack,Clubs)