Skip to content

Instantly share code, notes, and snippets.

View clemens's full-sized avatar
:octocat:
Getting sh*t done

Clemens Kofler clemens

:octocat:
Getting sh*t done
View GitHub Profile
@clemens
clemens / calendar_week.rb
Created November 24, 2014 15:36
A simple class wrapping a calendar week
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)
@clemens
clemens / order.rb
Created November 10, 2014 10:27
Generating unique order numbers with a year prefix
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
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)
@clemens
clemens / gist:eb04462668cdaebf4991
Created October 1, 2014 13:56
MacBook Air 11" (Mid 2012)
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)
require 'spec_helper'
module MetadataCollector
def translate(*args)
super.tap do |result|
collected_metadata << result.translation_metadata
end
end
def collected_metadata
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'
@clemens
clemens / minimum_rights_policy.json
Created September 5, 2014 09:39
Minimum rights policy for S3 that works just fine with CarrierWave/Fog
{
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket" ],
"Resource": [ "arn:aws:s3:::BUCKETNAME" ]
},
{
"Effect": "Allow",
"Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject"],
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
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
@clemens
clemens / delocalize-psych-example.yml
Created August 6, 2014 18:16
Example pulled from the delocalize readme for Ruby 1.9 compatible YAML formatting
en:
number:
format:
separator: '.'
delimiter: ','
precision: 2
date:
input:
formats:
- :default