Skip to content

Instantly share code, notes, and snippets.

# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
app = Rack::Builder.new do
map "/ping" do
run lambda { |_env| [200, {'Content-Type' => 'text/plain'}, ['pong']] }
end
map "/" do
@kml
kml / i18n.coffee
Created May 20, 2016 18:43
Simple I18n implementation for JavaScript
# Example usage:
# I18n.t("application.hello")
# I18n.t("hello", scope: "application")
# Application.t("hello")
#
# Application.t("missing")
# Error: translation missing: pl.application.missing
#
# I18n.locale = "ru"
# Application.t("hello")
@kml
kml / rails-boot-default-options.rb
Last active December 13, 2016 22:36
config/boot.rb with changed rails server defaults
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup'
require "rails/commands/server"
Rails::Server.class_eval do
def default_options
super.merge(Port: 3000, Host: "127.0.0.1")
end
end
@kml
kml / .ruby-version
Last active August 5, 2016 08:56
NestedAttributes
2.3.1
@kml
kml / assets-nginx.conf
Last active February 26, 2016 20:48
Custom proxy cache server for assets speedup in *development* environment.
# Custom proxy cache server for assets speedup in *development* environment.
#
# Usage:
# Foreground (for tests):
# nginx -c $(pwd)/assets-nginx.conf -g 'daemon off; error_log stderr;'
#
# Background:
# nginx -c $(pwd)/assets-nginx.conf
# nginx -c $(pwd)/assets-nginx.conf -s <SIGNAL>
# signals: stop, quit, reopen, reload
@kml
kml / virtus_attribute_coercer_call_patch.rb
Last active December 13, 2016 22:51
Don't raise and rescue exception - just check
# encoding: utf-8
# Source: https://gist.github.com/kml/da4f7cf70008986b3ba5
# Issue: https://github.com/solnic/coercible/issues/16
require "virtus/attribute/coercer"
# Coercible::Coercer::Object#to_string doesn't know how to coerce nil
# https://github.com/solnic/virtus/blob/master/lib/virtus/attribute/coercer.rb#L31
# encoding: utf-8
# Source: https://gist.github.com/kml/349d3ae1716e6500cbee
# Benchmark: https://gist.github.com/kml/0fb1588fc1b6ba4c60fa
# Issue: https://github.com/solnic/coercible/pull/22
# https://github.com/solnic/coercible/blob/master/lib/coercible/coercer/object.rb#L163
require "coercible"
if Coercible::VERSION != "1.0.0"
# encoding: utf-8
# Usage:
# jruby coercible_coercer_object_method_missing_patch_bench.rb
# jruby coercible_coercer_object_method_missing_patch_bench.rb patch
# Issue: https://github.com/solnic/coercible/pull/22
if $0 == __FILE__
require "bundler/inline"
@kml
kml / active_support_disable_circular_references_check.rb
Last active November 10, 2015 09:31
Remove circular references protection in ActiveSupport::JSON::Encoding::Encoder
# encoding: utf-8
# Source: https://gist.github.com/kml/3395d73d874b0c302224
# https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/json/encoding.rb
require "active_support/json/encoding"
unless defined?(ActiveSupport::JSON::Encoding::CircularReferenceError)
abort "#{__FILE__}: CircularReferenceError is not defined. Remove this patch!"
end
# encoding: utf-8
phrase = "sterownik".force_encoding("utf-8")
regexp = /(?i-mx:^bram[ay])|(?i-mx:(prz[e??]s[l??][ao]|element)[a-z??????]* ogrodz[a-z??????]*)|(?i-mx:(sterowniki?|automatyka).*\bbramy?)|(?i-mx:^tralk[ai])|(?i-mx:bojlery?|pojemno.ciow[ey])|(?i-mx:[a-z]+grzewacze? wody)/
puts phrase.match(regexp).inspect
=begin
UTF8Encoding.java:35:in `length': java.lang.ArrayIndexOutOfBoundsException: 9
from BaseUTF8Encoding.java:91:in `mbcToCode'