Skip to content

Instantly share code, notes, and snippets.

View redis_stats.rb
class RedisStats
attr_reader :redis, :pattern
def initialize(redis, pattern = '*')
@redis = redis
@pattern = pattern
def all_keys
@all_keys ||= [].tap do |result|
printercu / policy.rb
Last active Mar 5, 2018
Policy like in cancan, but with class-level declarations
View policy.rb
# Simple policy implementation. Like a mixin of Pundit and CanCan.
module Policy
index: :read,
show: :read,
new: :create,
edit: :update,
class Error < StandardError; end
printercu /
Last active Oct 13, 2020
Turbolinks adapter for vue
printercu / telegram_bot.rake
Created Sep 5, 2017
Telegram::Bot poller with daemons gem
View telegram_bot.rake
# lib/capistrano/tasks/telegram_bot.rake
namespace :telegram do
namespace :bot do
namespace :poller do
start: 'start an instance of the application',
stop: 'stop all instances of the application',
restart: 'stop all instances and restart them afterwards',
reload: 'send a SIGHUP to all instances of the application',
printercu / convert-images.rb
Created Jan 24, 2017
Convert svg images to multiple dimensions.
View convert-images.rb
#!/usr/bin/env ruby
# For some/file.svg run:
# script some/file
# Requirement for mac os:
# brew cask install inkscape
printercu /
Last active Jan 29, 2017
Speed up Rails 5 integration tests

Speed up integration tests in Rails 5 app

Rails 5 recompiles templates on every request in test env. Fix will be released only in 5.0.2.

Add this lines to test helper to get the performance now (I've got x2 improvement):

class << ActionView::LookupContext::DetailsKey
  def clear
printercu /
Last active Aug 15, 2016
Keep MarkerClusterer working after Google shut down svn-repos

First we’ll configure Rails, assuming you already have a copy of google-maps-utility-library-v3 in your repo. If you don’t have it yet, there are instructions in the bottom.

Most likely, you already have added utility folder to the assets pipeline:

# config/initializer/assets.rb
Rails.application.config.assets.paths += %W(
printercu / gist:022b0ee5bc3db99cd5bc
Last active Dec 6, 2016
Set custom symbol for currency in Money gem
View gist:022b0ee5bc3db99cd5bc
2.2.1 (main):0[1] >, :RUB).currency.symbol
=> "₽"
2.2.1 (main):0[2] > show-method, :RUB).currency.symbol
From: /Users/max/.rvm/gems/ruby-2.2.1/gems/money-6.5.1/lib/money/currency.rb @ line 211:
Owner: Money::Currency
Visibility: public
Number of lines: 3
attr_reader :id, :priority, :iso_code, :iso_numeric, :name, :symbol,
View sql_adapter.php
class SqlAdapter
protected $pdo;
protected $query;
protected $sth;
protected $params;
protected $lastMethod;
printercu / class_attribute_bm.rb
Last active Aug 29, 2015
Benchmarking thread-safe class_attribute
View class_attribute_bm.rb
require 'benchmark'
require 'active_support/all'
class Class
def class_attribute2(*attrs)
options = attrs.extract_options!
instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
instance_predicate = options.fetch(:instance_predicate, true)