Skip to content

Instantly share code, notes, and snippets.

For <http://bjeanes.com/2009/10/01/code-formatting-in-rss-feeds>:
Firstly, please don't limit your feed to just excerpts. Clicking through to read content is annoying at best (more clicks) and impossible at worst (i.e. offline).
Inline styling of the feed content is a much better idea but still not the best. Markup should be semantic (your current code block are not IMO) and feed readers may not even respect user styles.
I think the markup needs to be fixed so it makes sense semantically. I'm thinking it should be a normal <pre/> with <span/>s for style hooks. To add line numbers, wrap each line in <code/> so we can style each line (unless I'm missing a way to write a selector to match all lines a la ::first-line).
I have quickly thrown together a proof of concept, tested in Safari 4 only. It's roughly styled like your blog with the <pre/> code generated by the TextMate.tmbundle but with manually added <code/> tags. The styling is a good candidate for SASS with all the calculations.
raise "Check if this is still needed on #{Rails.version}" unless Rails.version == '2.3.5'
# <https://rails.lighthouseapp.com/projects/8994/tickets/3208-belongs_to-with-primary_key-does-not-work-with-finds-include>
# this should hopefully be fixed in 2.3.6. Untested on 3.0.
# can't easily patch the output of association_join via a alias_method_chain
# so the whole method is replaced here with the one line fix applied
module ActiveRecord::Associations::ClassMethods
class JoinDependency
class JoinAssociation
class Hash
def selekt
inject({}) {|hsh,(k,v)|
hsh[k] = v if yield(k,v)
hsh
}
end
end
@jasoncodes
jasoncodes / config.ru
Created May 18, 2010 11:29 — forked from toolmantim/config.ru
Serving simple static sites using Rack
# Rackup file for serving up a static site from a "public" directory
#
# Useful for chucking a static site on Heroku
class IndexRewriter
def initialize(app) @app = app end
def call(env)
env["PATH_INFO"].gsub! /\/$/, '/index.html'
@app.call(env)
end
@jasoncodes
jasoncodes / github_clone_all_public.rb
Created June 11, 2010 20:30
A quick script to clone all your public repos on GitHub
#!/usr/bin/env ruby
require 'net/http'
require 'yaml'
username = `git config github.user`.strip
if username.empty?
$stderr.puts "Please set github.user in your git config: https://github.com/account"
exit 1
#!/usr/bin/env ruby
# A couple of Searchlogic searches. Both are identical from a code
# perspective. With one, the user supplies a '.' (period) as part of the
# search query. This search blows up because it's generating an invalid SQL
# statement. I say it shouldn't. The error in question is:
#
# Mysql::Error: Not unique table/alias: 'users':
#
# SELECT `companies`.`id` AS t0_r0,
@jasoncodes
jasoncodes / disable_mass_assignment.rb
Created August 17, 2010 09:52
Noisy protected attributes (mass-assignment security)
ActiveRecord::Base.send(:attr_accessible, nil)
module ActionView::Helpers::FormTagHelper
def date_field(object_name, method, options = {})
ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("date", options.merge(:size => nil))
end
end
class ActionView::Helpers::FormBuilder
def date_field(method, options = {})
@template.send(
"date_field",
@jasoncodes
jasoncodes / README.markdown
Created October 6, 2010 11:16
Run VMware Fusion headless at Mac OS system startup

Run VMware Fusion headless at Mac OS system startup.

I heard you like headless VMs on your Mac so I wrote this script for your launchds.

Assumptions

  • Tested on Mac OS X 10.6.4 with VMware Fusion 2.0.5 and 3.1.1.
  • A interactive user automatically logs into the system at startup. I had some issues trying to get this running without an interactive user logged in. I automatically log in for Airfoil Speakers anyway.
  • Your virtual machines live in /Virtual Machines
@jasoncodes
jasoncodes / example.rb
Created January 19, 2011 02:39
Example usage of `composed_of`.
class Example < ActiveRecord::Base
composed_of :input_voltage,
:class_name => 'VoltageRange',
:mapping => [%w(input_voltage_min min), %w(input_voltage_max max)],
:allow_nil => true,
:converter => :new
composed_of :output_voltage,
:class_name => 'VoltageRange',