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
<ul>
<% @users.each do |user| %>
<li>
<%= user.name %>
<% if (orders = user.orders_in_timespan(@start_date, @end_date)).any? %>
<ul>
<% orders.each do |order| %>
<li><%= order.number %></li>
<% end %>
</ul>
@clemens
clemens / 1_redis_sorted_set_ranking_changes.rb
Created July 3, 2012 16:14
Redis sorted set ranking changes
redis.zadd('scores:20120701', 10, 'alice')
redis.zadd('scores:20120701', 7, 'bob')
redis.zadd('scores:20120701', 5, 'carol')
# resulting ranking:
# 1 - alice
# 2 - carol
# 3 - bob
redis.zadd('scores:20120702', 7, 'alice')
redis.zadd('scores:20120702', 9, 'bob')
h = { a: 1, b: 2 }
def foo(a:, b:)
[a, b]
end
foo(h) #=> [1, 2]
@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"],
module Trailblazer; end
module My; end
class Trailblazer::Operation
def self.inherited(klass)
*mod_names, klass_name = klass.name.split('::')
mod = const_get(mod_names.join('::'))
mod.define_singleton_method(klass_name) do |*args|
@clemens
clemens / resque_retry.rb
Created June 24, 2011 09:51
Retry failed Resque jobs in Ruby
# inspired by http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
end
# retry all :)
Resque::Failure.count.times do |i|
tmp[master]% convert logo.jpg -format png -colorspace srgb -profile ../vendor/profiles/sRGBColorSpaceProfile.icm logo.png
tmp[master]% rm logo.png
tmp[master]% cp logo.jpg logo.png
tmp[master]% mogrify -format png -colorspace srgb -profile ../vendor/profiles/sRGBColorSpaceProfile.icm logo.png
mogrify: improper image header `../vendor/profiles/sRGBColorSpaceProfile.icm' @ error/png.c/ReadPNGImage/3981.
@clemens
clemens / product.rb
Created April 17, 2011 21:27
Faster Sphinx facets
class Product < ActiveRecord::Base
define_index do
# rest of the index ...
has merchant_id
has merchant.company, :as => :merchant_name, :type => :string
has brand_id, :type => :integer
has brand.name, :as => :brand_name, :type => :string
2016-08-01T09:24:58.489044+00:00 heroku[router]: at=info method=GET path="/" host=example.com request_id=e8e2f6a9-b50b-4054-8efc-fb35457558e6 fwd="192.168.0.1" dyno=web.1 connect=0ms service=16ms status=302 bytes=1389
@keyframes animation-1 {
/* whatever */
}
@keyframes animation-2 {
/* whatever */
}
@keyframes animation-3 {
/* whatever */