Skip to content

Instantly share code, notes, and snippets.

@estum
estum / table-responsive.coffee
Last active August 29, 2015 13:56
Improved responsive tables for Bootstrap 2
# ==============================================
# = Improved responsive tables for Bootstrap 2 =
# ==============================================
#
# Add .table-responsive to enable this feature for tables.
# Change $.fn.tableResponsive.defaults.media_query to support other devices.
class TableResponsive
provide_uniq_id = (table) ->
table.id ?= "table-responsive-#{ just.genuniq() }"
# config/initializers/unauthorized_cross-origin_response_fix.rb
#
# Fixes unauthorized cross-origin response problem for .js templates (problem description in Russian http://habrahabr.ru/post/209618/)
# in Ruby On Rails 3.2, idea and code extracted from https://github.com/rails/rails/blob/4f4fdd643f9d19fbbeeec3ac77674f791c9beffa/actionpack/lib/action_controller/metal/request_forgery_protection.rb
#
# for Rails 4 just save https://raw2.github.com/rails/rails/4f4fdd643f9d19fbbeeec3ac77674f791c9beffa/actionpack/lib/action_controller/metal/request_forgery_protection.rb
# to config/initializers/unauthorized_cross-origin_response_fix.rb
#
# for Rails 4.1 there is https://github.com/rails/rails/pull/13345)
@estum
estum / .pryrc.rb
Last active December 27, 2015 20:39
Custom "reload!" command for pry, which just restarts rails. Works with non-rails projects.
# .pryrc
Pry::Commands.create_command "reload!" do
description "Exits and runs again pry process"
def process
target.eval <<-EVAL
at_exit { puts "Reloading pry..."; exec "pry" }
exit
EVAL
@estum
estum / passenger.rb
Created September 5, 2013 04:38
Capistrano task which generates nginx passenger config
# -- config/passenger.rb
# require this file in the config/deploy.rb
Capistrano::Configuration.instance.load do
# Config template path (config/passenger/template.nginx.conf)
set :template_path, File.expand_path('../passenger/template.nginx.conf', __FILE__)
# Upload config to:
set :config_deploy_path, "#{deploy_to}/config/nginx_passenger.conf"
@estum
estum / dsl.rb
Last active December 21, 2015 14:59
Bundler::DSL extension to provide OS-depended gems in Gemfile
# lib/bundler/dsl.rb
# Bundler::DSL extension to provide OS-depended gems in Gemfile
# https://github.com/bundler/bundler/wiki/Platform-as-a-parameter
#
# Allows to group os-dependent gems in blocks with one or more symbols, strings or regexps as parameters.
# OS name is obtained from `RbConfig::CONFIG['host_os']` or `RUBY_PLATFORM` if the first one is not available.
#
# Place this file in the project's lib folder and require it in your Gemfile:
# require File.expand_path('../lib/bundler/dsl', __FILE__)
@estum
estum / user.rb
Last active December 21, 2015 05:49
Migrate passwords from legacy systems to Devise
# updated variant of older solution:
# http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise
class User < ActiveRecord::Base
# ...
def valid_password?(password)
if legacy_password?
# Use Devise's secure_compare to avoid timing attacks
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))