Skip to content

Instantly share code, notes, and snippets.

View timriley's full-sized avatar
🇺🇦
Standing with Ukraine

Tim Riley timriley

🇺🇦
Standing with Ukraine
View GitHub Profile
//parent-fact/entry/pods/item[@id=$current-id]/preceding-sibling::item[position() = 1]/text()
@timriley
timriley / README.md
Created May 5, 2010 03:57
Handy little class for attaching arbitrary media files

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.

@timriley
timriley / gist:454635
Created June 27, 2010 04:27
Backup a photoset from flickr
#!/usr/bin/env ruby
require 'rubygems'
require 'flickraw'
require 'fileutils'
require 'open-uri'
YOUR_API_KEY = 'xxx'
SET_TO_BACKUP = 'yyy'
@timriley
timriley / gist:482620
Created July 20, 2010 06:52
Convert PNGs to JPGs
for file in `ls *.png`; do
newfile=`echo $file | sed -e 's/\.png$/\.jpg/'`
echo "converting: $file -> $newfile"
convert $file -quality 70 $newfile
done
@timriley
timriley / gist:633357
Created October 19, 2010 00:34
Association Extensions & Named Scopes
# 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
<ul>
<% User.all.with_item_counts do |user| %>
<li><%= user.username %> - Items: <%= user.calculated_item_count %>
<% end %>
</ul>
#pagelet_netego_lower,
#home_sponsor_nile,
.showIfOffline,
.ego_section,
.fbEmuEgoUnit,
.fbEmuEgoUnitFirst,
#pagelet_presence,
#chatFriendsOnline
{
display: none !important;
@timriley
timriley / gist:1446347
Created December 8, 2011 07:06
How to override Rack middleware so it doesn't run in certain circumstances
module Rack
class DeflaterWithExclusions < Deflater
def initialize(app, options = {})
@app = app
@exclude = options[:exclude]
end
def call(env)
if @exclude && @exclude.call(env)