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 FullUrlValidator < ActiveModel::EachValidator | |
| VALID_SCHEMES = %w(http https) | |
| def validate_each(record, attribute, value) | |
| unless valid_full_url?(value) | |
| record.errors[attribute] << (options[:message] || 'is not a valid URL') | |
| end | |
| 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
| # Compiled source # | |
| ################### | |
| *.com | |
| *.class | |
| *.dll | |
| *.exe | |
| *.o | |
| *.so | |
| # Packages # |
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
| # Set prefix to Ctrl-a | |
| set -g prefix C-a | |
| bind C-a send-prefix | |
| # Unbind previous Ctrl-b prefix | |
| unbind C-b | |
| # Change default delay between keystrokes | |
| set -s escape-time 1 |
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
| defmodule Chop do | |
| def guess(actual, range = low..high) when actual >= low and actual <= high do | |
| _guess(actual, ask(div(low + high, 2)), range) | |
| end | |
| defp _guess(actual, actual, _) do | |
| IO.puts "\nYES! It is #{actual}\n" | |
| 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 TrafficLight | |
| class Lamp | |
| %w(name color).each do |attr| | |
| define_singleton_method("#{attr}=") do |value| | |
| define_method(attr) { value } | |
| end | |
| end | |
| def to_s | |
| name |
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 AuthConstraint | |
| def matches?(request) | |
| request.session['user_id'].present? | |
| end | |
| end | |
| Officegames::Application.routes.draw do | |
| constraints(AuthConstraint.new) do | |
| root :to => 'games#index' | |
| 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
| require 'rack/deflater' | |
| module Rack | |
| class Deflater | |
| class GzipStream | |
| def each(&block) | |
| @writer = block | |
| gzip =::Zlib::GzipWriter.new(self) | |
| gzip.mtime = @mtime | |
| @body.each { |part| |
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
| ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
| if html_tag =~ /<label[^>]+/ | |
| "<div class='field_with_errors'>#{html_tag}".html_safe | |
| else | |
| "#{html_tag}</div>".html_safe | |
| end | |
| end |