Skip to content

Instantly share code, notes, and snippets.

View twe4ked's full-sized avatar
🐦
just setting up my twttr

Odin twe4ked

🐦
just setting up my twttr
View GitHub Profile
@twe4ked
twe4ked / application_controller.rb
Created April 29, 2010 04:40
One idea for giving devise's controllers their own layout
# How to give your devise controllers all the same layout (e.g. "authentication" below)
class ApplicationController < ActionController::Base
layout :setup_layout
def setup_layout
return "authentication" if
[ConfirmationsController, PasswordsController, SessionsController,
RegistrationsController, UnlocksController].include? self.class
"application"
end
# Send email to MockSMTP
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 1025,
:domain => "localhost"
}
# link_to 'Foo', bar_path, :class => active_link?('some_controller', 'some_action')
# link_to 'Foo', bar_path, :class => active_link?('some_controller') # Active anywhere within the controller
def active_link?(controller, action = nil)
action_match = case
when action.nil? then true
when action.is_a?(Array) then action.include? params[:action]
else action == params[:action]
end
params[:controller] == controller && action_match ? 'active ' : ''
- if Rails.env.development?
%link{:rel => 'shortcut icon', :href => "/favicon.ico?#{(100..200).to_a.shuffle[1]}"}
@twe4ked
twe4ked / 0_selector_hacks.scss
Created September 21, 2011 12:00 — forked from chriseppstein/0_selector_hacks.scss
This gist demonstrates some uses of the new sass feature: Passing content blocks to mixins.
@mixin ie6 { * html & { @content } }
#logo {
background-image: url("/images/logo.png");
@include ie6 { background-image: url("/images/logo.gif"); }
}
@twe4ked
twe4ked / input.scss
Created December 5, 2011 06:27
FREE! Sass (SCSS) mixin for including retina images (useful when developing for iOS).
@mixin background-image-retina($file, $type, $width, $height) {
background-image: url($file + '.' + $type);
@media (-webkit-min-device-pixel-ratio: 2), (-moz-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
}
}
}
@twe4ked
twe4ked / input.scss
Created December 20, 2011 04:43
FREE! Sass (SCSS) mixin for easily setting the width and height (size) and an element.
@mixin size($width, $height: $width) {
width: $width;
height: $height;
}
// Examples
#foo {
@include size(10px);
}
@twe4ked
twe4ked / twitter_list.rb
Created March 26, 2012 06:26
Simple, slow script to add Twitter users to a list.
# Written in a taxi on the way to Railscamp X
require 'twitter'
Twitter.configure do |config|
config.consumer_key =
config.consumer_secret =
config.oauth_token =
config.oauth_token_secret =
end
@twe4ked
twe4ked / chosen.rb
Created May 8, 2012 00:38
Testing chosen with RSpec.
def search_chosen(selector, search)
page.execute_script "jQuery('#{selector}').click();"
find('div.chzn-search input').set search
end
def select_from_chosen(selector, name)
page.execute_script "jQuery('#{selector}').click();"
page.execute_script "jQuery(\".chzn-results .active-result:contains('#{name}')\").click();"
wait_for_ajax
end