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
LETTERS = ('a'..'z').to_a | |
NUMBERS = (0..9).to_a | |
LETTERS_AND_NUMBERS = LETTERS.concat(NUMBERS) | |
# Generate a random unique ID | |
# in any length | |
class CodeGenerator | |
def generate(n=16) | |
code = [] | |
n.times {code << LETTERS_AND_NUMBERS.sample} |
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
# encoding: utf-8 | |
require 'talks' | |
class Hash | |
## | |
# Cascading Fetch | |
# | |
# Tries to fetch provided symbols one after the other | |
# and return fallback non-symbol value otherwise |
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
## | |
# Array of arrays to hash conversion | |
# | |
## | |
# Version 1 | |
array = [[1, 1], [2, 2], [3, 3]] | |
hash = Hash[*array.flatten] |
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 the json library to parse json into Ruby objects | |
require 'json' | |
require 'simple_statistics' | |
# The input | |
json = '[ | |
{ | |
"Low": 8.63, | |
"Volume": 14211900, | |
"Date": "2012-10-26", |
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 Range | |
def end_at(x) | |
Range.new(self.begin, x) | |
end | |
def start_at(x) | |
Range.new(x, self.end) | |
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
## | |
# A ruby-powered table of contents layout | |
words = %w(we are the world lets make it a better place we are the world) | |
words.each_with_index {|word, page| puts word.ljust(10, '.') + (page*page).to_s.rjust(3, '.')} | |
# => Output | |
# we..........0 | |
# are.........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
// Formtastic stylesheet based on the gem's version, retrieved 2013-01-04 | |
// This version reflects the gem exactly. | |
// Use as a base for modifications. | |
.formtastic | |
margin: 0 | |
padding: 0 | |
// resets | |
ul, ol, li, fieldset, legend, input, button, textarea, select, p |
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
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n | |
de: | |
devise: | |
confirmations: | |
confirmed: "Vielen Dank für Deine Registrierung. Bitte melde dich jetzt an." | |
confirmed_and_signed_in: "Vielen Dank für Deine Registrierung. Du bist jetzt angemeldet." | |
send_instructions: "Du erhältst in wenigen Minuten eine E-Mail, mit der Du Deine Registrierung bestätigen kannst." | |
send_paranoid_instructions: "Falls Deine E-Mail-Adresse in unserer Datenbank existiert erhältst Du in wenigen Minuten eine E-Mail mit der Du Deine Registrierung bestätigen kannst." | |
failure: |
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
form | |
.field | |
@extend .form-group | |
input[type=text], textarea, input[type=email], input[type=search], input[type=password] | |
@extend .form-control | |
label | |
@extend .control-label | |
.field .field_with_errors | |
@extend .has-error |
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 'active_support/core_ext' | |
def calendar_week(week) | |
now = Date.current | |
year = now.cweek < week ? now.year : now.year + 1 | |
Date.commercial(year, week, 1) | |
end | |
p calendar_week(49) | |
# => Mon, 02 Dec 2013 |
OlderNewer