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
# Using aws-sdk gem | |
@access_key = "access_key" | |
@secret_key = "secret_access_key" | |
@bucket = "my_bucket" | |
AWS.config( | |
:access_key_id => @access_key, | |
:secret_access_key => @secret_key | |
) |
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
# Loader for infinite time | |
["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} while 1 | |
# In case you want to run it for a few seconds (~ 20s in the example below) | |
10.times{ ["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} } | |
# Progress Bar | |
100.times{STDOUT.write "|"; sleep 0.1} | |
# Another kind of loading indicator |
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 url_for_oauth_code(options = {}) | |
# for permissions, see http://developers.facebook.com/docs/authentication/permissions | |
permissions = options[:permissions] | |
scope = permissions ? "&scope=#{permissions.is_a?(Array) ? permissions.join(",") : permissions}" : "" | |
display = options.has_key?(:display) ? "&display=#{options[:display]}" : "" | |
callback = options[:callback] || @oauth_callback_url | |
raise ArgumentError, "url_for_oauth_code must get a callback either from the OAuth object or in the options!" unless callback |
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 Link < ActiveRecord::Base | |
validate :url_presence | |
def url_presence | |
errors.add(:base, "#{Link.url_label(linktype)} can't be blank.") if url.blank? | |
end | |
def self.url_label(linktype) | |
{"web" => "Web URL", "video" => "Video URL", "audio" => "Audio URL", "ecommerce" => "Shop URL", | |
"page" => "Page number", "email" => "Email"}[linktype] || "URL" |
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
Ruby aws-sdk has poor documentation, and I wasn't able to locate it as well. Below is a function that I have created to check whether a file has read permission or not. Modify it as per your needs: | |
def check_if_public_read(object) | |
object.acl.grants.each do |grant| | |
begin | |
if(grant.grantee.uri == "http://acs.amazonaws.com/groups/global/AllUsers") | |
return true if ([:read, :full_control].include?(grant.permission.name)) | |
end | |
rescue | |
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
credentials = YAML.load_file("#{Rails.root}/config/s3.yml") | |
@access_key = credentials[Rails.env]["access_key_id"] | |
@secret_key = credentials[Rails.env]["secret_access_key"] | |
@bucket = credentials[Rails.env]["bucket"] | |
AWS.config( | |
:access_key_id => @access_key, | |
:secret_access_key => @secret_key | |
) | |
@s3 = AWS::S3.new |
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
<script type="text/javascript"> | |
var timer; | |
window.addEventListener("pageshow", function(evt){ | |
clearTimeout(timer); | |
}, false); | |
window.addEventListener("pagehide", function(evt){ | |
clearTimeout(timer); | |
}, false); |
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
{ | |
"Version": "2008-10-17", | |
"Id": "PolicyForCloudFrontPrivateContent", | |
"Statement": [ | |
{ | |
"Sid": "1", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "Enter your CloudFront Origin Access Identity here" | |
}, |
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
# To get the created at timestamp | |
sample_object.id.generation_time | |
# To do range queries | |
start = Moped::BSON::ObjectId.from_time(Time.now.beginning_of_day) | |
finish = Moped::BSON::ObjectId.from_time(Time.now.end_of_day) | |
MyModel.where(:id => {'$gt' => start, '$lt' => finish}).count |
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
// Install required modules as below: | |
npm install -g db-migrate | |
npm install -g db-migrate-mysql | |
// Create a database.json file: | |
{ | |
"development": { | |
"driver": "mysql", | |
"host": "localhost", |
OlderNewer