Skip to content

Instantly share code, notes, and snippets.

View unicornrainbow's full-sized avatar
💖
🎈Sharing codes 🔫🛍🛁📐🎉💉🕳🚬💎💰💳

Rashiki Grace unicornrainbow

💖
🎈Sharing codes 🔫🛍🛁📐🎉💉🕳🚬💎💰💳
  • Newstime
  • Daytona Beach, FL
View GitHub Profile
@unicornrainbow
unicornrainbow / rails_template.tmproj
Created January 15, 2011 19:59
My textmate project template for rails apps.
<?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>currentDocument</key>
<string>public/javascripts/init.js</string>
<key>documents</key>
<array>
<dict>
@unicornrainbow
unicornrainbow / application.rb
Created January 27, 2011 00:01
Set flash message by convention with i18n
class ApplicationController < ActionController::Base
# Sets a flash message based on locale.
def set_flash(key, options = {})
case key
when :notice, true
flash[:notice] = flash_message(:notice, options)
when :error, false
flash[:error] = flash_message(:error, options)
else
raise ArgumentError.new "Unrecognized flash key: #{key}"
@unicornrainbow
unicornrainbow / remove_project_trailing_whitespace.sh
Created January 27, 2011 16:17
A shell function to auto remove whitespace from an entire rails project in one shot.
remove_project_trailing_whitespace () {
for file in * (app|config|test|lib|public)/**/*.(rb|js|sass|css|yml|md|txt|erb|haml|config)
do
sed -i "" 's/[[:space:]]*$//' ${file}
sed -i "" -e :a -e '/^\n*$/N;/\n$/ba' ${file}
done
}
@unicornrainbow
unicornrainbow / bookmark.rb
Created January 27, 2011 20:06
Open up a failing test in testmate from terminal.
#! /usr/bin/env ruby
require 'yaml'
require 'term/ansicolor'
include Term::ANSIColor
# Usage:
# > rake test | bookmark # => Bookmark test output
# > bookmark 1 # => Open first failing test.
# > bookmark 2 # => Open second failing test.
@unicornrainbow
unicornrainbow / get.rb
Created January 30, 2011 17:35
Get at properties of values that might not be present with out checking for nil.
# Usage:
# nil.get :blake # => nil
# some_obj.get :name, :length # => The value of some_obj.name.length or nil
class Object
def get(*properties)
object = self
properties.each do |property|
if object.respond_to?(property)
object = object.send(property)
else
@unicornrainbow
unicornrainbow / gist:808298
Created February 2, 2011 19:55
Negating assertions
def assert_not(test, msg = (nomsg = true; nil))
nomsg ? assert(!test) : assert(!test, msg)
end
@unicornrainbow
unicornrainbow / gist:930146
Created April 20, 2011 01:25
Profile $(this) vs $this
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jQuery $this Test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#test1").click(function(){
var t0 = new Date
@unicornrainbow
unicornrainbow / env.rb
Created April 27, 2011 22:39 — forked from bru/env.rb
monkey patch to fix webrat follow redirect behaviour with rails 3
# features/support/env.rb
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
@unicornrainbow
unicornrainbow / syntax_highlighting.py
Created August 8, 2011 20:42 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@unicornrainbow
unicornrainbow / in.rb
Created September 21, 2011 04:03
Ruby #in method.
# in extension to object.
#
class Object
# Returns true if the object sent #in is included in the argument list.
#
# Usage in conditionals:
#
# if 1.in 1, 2, 3
# puts "1 was included"
# end