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
# generate random sequence | |
#SecureRandom also has methods for: base64, hex, bytes, random_number | |
#see: http://api.rubyonrails.org/classes/ActiveSupport/SecureRandom.html | |
require 'active_support/secure_random' | |
ActiveSupport::SecureRandom.hex(16) | |
# outputs: 6dc19d21e958e04645cddadb96e9c927 |
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
log/*.log | |
.DS_Store | |
public/cache/**/* | |
public/system/**/* | |
config/database.yml | |
config/*.sphinx.conf | |
config/s3_credentials.yml | |
*~ | |
*.cache | |
*.pid |
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
SHOW CREATE TABLE old_table; | |
INSERT INTO new_table SELECT DISTINCT * FROM old_table; | |
DROP TABLE old_table; | |
RENAME TABLE new_table TO old_table; |
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
# polymorphic_select_tag @item, :owner, Post.all(:order=>'created_at DESC').collect{|b| #[b.title, [Post, b.id]]} | |
def polymorphic_select_tag(object, field, option_array=[], options={}, html_options={}) | |
option_tags = "<option #{'selected="selected"' if (object.try(field) == nil)}/>" + | |
option_array.map do |tuple| | |
"<option value='#{tuple[1][0]}-#{tuple[1][1]}' #{'selected="selected"' if ((object.try(field).try(:id).to_s == tuple[1][1].to_s && object.try(field).try(:type).to_s == tuple[1][0].to_s) rescue false)}>#{tuple[0]}</option>" | |
end.to_s | |
prefix = options[:prefix] || '' | |
object_id = object.id |
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
IO.popen("ruby -v").readlines.to_s |
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
# raw get_bread_crumb(request.request_uri) | |
def get_bread_crumb(url) | |
begin | |
breadcrumb = '' | |
so_far = '/' | |
elements = url.split('/') | |
for i in 1...elements.size | |
so_far += elements[i] + '/' |
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
namespace :db do | |
desc "Backup database" | |
task :backup => :environment do | |
db_config = ActiveRecord::Base.configurations[Rails.env] | |
backup_path = "db/backups" | |
Dir.mkdir("#{Rails.root}/#{backup_path}") unless Dir.exist?("#{Rails.root}/#{backup_path}") | |
datestamp = Time.now.strftime("%Y%m%d%H%M%S") | |
file_name = "#{RAILS_ENV}_#{db_config['database']}_#{datestamp}.sql.gz" |
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 create_method(name, &block) | |
self.class.send(:define_method, name, &block) | |
end | |
def create_attr_methods(name) | |
create_method("#{name}=".to_sym) { |val| instance_variable_set("@" + name, val) } | |
create_method(name.to_sym) { instance_variable_get("@" + name) } | |
end | |
def create_attr(name, value = nil) |
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
Gchart.line_xy( | |
:data => [[-1], [5.6401944, 5.693536, 5.589820899999999, 5.9419287999999995, 6.140745299999999, 5.6134203, 4.6947865, 4.3917905, 3.969158, 6.6177003, 5.5682765, 5.3081125], [-1], [4.469642, 4.398298800000001, 4.4974612, 4.5136058, 4.7888061, 4.619375999999999, 1.2265295, 2.977351, 3.2739, 4.8158845, 4.4618883, 4.4220661], [-1], [4.3555019999999995, 4.215306200000001, 4.2568991, 5.3902482, 5.4936451, 4.6054233, 2.781287, 1.945629, 2.80498, 5.7298489, 4.2575779, 4.2970867], [-1], [3.0365569999999997, 3.1637157, 2.8597486, 3.3726310999999995, 3.1634554, 3.1847927, 1.9845335, 1.8754915, 1.9770175, 3.7286499, 3.2215343, 2.8594553], [-1], [2.6395803000000004, 2.5640393999999995, 2.3002405, 2.7694116999999996, 2.9414337, 2.7909993, 1.578009, 0.617353, 2.0158055, 3.0155125, 2.4871983, 2.3391488], [-1], [2.4379844, 2.2451725999999996, 2.0674406999999997, 2.6068367, 2.4240726, 2.3331188, 1.242108, 1.1643645, 1.4375965, 2.9311815, 2.6668297, 2.2688855], [-1], [2.2926647000000004, 2.2747717, 2.7112956, |
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
-------------------------------------------------- | |
-------------------------------------------------- | |
-- Import tasks from Things to OmniFocus | |
-------------------------------------------------- | |
-------------------------------------------------- | |
tell application "Things" | |
-- Loop through ToDos in Things | |
repeat with aToDo in to dos of list "Next" | |
OlderNewer