Skip to content

Instantly share code, notes, and snippets.

View igor-alexandrov's full-sized avatar
😀
Ruby, Ruby, Ruby, Ruby... Crystal :)

Igor Alexandrov igor-alexandrov

😀
Ruby, Ruby, Ruby, Ruby... Crystal :)
View GitHub Profile
@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
@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
@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(',')
@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
@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
@ushu
ushu / S3 buckets copy.md
Created October 29, 2013 16:12
Copy between S3 buckets w/ different accounts

This is a mix between two sources:

basically the first resource is great but didn't work for me: I had to remove the trailing "/*" in the resource string to make it work. I also noticed that setting the policy on the source bucket was sufficient. In the end these are the exact steps I followed to copy data between two buckets on two accounts

Basically the idea there is:

  • we allowe the destination account to read the source bucket (in the console for the source account)
  • we log as the destination and start the copy
@evtuhovich
evtuhovich / rmongo.rb
Created December 18, 2012 11:58
Код к докладу "Нетрадиционное использование Ruby и PostgreSQL" http://www.slideshare.net/evtuhovich/ruby-postgresql
require 'rubygems'
require 'pg'
require 'yaml'
class DB
def initialize(debug = true)
@conn = PG::Connection.open()
@debug = debug
end
@maxlapshin
maxlapshin / apache.erl
Created October 11, 2012 07:58
Script to check how many connections can Apache server survive
#!/usr/bin/env escript
-mode(compile).
-compile(export_all).
main([]) -> io:format("Usage: ~s URL [Count=1000]~n", [escript:script_name()]);
main([URL]) -> main([URL,"100"]);
main([URL,C] ) -> manage_workers(URL, [start_worker(URL, N) || N <- lists:seq(1,list_to_integer(C))]), ok.
@mahemoff
mahemoff / elasticsearch.rake
Created September 19, 2012 19:36 — forked from jarosan/elasticsearch.rake
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
# Begins by creating the index using tire:import command. This will create the "official" index name, e.g. "person" each time.
# Then we rename it to, e.g. "person20121001" and alias "person" to it.
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klasses = [Place, Person, Caption]
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active April 2, 2024 14:57
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#