Skip to content

Instantly share code, notes, and snippets.

View clemens's full-sized avatar
:octocat:
Getting sh*t done

Clemens Kofler clemens

:octocat:
Getting sh*t done
View GitHub Profile
@clemens
clemens / times
Created July 25, 2013 12:26
Is it just me or is this kind of weird? :) I'm aware that it's due to usecs but it's still "unexpected" ...
>> Date.current.beginning_of_day == Time.local(2013, 7, 25, 0, 0, 0)
Date.current.beginning_of_day == Time.local(2013, 7, 25, 0, 0, 0)
=> true
>> Date.current.end_of_day == Time.local(2013, 7, 25, 23, 59, 59)
Date.current.end_of_day == Time.local(2013, 7, 25, 23, 59, 59)
=> false
@clemens
clemens / deployment-issue
Created July 23, 2013 16:14
Can anyone help?
When trying to deploy with capistrano:
executing "cd /path/to/app/releases/20130723160825 && cat .ruby-version && ruby -v && which bundle"
servers: ["x.x.x.x"]
[x.x.x.x] executing command
** [out :: x.x.x.x] ruby-1.9.3-p448
** [out :: x.x.x.x] ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
** [out :: x.x.x.x] /usr/local/rvm/bin/bundle
command finished in 519ms
* executing "cd /path/to/app/releases/20130723160825 && bundle install --gemfile /path/to/app/releases/20130723160825/Gemfile --path /path/to/app/shared/bundle --deployment --binstubs --without development test"
servers: ["x.x.x.x"]
@clemens
clemens / date_select_with_zero_padding.erb
Created April 23, 2013 10:59
A little snippet if you want zero-padded month numbers with your Rails date_select (e.g. for credit card expiration)
<%= f.date_select :valid_until,
:use_month_names => (1..12).map { |m| sprintf('%02d', m.to_s) },
:order => [:month, :year] %>
Clemens is a freelancer with lots of experience in all things Ruby/Rails and the web in general. When not hacking on code, you'll probably find him working on his culinary skills, reading books about programming and health/fitness/nutrition or pretending to work on his PhD thesis in Marketing.
de:
i18n:
transliterate:
rule:
À: A
Á: A
Â: A
Ã: A
Å: A
Ä: Ae
class Article
define_index do
indexes title
indexes abstract
indexes content
end
end
Article.search("foo", :fields => [:title, :abstract])
@clemens
clemens / news_post.rb
Created September 26, 2012 17:03
Question: Polymorphic has_many through with custom polymorphic type column name
class NewsPost < ActiveRecord::Base
self.table_name = 'newsposts' # old schema; model was called Newspost
has_many :picture_assignments, :as => :owner
has_many :pictures, :through => :picture_assignments
end
NewsPost.first.pictures
# generated SQL:
# SELECT `pictures`.*
@clemens
clemens / key_objects.rb
Created July 2, 2012 15:04
Redis key objects
r = Redis.new(options)
# classic:
r.set('foo', 'bar')
r.get('foo')
r.sadd('baz', 1)
# etc.
# this could be cool:
k1 = r.key('foo')
# download test.jpg from http://www.railway.at/test/test.jpg
# then run the following command
cp test.jpg test1.jpg && time mogrify -rotate "90<" -resize "2000x1500" test1.jpg
# if GraphicsMagick is installed, this would also be helpful:
cp test.jpg test1.jpg && time gm mogrify -rotate "90<" -resize "2000x1500" test1.jpg
# Be careful not to repeatedly run mogrify on the same file because it replaces the file
# so from the second time on it would be faster because the file is smaller.
# This is why the commands above work on copies rather than the original.
# values in this case:
# - columns: 4
# - rows: 3
# - dimensions: an array containing two numbers (potentially floats due to mm to pixels conversion)
# - picture_paths: an array of already cropped pictures
# - target_path: the target path (obviously)
`montage -tile #{columns}x#{rows} -geometry #{dimensions.join('x')}+0+0 #{picture_paths.join(' ')} #{target_path}`