Skip to content

Instantly share code, notes, and snippets.

@rwilcox
rwilcox / passenger_launchd
Created April 27, 2011 13:13
passenger launchd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.wilcoxd.passenger_standalone</string>
<key>ProgramArguments</key>
<array>
<string>/Users/rwilcox/.rvm/bin/radiant_site_ruby</string>
<string>/Users/rwilcox/.rvm/gems/ruby-1.8.7-p299@radiant_site/bin/passenger</string>
@rwilcox
rwilcox / default_html_template_format.rb
Created May 12, 2011 21:19
default_html_template_format.rb
# Create our own FileSystemResolver so that it looks for a .html file to render if
# the (action).(format).erb file is not there. Useful for our MIME alias format.partial -
# instead of needing to create a (something).partial.erb file we can use (something).html.erb
# and use the template for both
#
# In this case (something).partial.erb files will be used if we want to provide something different than
# what the normal partial provides us. WD-rpw 05-12-2011
class DefaultHtmlTemplateFormat < ActionView::FileSystemResolver
@rwilcox
rwilcox / show.js.erb
Created May 20, 2011 12:42
show.js.erb
/* See this in action at: https://github.com/rwilcox/rails_js_representation/blob/master/app/views/todos/show.js.erb */
(function(){
var myobj = {
reallyDue: function() {
if (<%= @todo.new_record? -%>) {
alert("this is a new record");
} else {
alert("old record");
}
@rwilcox
rwilcox / keymando.rb
Created August 9, 2011 12:25
Useful motion commands for Keymando (also, example of command, delete)
# Motion commands
map "<Alt-Delete>", "<Alt-Right><Alt-Delete>" # Delete entire current word
map "<Cmd-Alt-Delete>", "<Cmd-Right><Cmd-Delete>" # Delete entire current line
# Move the current line one line up, or one line down (switch this line with the line currently
# above or below it)
#
# See also: TextMate's Text -> Move Selection -> Line Up (or Line Down)
map "<Cmd-Ctrl-Up>", "<Cmd-Left><Shift-Cmd-Right><Cmd-x><Delete><Up><Return><Shift-Cmd-Left><Delete><Cmd-v>"
map "<Cmd-Ctrl-Down>", "<Cmd-Left><Shift-Cmd-Right><Cmd-x><Delete><Down><Cmd-Right><Return><Shift-Cmd-Left><Delete><Cmd-v>"
@rwilcox
rwilcox / asset_path.rb
Created August 17, 2011 14:39
AssetPath.sass_require: for sharing SASS variables between SASS files in the Rails 3.1 Asset Pipeline
module AssetPath
# Why this instead of Sproket's require_tree?
# Sprokets compiles one SASS file at a time, which works OK... until you want
# to pull out some SASS things (mixins, layout settings) into separate files.
# In that case, you want to have SASS compile everything all at once, in one big file
# So, use this helper to include all the SASS files down a path
#
# The alternative is the ugly (and not DRY!): <http://asciicasts.com/episodes/268-sass-basics>
# where you list every file manually in the application.css.scass file.
@rwilcox
rwilcox / serialized.rb
Created August 27, 2011 19:58
An awesome way forward with serialized attributes
# WITH HASHIE (https://github.com/intridea/hashie)
# ######################################################
class User
before_create :default_preferences_value
serialize :preferences_hash
delegate :full_name, :to => :preferences_hash
delegate :full_name=, :to => :preferences_hash
delegate :timezone, :to => :preferences_hash
@rwilcox
rwilcox / ctags_for_current_project.applescript
Created September 11, 2011 14:36
CTags Applescript for BBEdit
tell application "BBEdit"
-- select the top level item of the project directory
set runcTagsIn to project window 1's selected items
if (runcTagsIn is missing value) or runcTagsIn is {} then
display dialog "plesae select the top level directory!"
end if
set uPath to POSIX path of (item 1 of runcTagsIn)
display dialog "Going to run ctags in " & uPath & ". Is this OK?"
do shell script "cd '" & uPath & "'; /usr/local/bin/bbedit --maketags"
@rwilcox
rwilcox / my_presenter_method.rb
Created September 21, 2011 19:33
presenter_pattern_gone_wrong?
# If the item has one comment, show it, else show the last comment and allow the user to expand
# (yes, a slightly contrived example)
def primary_comment
if self.comemnts.count > 1
"<details class='primary_comment details'><summary><h3>" + self.comments.last.text + " (and #{self.comments.count - 1} others)"
"<ul>"
self.comments.each[0...-1] do |comment|
"<li>" + comment.text + "</li>"
end
else
hello world