Skip to content

Instantly share code, notes, and snippets.

View boyvanamstel's full-sized avatar
👋
Hi there

Boy van Amstel boyvanamstel

👋
Hi there
View GitHub Profile
@boyvanamstel
boyvanamstel / gist:992838
Created May 26, 2011 09:32
Prevent error on first load in Heroku when using Compass and Sass
# in config/environments/production.rb
Compass.configuration.sass_options={:never_update=>true}
@boyvanamstel
boyvanamstel / gist:994910
Created May 27, 2011 09:13
Rails custom configuration options
# Source: http://stackoverflow.com/questions/592554/best-way-to-create-custom-config-options-for-my-rails-app
# For general application configuration that doesn't need to be stored in a database table, I like to create a
# config.yml file within the config directory. For your example, it might look like this:
defaults: &defaults
audiocast_uri_format: http://blablalba/blabbitybla/yadda
development:
<<: *defaults
@boyvanamstel
boyvanamstel / gist:1001987
Created June 1, 2011 08:35
MediaWiki .gitignore
# Ignore everything
/*
# Except .gitignore
!.gitignore
# Except for database, uploads, extensions and settings
!/mediawiki
mediawiki/*
@boyvanamstel
boyvanamstel / gist:1008969
Created June 5, 2011 13:42
Change Rails table field name
# http://stackoverflow.com/questions/1992019/how-to-rename-a-database-column-in-rails-using-migration
# $ rails g migration FixColumnName
# db/migrate/xxxxxxxxxx_fix_column_name.rb
class FixColumnName < ActiveRecord::Migration
def self.up
rename_column :table_name, :old_column, :new_column
end
@boyvanamstel
boyvanamstel / gist:1055880
Created June 30, 2011 08:52
Show custom post types on tag, category and archive pages in Wordpress
<?php
/**
* Also show custom post types in tag/category/archive pages
*/
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type) {
$post_type = $post_type;
} else {
@boyvanamstel
boyvanamstel / gist:1056310
Created June 30, 2011 14:11
Allow extra elements (iframe) in TinyMCE in Wordpress
<?php
/**
* Allow extra elements in TinyMCE
*/
add_filter('tiny_mce_before_init', create_function( '$a',
'$a["extended_valid_elements"] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]"; return $a;') );
?>
@boyvanamstel
boyvanamstel / gist:1069215
Created July 7, 2011 09:57
Test::Unit test for valid url and implementation of valid url testing in Rails
# Test in test/functional/sites_controller_test.rb
test "should contain a valid url" do
@site.url = "random text"
assert @site.invalid?
end
# Implementation in app/models/site.rb
class Site < ActiveRecord::Base
validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
end
@boyvanamstel
boyvanamstel / gist:1069221
Created July 7, 2011 10:02
Test::Unit test for unique property in Rails
# Test in test/functional/sites_controller_test.rb
test "should be unique" do
link1 = sites(:one)
link1.save
link2 = Site.new(sites(:two))
link2.url = link1.url
assert !link2.save, "Saved a link with the same url"
end
# Implementation in app/model/site.rb
@boyvanamstel
boyvanamstel / gist:1069227
Created July 7, 2011 10:05
User fixtures for Devise in Rails
boy:
id: 1
email: boy@email.com
encrypted_password: 4567554354
sign_in_count: 10
barry:
id: 2
email: barry@email.com
encrypted_password: 4567554354
@boyvanamstel
boyvanamstel / events_controller_test.rb
Created July 7, 2011 10:08
Enabling Devise testing in Rails
class EventsControllerTest < ActionController::TestCase
setup do
@event = events(:one)
sign_in users(:boy)
end
end