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
| // All values of INPUT and TEXTAREA elements with the "sticky" class | |
| // will be remembered in a session cookie and restored on page load | |
| // when the "value" of that element is empty. | |
| StickyInput = { | |
| name: function(e) { | |
| return "sticky-" + e.name; | |
| }, | |
| set: function(e, v) { |
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
| ;; Enable paredit for a couple for non lisp modes; tweak | |
| ;; paredit-space-for-delimiter-predicates to avoid inserting spaces | |
| ;; before open parens. | |
| (dolist (mode '(ruby espresso)) | |
| (add-hook (intern (format "%s-mode-hook" mode)) | |
| '(lambda () | |
| (add-to-list (make-local-variable 'paredit-space-for-delimiter-predicates) | |
| (lambda (_ _) nil)) | |
| (enable-paredit-mode)))) |
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
| (ns roman [:use clojure.test]) | |
| (def num-to-dig {1 "I", 4 "IV", 5 "V", 9 "IX" | |
| 10 "X", 40 "XL", 50 "L", 90 "XC" | |
| 100 "C", 400 "CD", 500 "D", 900 "CM" | |
| 1000 "M"}) | |
| (def dig-to-num (into {} (map (fn [[k v]] [v k]) num-to-dig))) | |
| (defn encode |
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
| // Highlight the element referred to by the anchor on the URL. | |
| Event.observe(window, 'load', function() { | |
| var id, hash = document.location.hash; | |
| if (hash && (id = hash.replace(/^#/, '')) && (id = $(id))) { | |
| setTimeout(function() { | |
| (id.down('td') ? id.select('td') : [id]).each(function(e) { | |
| new Effect.Highlight(e); | |
| }); | |
| }, 250); |
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
| # Automatically add checkbox class to check_box form elements to allow | |
| # styling them separately in older versions of IE. | |
| module ActionView::Helpers::FormHelper | |
| def check_box_with_class(object_name, method, options = {}, checked_value = "1", unchecked_value = "0") | |
| check_box_without_class(object_name, method, {:class => "checkbox"}.merge(options), checked_value, unchecked_value) | |
| end | |
| alias_method_chain :check_box, :class | |
| 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
| (ns #^{:author "Remco van 't Veer" | |
| :doc | |
| "Basic validation framework for maps. The constructed validator | |
| functions take two arguments the before- and after state of the map. | |
| They return a map of errors where keys are, typically, keys of the | |
| input map and values are lists of keyworded errors or maps of keyword | |
| errors to some relevant argument. For example: | |
| ((validator (not-blank :nr) |
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
| File.read("/etc/mime.types").split("\n").reject{|l| l =~ /^\s*#/}.reject(&:blank?).reduce({}){|m,l| t, *x = l.split(/\s+/); x.each{|k| m[k] = t}; m} |
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 ActiveRecord::Base | |
| class << self | |
| attr_writer :stripped_attributes | |
| def stripped_attributes | |
| @stripped_attributes ||= [] | |
| end | |
| def strip_value_of(*attrs) | |
| self.stripped_attributes += attrs |
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
| (defn levenshtein | |
| "Calculate levenshtein distance between two sequences." | |
| {:test #(are [d s1 s2] (= d (levenshtein s1 s2)) | |
| 0 "soup" "soup" | |
| 3 "kitten" "sitting" | |
| 3 "sitting" "kitten" | |
| 0 [1 2 3] [1 2 3] | |
| 1 [1 2 3] [1 2 3 4])} | |
| [s1 s2] | |
| (((reduce (fn [d [i j]] |