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 / 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
@mike-burns
mike-burns / speaker.md
Created June 14, 2012 18:33 — forked from matiaskorhonen/speaker.md
Frozen Rails Talk Proposal Template (http://2012.frozenrails.eu/)
@mike-burns
mike-burns / gist:2846438
Created May 31, 2012 21:31
groupBy in JS
Array.prototype.groupBy = function(f) {
var hash = {};
this.forEach(function(e) {
var result = f(e);
if (hash[result] == undefined)
hash[result] = [];
hash[result].push(e);
});
return hash;
}
interface List a implements Functor List, Applicative List, Monad List {
def filter(Lambda1 a Boolean) :: List a
}
interface Functor f {
def map(Lambda1 f[0] b) :: f b
}
interface Applicative f implements Functor Applicative {
def self.wrap(b) :: f b
@mike-burns
mike-burns / gist:1525703
Created December 28, 2011 01:21
pipe a value through filters
pipe :: [ a -> a ] -> a -> a
pipe [] xs = xs
pipe (f:fs) xs = pipe fs $ f xs