Skip to content

Instantly share code, notes, and snippets.

@chrisyour
chrisyour / web_steps_extended.rb
Created January 17, 2011 02:42
A custom Cucumber web step that looks for existing links
# Cucumber Step
Then /^I should see the link "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
matching_link = nil
with_scope(selector) do
all('a').each do |link|
matching_link = link if link.has_content?(text)
end
end
assert matching_link != nil, "No matching link was found"
end
@chrisyour
chrisyour / Coffeescript.md
Created January 3, 2011 17:17
Possible Ruby ways to write setTimeout methods in CoffeeScript

Possible Ruby ways to write setTimeout methods in CoffeeScript

Ruby:

def start_timer
  setTimeout(time_is_up, 2000)
end

def time_is_up

alert "Time's up!"

@chrisyour
chrisyour / Ruby.coffeescript
Created January 2, 2011 22:58
This would be a nice way to define a method in CoffeeScript...
# The current way to define and run a method in CoffeeScript:
hello = (name) ->
alert 'Hello ' + name
hello 'Chris'
# JavaScript output:
var hello;
@chrisyour
chrisyour / Folder Preferences
Created December 4, 2010 20:05
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
@chrisyour
chrisyour / .bashrc
Created December 2, 2010 22:36
Git Branch Status in the Command Prompt (OSX)
# A minimally beautiful command prompt:
# user: directory (branch):
# Place this in ~/.bashrc
export PS1="\u: \W"'$(__git_ps1 " (%s)")'": "
# Place this is /etc/profile to ensure Terminal sources ~/.bashrc when it launches
[ -r $HOME/.bashrc ] && source $HOME/.bashrc
@chrisyour
chrisyour / ie.sass
Created November 22, 2010 18:36
How to make display:inline-block; compatible with IE 6 and IE 7
// One of the biggest problems with Internet Explorer 6 and 7 is the lack of display:inline-block support.
// I use inline-block all the time. It's very handy. I'm ready to bug test in IE and of course, the main CSS problems
// are with inline-block.
// Using Compass you can remove that pain. Compass has cross-browser support for inline-block.
// Enjoy.
@import "compass/css3/inline-block";
ul{
@chrisyour
chrisyour / enumerable_each_slice.html.erb
Created November 21, 2010 16:50
Display collections of records in groups using Ruby's Enumerable's each_slice method.
# So you have a collection of records you want to display in rows of 3.
# Use Enumerable's each_slice method:
<%= content_tag :div, :class => :thumbs do %>
<% @thumbs.each_slice(3) do |slice| %>
<%= content_tag :div, :class => :thumbs_row do %>
<% slice.each do |thumb| %>
<%= render 'thumb' %>
<% end %>
@chrisyour
chrisyour / Polly.rb
Created November 17, 2010 22:11
My quest to create new Rails 3 Double Sided Polymorphic Gem
# Ok, I'm creating a paired down version of Has_Many_Polymorphs in Rails 3 and making use of Arel. A great way to learn!
# Super simple setup:
class Content < ActiveRecord::Base
polly :parents => :posts, :children => [:images, :paragraphs, :quotes]
end
class Post < ActiveRecord::Base
end
@chrisyour
chrisyour / Test Project.jsfl
Created November 4, 2010 17:15
Flash CS4/CS5 Project Panel: "Test Project" Keyboard Shortcut
// # I've assumed you've downloaded and installed the Flash CS4/CS5 Project Panel update at: http://www.gskinner.com/blog/archives/2010/07/project_panel_u.html
// # 1. Create this file in: /Users/{you}/Library/Application Support/Adobe/Flash CS4/en/Configuration/Commands
// # 2. Then go to Flash => Keyboard Shortcuts...
// # 3. Create your shortcut under the Commands menu, I use 'Cmd+Opt+P'
function call_method(p_panelName, p_function, p_param){
l = fl.swfPanels.length;
if (l == 0) return 'false';
for (i=0; i<l; i++){
(From @wayneeseguin)
This example shows how to setup an environment running Rails 3 beta under 1.9.1 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell))
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.1