Skip to content

Instantly share code, notes, and snippets.

View kastner's full-sized avatar
🕳️
actively choosing...

Erik Kastner kastner

🕳️
actively choosing...
View GitHub Profile

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. However, it is very fragile (i.e. easy to crash the compiler).

For example, instance methods of fmap will run fine, but attempting to use a globally defined fmap that acts on Functor types will cause a crash. Similarly for bind. Unfortunately this means we cannot define the nice infix operator versions of these functions.

@kastner
kastner / README.md
Last active December 15, 2015 11:19 — forked from mbostock/.block
#
# Ideas stolen from lograge and brought to Rails 2.3
# https://github.com/mattmatt/lograge/blob/master/lib/lograge/log_subscriber.rb
#
module ImprovedControllerLogging
def self.included(base)
base.alias_method_chain :log_processing, :fixup
base.inject_alias_method_chain :perform_action,
:perform_action_with_benchmark,
@kastner
kastner / boilerplate.rb
Created August 7, 2011 18:48 — forked from caseybecking/gist:1130632
deployinator multiple deployments
module Deployinator
module Stacks
module Boilerplate
def boilerplate_production_version
# %x{curl http://my-app.com/version.txt}
"cf44aab-20110729-230910-UTC"
end
def boilerplate_head_build
# the build version you're about to push
# sometimes you really _do_ want a global...
# alternately, stick it as a method on a Module somewhere, App.logger or whatever, but it's still just as much of a smell.
# replace STDERR with your filename of choice.
$logger = Logger.new(STDERR)
$logger.formatter = proc { |severity, datetime, progname, msg|
"#{severity} - #{progname} - [#{datetime.strftime("%d/%m/%Y %H:%M:%S")}] #{msg}\n"
}
run(Rack::Builder.new {
def test_something_for_real
flunk <<-ABBOT_AND_COSTELLO
hey buddy, you should probably rename this file and start testing for real.
For Rael?
No real...
What's real? Rael?
Rael? You mean Rails?
Who's talking about Rails, all I want to know is if the test is for Rael...
ABBOT_AND_COSTELLO
end
# This is how you can get a user's location using MacRuby and CoreLocation
framework 'CoreLocation'
def locationManager(manager, didUpdateToLocation: new_location, fromLocation: old_location)
puts "location: #{new_location.description}"
exit
end
loc = CLLocationManager.alloc.init
loc.delegate = self
@kastner
kastner / gist:256876
Created December 15, 2009 11:49 — forked from evan/gist:256524
class Class
def memoize(*methods)
methods.each do |method_name|
safe_method_name = method_name.to_s.gsub(/(\!|\?)/, '_')
class_eval("
alias :'#{safe_method_name}_without_memo' :'#{method_name}'
def #{method_name}
if defined?(@#{safe_method_name})
@#{safe_method_name}
module Harmony
# Allows accessing config variables from harmony.yml like so:
# Harmony[:domain] => harmonyapp.com
def self.[](key)
unless @config
raw_config = File.read(Rails.root + "/config/harmony.yml")
@config = YAML.load(raw_config)[Rails.env].symbolize_keys
end
@config[key]
end