Skip to content

Instantly share code, notes, and snippets.

@wesrog
wesrog / discogs_api_example.rb
Created December 15, 2010 21:40
Simple Discogs Ruby API Client
require 'zlib'
require 'open-uri'
url = "http://www.discogs.com/release/123?f=xml&api_key=111"
headers = {'Accept-Encoding' => 'gzip', 'User-Agent' => 'MyDiscogsClient/1.0 +http://mydiscogsclient.org'}
begin
response = open(url, headers)
begin
data = Zlib::GzipReader.new(response)
@wesrog
wesrog / discogs_api_example.py
Created December 15, 2010 21:15
Simple Discogs Python API Client
import urllib2, gzip, cStringIO
url = 'http://www.discogs.com/release/123?f=xml&api_key=1111'
headers = {'Accept-Encoding': 'gzip', 'User-Agent': 'MyDiscogsClient/1.0 +http://mydiscogsclient.org'}
request = urllib2.Request(url, None, headers)
try:
response = urllib2.urlopen(request)
data = response.read()
try:
class ListItem < ActiveRecord::Base
belongs_to :list
serialize :data
def method_missing(meth)
if list.fields.map { |f| f.name.parameterize.underscore }.include?(meth)
data[meth.to_sym] if data
else
super
end
def public_url_to(resource)
if resource.respond_to?(:slug)
if resource.is_a?(Article)
yield post_url(resource.to_url)
elsif resource.is_a?(Page)
yield page_url(resource.slug)
else
yield resource
end
end
@wesrog
wesrog / sort_itunes_groupings.rb
Created November 10, 2009 16:55
Sort iTunes groupings
def w(t); t.grouping = s(t) unless s?(t); end
def s?(t); t.grouping.to_s == s(t); end
def s(t); t.grouping.to_s.split(', ').sort.join(', '); end
require 'osx/cocoa'
OSX.require_framework 'ScriptingBridge'
a = OSX::SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
l = a.sources.first.playlists.detect { |p| p.name == 'Library' }
l.tracks.each_with_index { |t,i| print "\r\e[0KProcessing: #{i}/#{l.tracks.size}"; w(t); $stdout.flush; }
["1.2.2", "1.2.3", "1.2.5", "1.2.6", "2.0.2", "2.1.0", "2.2.2", "2.3.2", "2.3.3", "2.3.4"]
@wesrog
wesrog / uniq_rails_versions.rb
Created October 29, 2009 03:50
Get Rails versions of apps in a directory
Dir['*'].map { |d| `cat #{d}/config/environment.rb | grep RAILS_GEM_VERSION`.scan(/[\d\.]+/) }.flatten.uniq.sort
LoadModule passenger_module /Users/wes/src/passenger/ext/apache2/mod_passenger.so
PassengerRoot /Users/wes/src/passenger
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
NameVirtualHost *:80
# Added by the Passenger preference pane
# Make sure to include the Passenger configuration (the LoadModule,
# PassengerRoot, and PassengerRuby directives) before this section.
@wesrog
wesrog / gemrc
Created February 16, 2009 22:40
:update_sources: true
:sources:
- http://gems.rubyforge.org/
- http://gems.github.com
:benchmark: false
:bulk_threshold: 1000
:backtrace: false
:verbose: true
gem: --no-ri --no-rdoc
@wesrog
wesrog / lastfm_tagger.rb
Created December 5, 2008 18:28
Last.fm Tagger CLI
# Last.fm Tagger v0.7
#
# Author:
# [email protected]
#
# Abstract:
# For each selected track in iTunes, retrieve the genre from Last.fm and accordingly tag the track.
# Use -q to subdue confirmations
#
# Todo: