Skip to content

Instantly share code, notes, and snippets.

View mike-burns's full-sized avatar
💭
GitLab

Mike Burns mike-burns

💭
GitLab
View GitHub Profile
@mike-burns
mike-burns / .msmtp
Last active December 23, 2022 14:56
FastMail + mutt
account default
host mail.messagingengine.com
port 587
protocol smtp
auth on
from mike@mike-burns.com
user mikeburns@fastmail.fm
password topsecretpassword!
tls on
tls_nocertcheck
@mike-burns
mike-burns / io.rb
Created November 29, 2011 01:55
The IO data type, functor, and monad ... in Ruby
class InputOutput
def initialize(&action)
@action = action
end
private_class_method :new
# return :: (Monad m) => a -> m a
def self.unit(x)
new { x }
end
@mike-burns
mike-burns / thingy_and_its_maker.py
Created September 5, 2013 19:56
Example builder pattern in Python
class ThingyMaker(object):
def __init__(self):
self.thingy = None
self.widget = None
def with_thingy(self, thingy):
self.thingy = thingy
return self
def with_widget(self, widget):
@mike-burns
mike-burns / io.rb
Created August 25, 2013 02:17
Haskell's IO implemented in Ruby
class Io
attr_reader :action
def initialize(&action)
@action = action
end
def bind(&f)
Io.new do
result = @action.call
f.call(result)
@mike-burns
mike-burns / folds.rb
Last active December 21, 2015 13:59
Monoids
class Monoid
attr_accessor :value
def initialize(value)
@value = value
end
def self.base
new(const_get(:BASE))
end
@mike-burns
mike-burns / open-location
Created July 22, 2013 22:49
Open a prompt for a file location then open that file. Useful for directories.
#!/bin/sh
entry_text=`pwd`
location=`zenity --file-selection --directory --filename=$entry_text --title="Open location"`
if [ "x$?" = "x0" ]; then
xdg-open "$location"
fi
@mike-burns
mike-burns / is_fib.rb
Created June 20, 2013 22:59
Is a number in the set of Fibonacci numbers?
module IsFibber
def fibonacci?(n)
perfect_square?(5 * n * n + 4) || perfect_square?(5 * n * n - 4)
end
private
def perfect_square?(f)
sqrt = Math.sqrt(f)
sqrt == sqrt.round
@mike-burns
mike-burns / run-in-terminal.sh
Created November 7, 2012 15:49
run-in-terminal
#!/bin/sh
desktop=`xdotool get_desktop`
window=`xdotool search --onlyvisible --all --desktop $desktop --class gnome-terminal | head -1`
xdotool windowactivate --sync $window type "$@
"
xdotool windowactivate --sync $window key Return
@mike-burns
mike-burns / gist:3958781
Created October 26, 2012 13:20
refinements cannot do recursion
class Literal < Struct.new(:number)
def show
print number
end
end
class Add < Struct.new(:a, :b)
def show
a.show
print ' + '
@mike-burns
mike-burns / examples.rb
Created October 24, 2012 13:24
Stop typoing #initialize
class User < Params.over(:first_name, :last_name)
def info
"I am a user: #{@first_name} #{@last_name}"
end
end
class Admin < User.params(:awesomeness_level)
def info
"I am a level #{@awesomeness_level} admin: #{@first_name} #{@last_name}"
end