Skip to content

Instantly share code, notes, and snippets.

@scaint
scaint / form_tag_helper.rb
Last active May 9, 2018 14:40
Removing "utf8=✓" from url in Rails. Put this file to app/helpers directory.
module FormTagHelper
# see http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-utf8_enforcer_tag
def utf8_enforcer_tag
''.html_safe
end
end
@scaint
scaint / gist:8691054
Created January 29, 2014 15:59
An approach to emulate Array::map for single objects
# Using instance_eval
# Time: 0.267886376
Benchmark.measure do
1000000.times { 1.instance_eval { self+1 } } # => 2
end
# Using tap+break
# Time: 0.304528147
Benchmark.measure do
1000000.times { 1.tap { |o| break o+1 } } # => 2
@scaint
scaint / gist:7779227
Created December 3, 2013 23:02
Using pushState instead of hash
App.Router.reopen({
location: 'history'
});
@scaint
scaint / gist:7156430
Created October 25, 2013 15:21
Capistrano 3 tasks for Unicorn
set :unicorn_config, -> { current_path.join('config/unicorn.rb') }
set :unicorn_pid, -> { shared_path.join('tmp/pids/unicorn.pid') }
namespace :unicorn do
desc 'Stop Unicorn'
task :stop do
on roles(:app) do
if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, capture(:cat, fetch(:unicorn_pid))
end
@scaint
scaint / prompt.sh
Created June 16, 2013 09:34
Show the current Git branch in Bash prompt
#Based on https://github.com/jimeh/git-aware-prompt
find_git_branch() {
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch=" ($branch)"
else
git_branch=""
@scaint
scaint / gist:5706321
Created June 4, 2013 14:24
Shortcut for the Capistrano `deploy` task :)
echo 'alias "поехали!"="bundle exec cap deploy"' >> ~/.bashrc