Skip to content

Instantly share code, notes, and snippets.

@wjdix
wjdix / switch.ex
Last active January 26, 2016 00:27
defmodule Switch do
def start_link(n \\ 10, callback \\ fn (_) -> IO.puts "Turned on" end, opts \\ []) do
:gen_fsm.start_link(__MODULE__, [n, callback], opts)
end
def init([n, callback]) do
{:ok, :off, %{n: n, received: 0, on_callback: callback}}
end
def off({:event}, state) do
(defmacro better-if-let
([bindings then]
`(better-if-let ~bindings ~then nil))
([[form tst & rest-bindings] then else]
`(let [temp# ~tst]
(if temp#
(let [~form temp#]
~(if (seq rest-bindings)
`(better-if-let ~(vec rest-bindings) ~then ~else)
then))

Keybase proof

I hereby claim:

  • I am wjdix on github.
  • I am dix (https://keybase.io/dix) on keybase.
  • I have a public key whose fingerprint is 8596 5C6D A326 4D3B 16FE D656 E52A BABC A595 594C

To claim this, I am signing this object:

(defn- consumer-queue [dequeue]
(lazy-seq
(let [head (.take dequeue)]
(cons head (consumer-queue dequeue)))))
(defn- send-in-batches [tweet-list]
(loop [tweets tweet-list]
(send-tweet-emails (take 2 tweets) (System/getenv "GMAIL_PASS"))
(recur (drop 2 tweets))))
@wjdix
wjdix / gist:8599039
Created January 24, 2014 15:08
Actual IMs I Just Received, Am I In SOME KIND OF MOVIE?!??!!
10:05 Shy Guy: i know the source
10:05 Shy Guy: i can fix it
c := newCluster(3).withChannelPeers().withStateMachine(buildThrowAwayStateMachine).withTimeouts(2, 9, 9)
c.startChannelPeers()
c.startElectionTimers()
c.server(1).StartElection()
c.partition(3)
c.server(1).AppendEntries("A")
c.server(1).AppendEntries("B")
@wjdix
wjdix / gist:5724564
Created June 6, 2013 20:15
#FAKE #SPOILER #ALERT
2:56 drew everyone in the lord of the rings dies in a wedding, fyi
2:56 dog bark!
2:57 Tony Pitluga woah!
2:57 William Dix fake spoiler alert!!
2:57 drew and one of them is cooking meth and is a cylon
2:57 William Dix also Littlefinger will go on to be the mayor of Baltimore and he will disappoint
2:57 drew but, during the wedding catastrophe, frodo just keeps staring at the ring with wide eyes falling into water because THAT'S ALL HE EVER DOES
2:58 drew i think i might have had too much caffeine
2:58 Pilat and then he realizes he's been dead the whole time
2:59 William Dix but it's okay b/c he was only a sled anyway!
@wjdix
wjdix / intersection.rb
Created March 20, 2012 15:56
ruby stdlib set error
class Point
attr_reader :x, :y
def initialize(x, y)
@x, @y = x, y
end
def ==(other)
x == other.x && y == other.y
end
end
@wjdix
wjdix / headless.rb
Created June 13, 2011 15:38
Headless Capybara
# in Gemfile
gem 'headless', :git => 'git://github.com/msgehard/headless.git'
# in some capybara support file
# I use features/support/world.rb
if Capybara.current_driver == :selenium && RAILS_EVN == 'hudson'
require 'headless'
headless = Headless.new
@wjdix
wjdix / date_select_step.rb
Created December 15, 2010 17:10
Cucumber step to select dates
When /^I select "([^"]*)" as the "([^"]*)" date$/ do |date, field|
broken_date = date.split("/")
day = broken_date[1]
month = Date::MONTHNAMES[broken_date[0].to_i]
year = broken_date [2]
select year, :from => "#{field}_1i}"
select day, :from => "#{field}_2i}"
select month, :from => "#{field}_3i}"
end