This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getProfileIDs($sortBy, $omitPhotoless) { | |
if($omitPhotoless) { | |
$this->bindModel(array('hasOne' => array('MediaProfile'))); | |
$params = array( | |
'fields' => array('Profile.id'), | |
'conditions' => array( | |
'NOT' => array('MediaProfile.media_id' => null) | |
) | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install rds-command-line-tools | |
rds-create-db-parameter-group mysql-utf8-55 --db-parameter-group-family mysql5.5 --description "MySQL 5.5 configured for UTF-8" | |
rds-modify-db-parameter-group mysql-utf8-55 \ | |
--parameters="name=character_set_server, value=utf8, method=immediate" \ | |
--parameters="name=character_set_client, value=utf8, method=immediate" \ | |
--parameters="name=character_set_results,value=utf8,method=immediate" \ | |
--parameters="name=collation_server, value=utf8_general_ci, method=immediate" \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Countdown.js | |
// A plugin to generate a countdown to a date. | |
// version 1.0, January 2013 | |
// by Andrew Anderson | |
;(function ( $, window, document, undefined ) { | |
var pluginName = "countdown", | |
defaults = { | |
year: "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO `redirects` (`match`, `redirect_to`, `account_id`, `created_at`, `updated_at`) | |
VALUES | |
('/old_page.php', '/new/page', 40, NOW(), NOW()), | |
('/old_page_two.php', '/new/page/two', 40, NOW(), NOW()), | |
('/old_page_three.php', '/new/page-two', 40, NOW(), NOW()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used in a Stylesheet model to import other Stylesheet instances. Compile like this. | |
# The gsub is used to clean out NULL byte characters. | |
# | |
# class Stylesheet < ActiveRecord::Base | |
# include SassImporters | |
# | |
# def compile | |
# compressed_styles = SassC::Engine.new(self.sass.gsub("\u0000", ''), { :importer => DatabaseImporter }).render | |
# end | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Random < ActiveRecord::Base | |
after_initialize :check_data | |
after_initialize :save_data | |
before_save :check_data | |
before_save :save_data | |
private | |
def check_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return Photo.find(params[:photo][:id]) or Photo.new | |
# Valid parameter: instance from database | |
# Invalid parameter: new instance | |
return photo = Photo.find(params[:photo][:id]) and photo.update(comment: params[:photo][:comment]) and photo | |
# Valid ID and successful update: photo instance | |
# Valid ID and failed update: result of update | |
# Invalid ID: nil | |
# Yes, I work in Rails. You got a problem with that?!? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# && | |
puts "test".is_a?(String) && 54+33 # => 87 | |
puts "test".is_a?(String) && true # => true | |
puts 54+33 && "test".is_a?(String) # => true | |
puts true && "test".is_a?(Integer) # => false | |
puts "test".is_a?(Integer) && true # => false | |
# || | |
puts "true" || "test".is_a?(String) # => "true" | |
puts "true".size == 12 || "test".is_a?(String) # => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def odd(n) | |
n%2 != 0 | |
end | |
# Here's what we expect: | |
if a = odd(5) and a == true | |
puts "a is odd" | |
end | |
# => "a is odd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TreeGeneratorOptimized | |
def self.generate_tree | |
pages = all.select('id, name, depth, parent_id, sort_order').order('sort_order ASC') | |
ordered_pages = ActiveSupport::OrderedHash.new | |
parent_hash = Hash.new | |
pages.each do |page| | |
parent_hash[page.parent_id] = Array.new if parent_hash[page.parent_id].nil? | |
parent_hash[page.parent_id].push(page) unless page.nil? | |
end |
OlderNewer