Skip to content

Instantly share code, notes, and snippets.

View dpsk's full-sized avatar
🏠
Working from home

Mikhail Nikalyukin dpsk

🏠
Working from home
View GitHub Profile
@dpsk
dpsk / Wunderlist2.alfredextension
Created December 28, 2012 10:33
Wunderlist2 remove local database, so old extensions don't work anymore. Here is the one that will work with Wunderlist2.
on alfred_script(q)
set the clipboard to q
tell application "System Events"
tell application "Wunderlist" to activate
tell process "Wunderlist"
click menu item "Add New Item" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
@dpsk
dpsk / my_params_parser.rb
Created December 14, 2012 15:01
Catch Invalid XML error in ActionDispatch::ParamsParser
if defined?(ActionDispatch)
class MyParamsParser < ActionDispatch::ParamsParser
def call(env)
super
rescue REXML::ParseException
[400, {"Content-Type" => "application/xml"}, ["Invalid Request"]]
end
end
end
@dpsk
dpsk / partially_valid.rb
Created September 25, 2012 12:31
Partially validate model attributes. Good for multi-step wizards form without saving record on each step.
module PartiallyValidatable
extend ActiveSupport::Concern
included do
def self.partially_valid?(params, valid=true)
mock = self.new(params)
params.each{|attr, _| valid = false if mock.errors.messages[attr.to_sym].present?} unless mock.valid?
valid
end
@dpsk
dpsk / deploy.rb
Created July 5, 2012 12:42 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# Capistrano configuration
#
# require 'new_relic/recipes' - Newrelic notification about deployment
# require 'capistrano/ext/multistage' - We use 2 deployment environment: staging and production.
# set :deploy_via, :remote_cache - fetch only latest changes during deployment
# set :normalize_asset_timestamps - no need to touch (date modification) every assets
# "deploy:web:disable" - traditional maintenance page (during DB migrations deployment)
# task :restart - Unicorn with preload_app should be reloaded by USR2+QUIT signals, not HUP
@dpsk
dpsk / contenteditable_change.js.coffee
Created February 10, 2012 07:33
contenteditable change event emulation
$ ->
# contenteditable change event
$("[contenteditable]").live("focus", ->
$this = $(this)
$this.data "before", $this.html()
$this
).live "blur keyup paste", ->
$this = $(this)
if $this.data("before") isnt $this.html()
$this.data "before", $this.html()
@dpsk
dpsk / gist:1533526
Created December 29, 2011 10:59
Prime from 1 to N
# prime.rb
limit = Integer(ARGV.shift || 1000)
primes = []
#list all numbers
for i in 2 .. limit
primes[i] = i
end
@dpsk
dpsk / gist:1471991
Created December 13, 2011 12:37 — forked from moro/gist:1024620
Kaminari and pushState
(function($){
$('.pagination a[data-remote=true]').live('ajax:success', function(e){ window.history.pushState('', '', $(e.target).attr('href')) })
$(window).bind('popstate', function(){ $.ajax({url:window.location, dataType:'script'}) ; return true });
})(jQuery);
@dpsk
dpsk / deffered_garbage_collection.rb
Created December 7, 2011 10:55
speed up RSpec tests by patcihng Ruby GC. 600 specs, time fall from 490 secs to 240(ruby 1.9.3)
RSpec.configure do |config|
config.before(:all) do
DeferredGarbageCollection.start
end
config.after(:all) do
DeferredGarbageCollection.reconsider
end
end
# Русский перевод для https://github.com/plataformatec/devise/tree/v1.4.7
# Другие переводы на http://github.com/plataformatec/devise/wiki/I18n
ru:
errors:
messages:
expired: "устарела. Пожалуйста, запросите новую"
not_found: "не найдена"
already_confirmed: "уже подтверждена. Пожалуйста, попробуйте войти в систему"
not_locked: "не заблокирована"
@dpsk
dpsk / gist:1422624
Created December 2, 2011 10:03
quiet_assets.rb
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
alias_method_chain :call, :quiet_assets