Skip to content

Instantly share code, notes, and snippets.

@printercu
printercu / gist:9226096
Last active August 29, 2015 13:56
rails 3.2: 400 for malformed request
# config/initializers/action_dispatch_params_parser.rb
# backport from 4.0
module ActionDispatch
class ParamsParser
class ParseError < StandardError
attr_reader :original_exception
def initialize(message, original_exception)
super(message)
@original_exception = original_exception
@printercu
printercu / _media_queries.scss
Created May 13, 2014 04:43
bootstrap media queries
$screen: "only screen" !default;
$landscape: "#(orientation: landscape)" !default;
$portrait: "#(orientation: portrait)" !default;
$xs-up: $screen !default;
$xs-only: "#(max-width: #{$screen-xs-max})" !default;
$sm-up: "#(min-width:#{$screen-sm-min})" !default;
$sm-only: "#(min-width:#{$screen-sm-min}) and (max-width:#{$screen-sm-max})" !default;
@printercu
printercu / plugin.coffee
Last active August 29, 2015 14:05
plugin template
do ($ = jQuery) ->
plugin_name = 'pluginName'
data_index = "#{plugin_name}.instance"
# Example:
#
# $.
$[plugin_name] = class PluginClassName
@init: ->
$('[data-plugin-selector]')[plugin_name]()
@printercu
printercu / class_attribute_bm.rb
Last active August 29, 2015 14:05
Benchmarking thread-safe class_attribute
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)
@printercu
printercu / sql_adapter.php
Created November 7, 2014 09:21
SqlAdapter
<?php
class SqlAdapter
{
protected $pdo;
protected $query;
protected $sth;
protected $params;
protected $lastMethod;
@printercu
printercu / gist:022b0ee5bc3db99cd5bc
Last active December 6, 2016 05:48
Set custom symbol for currency in Money gem
2.2.1 (main):0[1] > Money.new(100, :RUB).currency.symbol
=> "₽"
2.2.1 (main):0[2] > show-method Money.new(100, :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,
@printercu
printercu / marker-clusterer.md
Last active August 15, 2016 17:56
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(
 #{Rails.root}/vendor/assets/google-maps-utility-library-v3
@printercu
printercu / rails-5.0-integration-tests-speedup.md
Last active March 7, 2022 01:20
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
printercu / convert-images.rb
Created January 24, 2017 18:36
Convert svg images to multiple dimensions.
#!/usr/bin/env ruby
#
# For some/file.svg run:
#
# script some/file
#
# Requirement for mac os:
#
# brew cask install inkscape
@printercu
printercu / telegram_bot.rake
Created September 5, 2017 12:05
Telegram::Bot poller with daemons gem
# 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',