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 CalendarWeek | |
attr_reader :week, :year, :date | |
private :date | |
def self.current | |
for_date(Date.today) | |
end | |
def self.for_date(date) | |
new(date.year, date.cweek) |
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 Order < ActiveRecord::Base | |
before_validation :generate_order_number, :on => :create | |
class << self | |
def format_order_number(number) | |
number_of_digits = 4 | |
sprintf("#{order_number_prefix}%0#{number_of_digits}u", number) | |
end | |
def order_number_prefix |
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
Here's what happened: | |
- I wanted to create a Gmail account to archive emails for a project. | |
- When I did that, I was logged in under my default (non-Gmail) account – which I wasn't aware of. | |
- Google then decided that the Gmail address would now be the main address for my account and made my previous main address secondary. | |
- There seems to be no way to change it: I can change the secondary address but not the primary one. | |
What I want to do: | |
- split the two addresses (separate passwords and everything) | |
- keep all authentications and such (e.g. Google Docs authentications for the appropriate email) |
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
My Apple MacBook Air 11" (Mid 2012), prime condition (visual and functional) is for sale. | |
Specs: | |
- Core i7-3667U (upgraded, max.) | |
- 8 GB RAM (upgraded, max.) | |
- 256 GB SSD (upgraded) | |
- near-perfect battery (150 cycles) | |
- other specs here: http://en.wikipedia.org/wiki/MacBook_Air#Specifications | |
- including 2 chargers, sleeve, ~1 year of Apple Care (until June 2015) |
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
require 'spec_helper' | |
module MetadataCollector | |
def translate(*args) | |
super.tap do |result| | |
collected_metadata << result.translation_metadata | |
end | |
end | |
def collected_metadata |
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
task :optimize_pngs => 'optimize_pngs:setup' do | |
dir = ENV['DIRECTORY'] || Rails.root.join('app/assets') | |
from_extension = ENV['EXTENSION'] || '-optimize' | |
to_extension = 'd.png' # -2x-optimize.png => -2x-optimized.png | |
speed = ENV['SPEED'] || 1 | |
files = Dir[dir.join("**/*#{from_extension}.png")] | |
options = ["--ext #{to_extension}", "--speed #{speed}"] | |
options << '--verbose' if ENV['VERBOSE'] == '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
{ | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": ["s3:ListBucket" ], | |
"Resource": [ "arn:aws:s3:::BUCKETNAME" ] | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject"], |
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 FogFile | |
def initialize(path) | |
@path = path | |
end | |
def url | |
directory = connection.directories.new(:key => uploader.fog_directory) | |
file = directory.files.new(:key => @path) | |
file.url(::Fog::Time.now + uploader.fog_authenticated_url_expiration) | |
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
url = 'http://example.com/ ?api_token=a-token&username=USERNAME' # => "http://example.com/ ?api_token=a-token&username=USERNAME" | |
url =~ URI.regexp(%w[http https]) # => 0 | |
URI.parse(url) # => URI::InvalidURIError: bad URI(is not URI?): http://example.com/ ?api_token=a-token&username=USERNAME |
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
en: | |
number: | |
format: | |
separator: '.' | |
delimiter: ',' | |
precision: 2 | |
date: | |
input: | |
formats: | |
- :default |