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
| // Exercise 2 - Closures | |
| // Wrap the following code in a closure and export only the "countdown" function. | |
| (function(scope, functionName) { | |
| var index; | |
| function log(){ | |
| console.log(index); | |
| } |
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
| function isCreditCard(CC) { | |
| if (CC.length < 20) { | |
| for (var i = 0, l = CC.length, double = false, sum = 0; | |
| i < l; | |
| i++, double = !double) { | |
| var digit = CC.substring(l-i-1,l-i), | |
| tproduct = parseInt(digit ,10) * (double ? 2 : 1); | |
| sum += Math.floor(tproduct / 10) + tproduct % 10; | |
| } |
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
| #!/usr/bin/env ruby | |
| color = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD'] | |
| if color =~ /^\#?(([0-9a-f]{3}){1,2})$/i | |
| hex = $1 | |
| hexes = if hex.length == 3 | |
| [hex[0, 1] * 2, hex[1, 1] * 2, hex[2, 1] * 2] | |
| else | |
| [hex[0, 2], hex[2, 2], hex[4, 2]] |
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
| /** | |
| * Style definitions for banner management | |
| */ | |
| .ui-split { | |
| position: relative; | |
| } | |
| .ui-split-pane { | |
| position: absolute; |
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 Mongoid | |
| module Markdown | |
| def self.included(base) | |
| base.extend ClassMethods | |
| end | |
| module ClassMethods | |
| def markdown(*attributes) | |
| write_inheritable_attribute(:markdown_attributes, markdown_attributes + Array(attributes)) | |
| @markdown_unicode = String.new.respond_to? :chars |
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 Mongoid | |
| module DeepCloning | |
| def deep_clone(attrs = {}, obj = nil) | |
| returning obj || self.class.new do |o| | |
| o.write_attributes(@attributes.merge(attrs).except("_id", "versions").except(*o.class.associations.keys)) | |
| yield o if block_given? | |
| o.save | |
| @attributes.each_pair do |key, value| | |
| next unless proxy = self.associations[key] | |
| case proxy.association |
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 Account | |
| include Mongoid::Document | |
| include Mongoid::Timestamps | |
| field :subdomain, :type => String | |
| embeds_many :users | |
| accepts_nested_attributes_for :users | |
| validates_presence_of :name, :subdomain | |
| validates_uniqueness_of :subdomain, :case_sensitive => false |
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 InlinePremailer < ::Premailer | |
| def initialize(string, options = {}) | |
| @options = {:warn_level => Warnings::SAFE, | |
| :line_length => 65, | |
| :link_query_string => nil, | |
| :base_url => nil, | |
| :remove_classes => false}.merge(options) | |
| @html_file = @options[:base_url] | |
| @is_local_file = false |
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
| require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") | |
| class ValidationTest | |
| include ActiveModel::Validations | |
| before_validate :do_something | |
| validates_presence_of :something | |
| def do_something | |
| raise "callback" |
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 Post | |
| key :title, String | |
| key :slug, String | |
| validates_presence_of :title, :slug | |
| validates_uniqueness_of :slug | |
| before_create :fill_in_slug | |
| protected | |
| def fill_in_slug |