Skip to content

Instantly share code, notes, and snippets.

@bricker
bricker / sessions.py
Created June 21, 2012 21:43
Simple PyYAML constructor for handling Ruby Flash Hash
# Simple PyYAML constructor for handling Ruby Flash Hash
# Not perfect or graceful - just takes the Ruby Flash object
# and the Set object inside of it, and nullifies them.
# This could be expanded to handled different tags.
# If you wanted to maintain the Ruby objects across requests,
# or use convert a Ruby object to a Python object, you'll
# need something a little more complex, but this should get
# you started.
@bricker
bricker / application.html.erb
Created June 21, 2012 22:47
Simple breadcrumbs for Rails
<!-- Simple breadcrumbs for Rails -->
<!-- Example output -->
<!-- This example uses the Twitter Bootstrap classes for breadcrumbs -->
<!-- http://twitter.github.com/bootstrap/components.html#breadcrumbs -->
<% if breadcrumbs %>
<ul class="breadcrumb">
<% breadcrumbs.each do |crumb| %>
<li>
@bricker
bricker / example.rb
Created June 21, 2012 23:43
Ruby + Lyris HQ (EmailLabs) - A basic Ruby wrapper for the Email Labs API
# Ruby + Lyris HQ (EmailLabs) - A basic Ruby wrapper for the Email Labs API
# Example usage.
# Message is an imaginary object that you'll have to setup
@message = Message.new(email_subject: "Welcome to My Website!", body: "Welcome to My Website! You can browse blog entries, and watch videos, and much more! Thanks for joining! -The Management" email_sent: false>
lyris = Lyris.new(@message)
if lyris.add_message and lyris.send_message
@message.update_column(:email_sent, true)
@bricker
bricker / rails_centOS_setup.mdown
Created July 8, 2012 06:37
Get a Rails app running on vanilla CentOS (5 or 6) via Nginx & Passenger in minutes

Setup RVM/Ruby, Nginx/Passenger, and Rails in minutes on vanilla CentOS (5 or 6)

July 1, 2012

Based on articles at http://articles.slicehost.com/centos

This gist only covers the steps that are necessary to get a Rails app running quickly via RVM, nginx and Passenger. It disregards security in many cases (such as RVM & iptables)! Go through the articles above for more on that.

Please note that I wrote this after I had already got it all working, so I apologize if

@bricker
bricker / has_secure_attribute.rb
Created July 10, 2012 04:34
has_secure_attribute, a smarter `has_secure_password` for Rails.
# This is a modified versions of Rails' built-in `has_secure_password`
# It allows you to do the same thing to any attribute.
# Useful for legacy databases, credit card information, addresses, etc.
# Use it pretty much the same way you would use has_secure_password
# You can also use any name for the digest column,
# just pass in an :encrypted_attribute option:
#
# has_secure_attribute :credit_card_number, encrypted_attribute: :ccn_hash
#
@bricker
bricker / 2012071301_replace_tags_in_nokogiri.mdown
Created July 13, 2012 22:49
Replacing tags inside of a Nokogiri Node

Replacing tags inside of a Nokogiri Node

July 13, 2012

I recently had some trouble trying to figure out how to do a simple gsub to the innner_html of a Nokogiri node. My problem was that I was trying something like this:

# Does not work!
document.at_css('p.content').inner_html.gsub!(/\n/, "<br />")
@bricker
bricker / 2012071401_symbols_vs_strings.mdown
Created July 15, 2012 06:38
The difference between symbols and strings in Ruby

The difference between symbols and strings in Ruby

July 14, 2012
1.9.3p0 :032 > :something.object_id
 => 4300488 
1.9.3p0 :033 > :something.object_id
 => 4300488 
1.9.3p0 :034 > :something.object_id
 =&gt; 4300488 
@bricker
bricker / 2012071901_interpolation_shorthand.mdown
Created July 19, 2012 23:21
Accidental Discovery: Interpolation shorthand in Ruby

Accidental Discovery: Interpolation shorthand in Ruby

July 19, 2012

I type in Textmate all day long. One of things its Ruby bundle does is auto-complete the string interpolation syntax for you. If you're inside of double-quotes (or a few other cases where string interpolation is possible), and you hit the # (hash) key, it writes #{} and places your cursor between the curly-brackets.

So, sometimes when I'm testing things in IRB, I forget that it doesn't auto-complete things like Textmate does. The result? Accidentally discovering a shorthand for string interpolation:

@name = "World"
puts "Hello #@name."
@bricker
bricker / 2012073001_rails_dbsync.mdown
Created July 30, 2012 22:08
Rails: Synchronizing your development database with your production database using Rake tasks

Rails: Synchronizing your development database with your production database using Rake tasks

July 30, 2012

If you run an active website with lots of new content every day, it's often helpful to keep your local database up-to-date with your production database, so when you're working on the application locally you're working with fresh content.

Here are a couple rake tasks that you can copy-and-paste into your local Rails application which will make this syncing process a one-step process.

@bricker
bricker / 2012070101_making_django_and_rails_play_nice.mdown
Created July 30, 2012 22:43
Making Django and Rails play nice: Part 2 (part 2)

Making Django and Rails play nice: Part 2 (part 2)

July 1, 2012

A few months ago, former KPCC developer Eric Richardson posted a fantastic solution to a seemingly simple problem: How do you share sessions between a Rails application and a Django application?

The issue: Ruby and Python serialize objects using different libraries (Marshal and Pickle, respectively).