Skip to content

Instantly share code, notes, and snippets.

class Player
def play_turn(warrior)
warrior.walk!
end
end
@romansklenar
romansklenar / commands.sh
Created April 26, 2014 17:28
Rails 4.1 application update diff
rails _3.2.15_ new rails_update --database=postgresql --skip-bundle
rails _4.1.0_ new rails_update --database=postgresql --skip-bundle
@romansklenar
romansklenar / devise.cs.yml
Last active August 29, 2015 14:08 — forked from jnv/devise.cs.yml
Czech translation for Devise 3.4
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n
cs:
errors:
messages:
already_confirmed: 'byl již potvrzen, prosím, zkuste se přihlásit'
confirmation_period_expired: 'musí být potvrzen během %{period}, požádejte prosím o nový'
expired: 'vypršel, požádejte prosím o nový'
not_found: 'nenalezen'
not_locked: 'nebyl uzamčen'
@romansklenar
romansklenar / Record.php
Created December 13, 2009 18:42
Record: simple abstraction above database row (DibiRow replacement)
<?php
/**
* Provide very simple abstraction above database row (DibiRow replacement)
*
* @author Roman Sklenář
* @copyright Copyright (c) 2009 Roman Sklenář (http://romansklenar.cz)
* @license New BSD License
* @version 0.1
@romansklenar
romansklenar / sablona_seminarek.pdf
Created March 10, 2012 14:05
Šablona seminárek v LaTeXu
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@romansklenar
romansklenar / foo.rb
Created July 19, 2012 12:38
Rails ActiveRecord Model protected against overwrite by another user updating same instance
class Foo < ActiveRecord::Base
attr_accessor :timestamp_control
after_initialize { self.timestamp_control ||= Time.zone.now }
before_validation :overwrite_check
def overwrite_check
errors[:base] << I18n.t('errors.messages.overwritten') if updated_at > timestamp_control
end
@romansklenar
romansklenar / README.md
Created January 8, 2013 16:00
Killing Rails observers

Killing Rails observers

  • decreases startup time by not loading all your models
  • makes it possible to preload config/environment.rb and still test models -> spin/zeus
  • makes dependencies obvious
  • replaces ActiveRecord magic with ruby
  • makes your app Rails 4 ready

Before

@romansklenar
romansklenar / seeds.rb
Created January 10, 2013 17:45
Apple stocks import
require 'open-uri'
require 'roo'
apple = Company.create! do |company|
company.name = "Apple Inc."
company.code = "AAPL"
company.messages_url = "http://finance.yahoo.com/rss/headline?s=#{company.code}"
company.stocks_url = "http://ichart.finance.yahoo.com/table.csv?s=#{company.code}"
end
@romansklenar
romansklenar / seeds_generator.rb
Created January 29, 2013 21:49
Auditster: sample users CSV import generator
# company_names = (1..15).map { Faker::Company.name }
company_names = %w[Design Marketing Branding Stores Mobile Desktop Software Hardware] # departments
data = (1..500).map do
[ company_names.sample,
name = Faker::Name.name,
Faker::Internet.free_email(name.parameterize),
Faker::Internet.user_name(name.parameterize),
SecureRandom.urlsafe_base64(10).gsub('-', '') ]
end