This file contains hidden or 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
| require 'right_aws' | |
| namespace :utils do | |
| namespace :attachments do | |
| task :initialize_s3 => :environment do | |
| s3_config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../config/amazon_s3.yml')) | |
| s3_config = s3_config[RAILS_ENV].to_options | |
| @s3 = RightAws::S3.new(s3_config[:access_key_id], s3_config[:secret_access_key]) | |
| end |
This file contains hidden or 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
| var DateHelper = { | |
| // Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time | |
| // Ruby strftime: %b %d, %Y %H:%M:%S GMT | |
| time_ago_in_words_with_parsing: function(from) { | |
| var date = new Date; | |
| date.setTime(Date.parse(from)); | |
| return this.time_ago_in_words(date); | |
| }, | |
| time_ago_in_words: function(from) { |
This file contains hidden or 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
| document.observe("dom:loaded", function() { | |
| function updateElementsWithTime() { | |
| $$("span[time]").invoke('updateTime') | |
| } | |
| // update immediately | |
| updateElementsWithTime() | |
| // continue updating every 2 minutes | |
| new PeriodicalExecuter(updateElementsWithTime, 60 * 2) | |
| }) |
This file contains hidden or 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
| #/usr/bin/ruby | |
| name = 1 | |
| 300.times do | |
| `time dd if=/dev/zero of=#{name}.bin bs=100000 count=1` | |
| name += 1 | |
| end |
This file contains hidden or 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
| # controllers/application.rb | |
| def current_cart | |
| if session[:cart_id] | |
| @current_cart ||= Cart.find(session[:cart_id]) | |
| session[:cart_id] = nil if @current_cart.purchased_at | |
| end | |
| if session[:cart_id].nil? | |
| @current_cart = Cart.create! | |
| session[:cart_id] = @current_cart.id | |
| end |
This file contains hidden or 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
| # Add safe tags to sanitize method | |
| Rails::Initializer.run do |config| | |
| config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' | |
| config.action_view.sanitized_allowed_attributes = 'id', 'class', 'style' | |
| end |
This file contains hidden or 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
| # If cached file exists, serve it and stop processing | |
| RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_FILENAME} -f | |
| RewriteRule ^(.*)$ /cache/%{HTTP_HOST}$1 [L] | |
| # other redirection (imgs, js, css, ...) | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_URI} !.*/mephisto/.* | |
| RewriteCond %{REQUEST_URI} !.*html | |
| RewriteCond %{REQUEST_URI} !^/cache | |
| RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/$1 -f |
This file contains hidden or 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
| # How to set Safari to open links targeted for a new window in a new tab | |
| defaults write com.apple.Safari TargetedClicksCreateTabs -bool true |
This file contains hidden or 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
| # deploy to staging from your current topic branch, with ease | |
| set :branch, "origin/#{`git branch`.scan(/^\* (\S+)/)}" |
This file contains hidden or 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
| SELECT users.`firstname` AS first, | |
| users.`lastname` AS last, | |
| user_details.`birthday` AS birthday | |
| FROM users | |
| LEFT OUTER JOIN user_details ON user_details.user_id = users.id | |
| WHERE | |
| STR_TO_DATE(DATE_FORMAT(birthday,'%m-%d'),'%m-%d') >= STR_TO_DATE(DATE_FORMAT(now(),'%m-%d'),'%m-%d') | |
| AND | |
| STR_TO_DATE(DATE_FORMAT(birthday,'%m-%d'),'%m-%d') < STR_TO_DATE(DATE_FORMAT(now()+INTERVAL 7 DAY,'%m-%d'),'%m-%d'); |