This file contains 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
(('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).sample(30).join #=> "yh8D5NrognVw16GldXPcCxJ24ALU3W" | |
# with special characters | |
(('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a + ['!','@','#','$','%','^','&','*']).sample(30).join #=> "Nc&inVolamjMLWfsE#k6$D^p2!b@XC" |
This file contains 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
def collection_class_name(collection, index) | |
if index == 0 | |
return 'first' | |
elsif index == ( collection.size - 1 ) | |
return 'last' | |
end | |
end |
This file contains 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
NOTE: For all installations, as of 1.7, RVM no longer autoloads .rvmrc files. In order to return this | |
functionality, you MUST add 'export rvm_project_rvmrc=1' to your $HOME/.rvmrc file. | |
This causes RVM to override 'cd' which, while toggleable even < 1.7, is currently defaulted to 'off'. | |
This knob returns the previous behaviour to active which causes per-project .rvmrc files to be loaded | |
once again. | |
Example: echo 'export rvm_project_rvmrc=1' >> $HOME/.rvmrc && rvm reload |
This file contains 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 |
This file contains 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 Parsing where | |
> | |
> | |
> import Data.Char | |
> import Control.Monad | |
> import Control.Applicative | |
> | |
> infixr 5 +++ | |
The monad of parsers |
This file contains 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 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 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 AppName.FormHelpers do | |
@doc """ | |
Generates a form input tag | |
Example: | |
<%= input f, | |
:name, | |
input: [ | |
placeholder: gettext("What should we call you?"), | |
], |
This file contains 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
use Ecto.Schema | |
import Ecto.Changeset | |
@type t :: module | |
# A required field for all embedded documents | |
@primary_key {:id, :binary_id, autogenerate: true} | |
schema "" do |