Skip to content

Instantly share code, notes, and snippets.

View igor-alexandrov's full-sized avatar
😀
Ruby, Ruby, Ruby

Igor Aleksandrov igor-alexandrov

😀
Ruby, Ruby, Ruby
View GitHub Profile
@aishek
aishek / deploy.rb
Last active December 27, 2015 08:58
Sidekiq Capistrano extension to use different sidekiq_processes on different hosts. Disadvantage of using this extension is sequental only commands execution (no parallel execution support).
require 'sidekiq/capistrano'
load 'config/deploy/extensions/sidekiq' # required to be after require 'sidekiq/capistrano'
set :sidekiq_role, :sidekiq
role :sidekiq, 'server1.com', 'server2.com'
# you may use default syntax – same number of processes at all hosts
# set :sidekiq_processes, 1
# or use hash notation to specify host-dependent number of processes
@ernie
ernie / delegate.rb
Last active May 31, 2016 10:39
An alternate take on the delegation class macro provided by ActiveSupport. Updated with Ruby 2.0's caller_locations.
#!/usr/bin/env ruby
class Module
private
def delegate(*args)
dest, prefix = _extract_valid_delegation_options(args.pop)
_define_delegators(caller_locations.first, prefix, dest, args)
end
@devishot
devishot / mini_magick#get_dominant_color.rb
Last active August 29, 2015 13:57
example of how to convert image to "-format %c histogram:info:" (http://www.imagemagick.org/Usage/files/#histogram) by gem "mini_magick". It used below to get dominant color of image by this solution for ImageMagick http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12033
require "mini_magick"
module MiniMagick
class Image
def get_dominant_color
color = run_command("convert", path, "-format", "%c\n", "-colors", 1, "-depth", 8, "histogram:info:").split(' ');
# color = " 1764000: (208,195,161) #D0C3A1 srgb(208,195,161)\n\n"
{
hex: color[2],
rgb: color[1][1..-2].split(',')
@fran-worley
fran-worley / Example 1
Last active March 28, 2017 19:42
Some Reform/dry-v examples
class FieldForm < Reform::Form
property :key
collection :field_options, form: FieldOptionForm
validation do
configure do
option :form # include this line if you want access to your form in predicates
config.messages_file = 'config/error_messages.yml' # if you define any custom predicates you must provide a message for them
@cjgajard
cjgajard / app.cr
Last active September 12, 2019 08:20
Kemal controllers pattern
# src/{{app_name}}.cr
require "kemal"
require "./controllers/*"
alias Env = HTTP::Server::Context # this could be provided by Kemal
module Main
get "/", &->index(Env)
get "/:name", &->greet(Env)
end