I had an interesting realization tonight: I'm terrified of hash tables. Specifically, my work on JRuby (and even more directly, my work optimizing JRuby) has made me terrified to ever consider using a hash table in the hot path of any program or piece of code if there's any possibility of eliminating it. And what I've learned over the years is that the vast majority of execution-related (as opposed to data-related, purely dynamic-sourced lookup tables) hash tables are totally unnecessary. Some background might be interesting here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module StaticMapHelper | |
| def static_map_for(location, options = {}) | |
| params = { | |
| :center => [location.lat, location.lng].join(","), | |
| :zoom => 15, | |
| :size => "300x300", | |
| :markers => [location.lat, location.lng].join(","), | |
| :sensor => true | |
| }.merge(options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Alert < ActiveRecord::Base | |
| belongs_to :alertable, :polymorphic => true | |
| end | |
| class Region < ActiveRecord::Base | |
| has_many :alerts, :as => :alertable | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Medium < ActiveRecord::Base | |
| serialize :payload, JSON | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UrlValidator < ActiveModel::EachValidator | |
| def validate_each(record, attribute, value) | |
| valid = begin | |
| URI.parse(value).kind_of?(URI::HTTP) | |
| rescue URI::InvalidURIError | |
| false | |
| end | |
| unless valid | |
| record.errors[attribute] << (options[:message] || "is an invalid URL") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UILabel_Adjustable | |
| # Borrowed and modified the excellent example at http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/ | |
| # adapting it for RubyMotion | |
| # This applies only to a multi-line label. You can use '.adjustsFontSizeToFitWidth = true' for a single-line label | |
| # usage is: | |
| # text = "It's bad luck to be superstitious" | |
| # text_label = UILabel.alloc.initWithFrame([[20, 20], [70, 120]]) | |
| # text_label.numberOfLines = 0 # set 0 for word wrap | |
| # text_label.lineBreakMode = UILineBreakModeWordWrap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @charset "UTF-8"; | |
| @mixin grab-cursor { | |
| // http://www.google.com/intl/en_ALL/mapfiles/openhand.cur | |
| cursor: url('data:image/vnd.microsoft.icon;base64,AAACAAEAICACAAcABQAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAAAEAAAAAAAAAAAAAAgAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8AAAA/AAAAfwAAAP+AAAH/gAAB/8AAA//AAAd/wAAGf+AAAH9gAADbYAAA2yAAAZsAAAGbAAAAGAAAAAAAAA//////////////////////////////////////////////////////////////////////////////////////gH///4B///8Af//+AD///AA///wAH//4AB//8AAf//AAD//5AA///gAP//4AD//8AF///AB///5A////5///8='), all-scroll; | |
| // cursor: -webkit-grab; | |
| cursor: -moz-grab; | |
| cursor: -o-grab; | |
| cursor: -ms-grab; | |
| cursor: grab; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializers/markdown_handler.rb | |
| module MarkdownHandler | |
| def self.erb | |
| @erb ||= ActionView::Template.registered_template_handler(:erb) | |
| end | |
| def self.call(template) | |
| compiled_source = erb.call(template) | |
| "Kramdown::Document.new(begin;#{compiled_source};end, auto_ids: false).to_html" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install MacTex: http://mirror.ctan.org/systems/mac/mactex/mactex-basic.pkg | |
| $ sudo chown -R `whoami` /usr/local/texlive | |
| $ tlmgr update --self | |
| $ tlmgr install ucs | |
| $ tlmgr install etoolbox | |
| # Install pandoc view homebrew |