Code examples for openmonkey.com article "Rails Label Helpers with Blocks".
Example for comment on openmonkey.com article "Rails Label Helpers with Blocks".
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
//parent-fact/entry/pods/item[@id=$current-id]/preceding-sibling::item[position() = 1]/text() |
Handy little class for attaching arbitrary media files (images, audio, video, etc.) to events in a timeline application. It does a couple of nifty things for supporting the varying media types:
The before_post_process
method ensures we attempt to generate thumbnails only for images.
The named scopes along with the set_item_type
callback gives us a way to pull out media items of a certain type, without having to go down the often more-trouble-than-it's-worth STI path.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'flickraw' | |
require 'fileutils' | |
require 'open-uri' | |
YOUR_API_KEY = 'xxx' | |
SET_TO_BACKUP = 'yyy' |
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
for file in `ls *.png`; do | |
newfile=`echo $file | sed -e 's/\.png$/\.jpg/'` | |
echo "converting: $file -> $newfile" | |
convert $file -quality 70 $newfile | |
done |
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
# This is how I would like the models | |
# | |
# Order has an extension on its order_transactions association to return the total amount of all the transactions | |
# | |
# I want to call this extension method while modifying the association via a named scope, but it doesn't work (see below). | |
class OrderTransaction < ActiveRecord::Base | |
scope :purchases, where(:action => 'purchase') | |
scope :refunds, where(:action => 'credit') | |
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
<ul> | |
<% User.all.with_item_counts do |user| %> | |
<li><%= user.username %> - Items: <%= user.calculated_item_count %> | |
<% end %> | |
</ul> |
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
#pagelet_netego_lower, | |
#home_sponsor_nile, | |
.showIfOffline, | |
.ego_section, | |
.fbEmuEgoUnit, | |
.fbEmuEgoUnitFirst, | |
#pagelet_presence, | |
#chatFriendsOnline | |
{ | |
display: none !important; |
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 Rack | |
class DeflaterWithExclusions < Deflater | |
def initialize(app, options = {}) | |
@app = app | |
@exclude = options[:exclude] | |
end | |
def call(env) | |
if @exclude && @exclude.call(env) |