- Email: aleks@rubysfera.pl
- Twitter: @_tjeden
- Website or Blog: http://rubysfera.pl
- Company: Astarium.pl
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 ArticlesController < ApplicationController | |
def new | |
writer = Writer.find(params[:writer_id]) | |
@article = writer.articles.build | |
end | |
def save | |
writer = Writer.find(params[:writer_id]) | |
@article = writer.articles.build(article_params) | |
@article.save |
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 BasiaAttr | |
def basia_reader(method_name) | |
define_method(method_name) do | |
instance_variable_get("@#{method_name}".to_sym) | |
end | |
end | |
def basia_writer(method_name) | |
define_method("#{method_name}=") do |value| | |
instance_variable_set("@#{method_name}".to_sym, value) |
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 Product < ActiveRecord::Base | |
validates :price, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 100 } | |
validates :description, presence: true | |
validates :title, presence: true, length: { minimum: 4 }, uniqueness: true | |
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
def fizz_buzz(n) | |
result = "" | |
(1..n).to_a.each do |i| | |
x = "" | |
x += "Fizz" if i % 3 == 0 | |
x += "Buzz" if i % 5 == 0 | |
x = i.to_s if x == "" | |
result += x | |
end | |
result |
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 average(*values) | |
values.inject(:+)/values.size.to_f if !values.empty? | |
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 Enumerable | |
def inject_with_index(sum = 0) | |
each_with_index do |e, i| | |
sum = yield(sum, e , i) | |
end | |
sum | |
end | |
end | |
puts ['a', 'b', 'c', 'd'].inject_with_index { |a, e, i| a + i } |
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
@import url(http://fonts.googleapis.com/css?family=Poly); | |
body {font-family: 'Poly', serif;} | |
#preso, .slide { | |
background: #fff; | |
width: 1920px; | |
height: 1080px; | |
} |
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
# encoding: UTF-8 | |
contestants = ["piotr3k", "Marcin", "Sławosz", "Nowaker", "Rafał Wrzochol", "Maciej Lotkowski", "regedarek", "Świstak35", "pan_sarin", "jgonera", "Michał Krajewski", "Tomasz Orzechowski", "Piotr Jurczyński", "Maciej Gajewski"] | |
puts contestants[rand(contestants.length)] |
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 Converter | |
def postalize(text) | |
if text.length == 5 | |
"#{text[0..1]}-#{text[2..4]}" | |
else | |
text[2] = "-" | |
text | |
end | |
end | |
end |
NewerOlder