Skip to content

Instantly share code, notes, and snippets.

@karmi
karmi / 000_create_categories.rb
Created November 25, 2008 11:34
I ♥ Ruby so much...
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name_en,
:name_cz,
:name_es
t.timestamps
end
end
locales = ["cz", "en"]
%w{name name_cz name_is_long name_is_long_cz name123_cz name_en name_ane name_es}.each do |attribute_name|
if includes_locale = locales.find { |locale| attribute_name =~ Regexp.new("_#{locale}$") }
puts includes_locale.inspect
puts attribute_name + ' : true'
<tr>
<td style="width: 25%" class="align-right sortable"><%= text_field_tag 'program_event[entrance_fees][][price]', nil, :class => 's' %> Kč</td>
<td style="width: 50%" class="sortable">
<!-- <span class="drag_handle">&nbsp;&nbsp;&nbsp;&nbsp;</span> -->
<%= text_field_tag 'program_event[entrance_fees][][description]', nil %>
</td>
<td>&nbsp;</td>
</tr>
>> Dir.pwd
=> "/Users/karmi/Playground/Ruby/Pushr/Application/shared/cached-copy"
>>
>> `git status`
=> "# On branch master\nnothing to commit (working directory clean)\n"
>>
>> `git fetch -q nonexistent`
fatal: 'nonexistent': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly
=> ""
>> Dir.pwd
=> "/Users/karmi/Playground/Ruby/Pushr/Application/shared/cached-copy"
>>
>> `git status`
=> "# On branch master\nnothing to commit (working directory clean)\n"
>>
>> `git fetch -q nonexistent 2>&1`
fatal: 'nonexistent': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly
=> ""
@karmi
karmi / sheep_in_your_shoes.rb
Created December 9, 2008 22:52
A simple game with bunch of sheeps and one dog to demonstrate OOP in my tommorow’s lecture
module SheepInYourShoes
# The Pasture
class Pasture
attr_reader :sheep, :dog, :catched
def initialize(num_sheep=0)
@catched = 0
@sheep = []
== Usage
Declare the association in your ActiveRecord model:
picturable_with_flickr
You can then attach/access/destroy your pictures (assuming there's a model +Book+ in your application):
Picturable.search( :text => 'My cute kitten' )
=> #<Flickr::Photos::PhotoResponse:0x300dc5c ... photos[#<Flickr::Photos::Photo:0x2fe6a30 ... @id="1234567890", ...
== Usage
Declare the association in your ActiveRecord model:
picturable_with_flickr
You can then attach/access/destroy your pictures (assuming there's a model +Book+ in your application):
Picturable.search( :text => 'My cute kitten' )
=> #<Flickr::Photos::PhotoResponse:0x300dc5c ... photos[#<Flickr::Photos::Photo:0x2fe6a30 ... @id="1234567890", ...
Let's make a list of Sinatra-based apps!
Apps:
- http://github.com/cschneid/irclogger "Sinatra based irclogger.com"
- http://github.com/rtomayko/wink "minimalist blogging engine"
- http://github.com/foca/integrity "The easy and fun Continuous Integration server"
- http://github.com/sr/git-wiki "git-powered wiki"
- http://github.com/entp/seinfeld "Seinfeld-inspired productivity calendar to track your public github commits."
- http://github.com/karmi/marley "Marley, the blog engine without <textareas>."
- http://github.com/ichverstehe/gaze "Serve up your Markdown files with this tiny Sinatra app!"
# Find all records tagged with a +'tag'+ or ['tag one', 'tag two']
# Pass either String for single tag or Array for multiple tags
def find_all_tagged_with(tag_or_tags)
case tag_or_tags
when Array
all(:include => ['tags', 'taggings']).select { |record| tag_or_tags.all? { |tag| record.tags.map(&:name).include?(tag) } }
when String
all(:include => ['tags', 'taggings']).select { |record| record.tags.map(&:name).include?(tag_or_tags) }
end
end