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
ActionController::Base.logger.info "[Base] Loading config/initializers/" + File.basename(__FILE__)
class String
def to_permalink
text = self.dup
replacements = {
# replacement special character(s) to be replaced
"A" => [ "À", "Á", "Â", "Ã", "Å"],
"Ae" => [ "Ä", "Æ" ],
"C" => [ "Ç" ],
# config
:number => {
:format => {
:precision => 3,
:separator => '.',
:delimiter => ','
},
:currency => {
:format => {
:unit => '$',
def number_to_human_size(number, *args)
return number.nil? ? nil : pluralize(number.to_i, "Byte") if number.to_i < 1024
options = args.extract_options!
options.symbolize_keys!
defaults, human = I18n.translate([:'number.format', :'number.human.format'], :locale => options[:locale]) || [{},{}]
defaults = defaults.merge(human)
unless args.empty?
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
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'
require 'spec_helper'
module MetadataCollector
def translate(*args)
super.tap do |result|
collected_metadata << result.translation_metadata
end
end
def collected_metadata
@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)
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 / 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
@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)