Skip to content

Instantly share code, notes, and snippets.

View aredington's full-sized avatar

Alex Redington aredington

View GitHub Profile
@aredington
aredington / gist:1761017
Created February 7, 2012 18:03
Briefer commatize
(defn commatize [n]
(apply str
(flatten
(butlast
(interleave
(reverse
(partition 3
3
()
(reverse (seq (str n)))))
@aredington
aredington / javacalisbad.clj
Created February 17, 2012 16:46
Problems with java.util.Calendar
(def cal (java.util.Calendar/getInstance))
(.clear cal)
(.set cal java.util.Calendar/YEAR 2010)
(.set cal java.util.Calendar/MONTH 11)
(.set cal java.util.Calendar/WEEK_OF_YEAR 1)
(.getTime cal)
(if (= 2009 (.get cal java.util.Calendar/YEAR))
(throw (IllegalStateException. "WTF? LOOK AT LINE 3!!!")))
@aredington
aredington / gist:5781826
Created June 14, 2013 13:32
Add (multiplex <readports>) and (broadcast <writeports>) to core.async

What

Add two functions, multiplex and broadcast, to core.async.

Multiplex is a variadic function of n arguments, returning a new single core.async read port which produces values by multiplexing together all of the provided read ports.

Broadcast is a variadic function of n arguments, returning a new single core.async write port which will write values by writing the values it receives to each of the provided write ports.

What'

@aredington
aredington / gist:6320532
Created August 23, 2013 15:20
Demonstration of using monotony with new period-name fn
(require '[monotony.core :as m])
(def config (m/local-config))
(defn weekday-hours
[conf day]
(let [hours (m/bounded-cycles-in conf day :hour)]
[(nth hours 0) (nth hours 18)]))
(defn weekend-hours
@aredington
aredington / output.clj
Last active August 29, 2015 14:09 — forked from hmanish/output.clj
(defn compute-position
"returns a map
key is a vector -[ <settlement index name> <power primitive name>]
value is a map - {<Date representing yyyy-MM> <Double: the positon> }
For non power trades, primitive name will be nil"
[trade]
;;compute postion code)

Keybase proof

I hereby claim:

  • I am aredington on github.
  • I am holy_chao (https://keybase.io/holy_chao) on keybase.
  • I have a public key ASBYQU_MVKO_5ezGJL10NtcM9bOr1uslOsTmtIsPSUwu7Qo

To claim this, I am signing this object:

@aredington
aredington / makehammer40k.rb
Created February 18, 2022 16:29
How bad can we make a makefile tree?
#!/usr/bin/env ruby
File.open("Makefile","w") do |f|
targets = (1..6).to_a.repeated_permutation(6).map{|a| "t#{a.join}"}.join(" ")
f.puts("all: #{targets}\n\n")
(1..6).each do |root_target|
f.puts "t#{root_target}:\n"
f.puts "\tmkdir -p o#{root_target}\n"