Skip to content

Instantly share code, notes, and snippets.

View momolog's full-sized avatar

Alexander Presber momolog

View GitHub Profile
@momolog
momolog / gist:7680823
Created November 27, 2013 18:34
add remote
[remote "fast"]
url = git@heroku.com:capetimes-fast.git
fetch = +refs/heads/*:refs/remotes/capetimes-fast/*
@momolog
momolog / 400 vs 500 explanation
Last active December 23, 2015 20:29
400 vs 500
Controller action expecting certain input.
In case the input is not provided, the first version will fail with a 500 exception,
a stack trace and an airbrake notification.
But this is just invalid input and not an error for us to care about.
Instead, like the second version, it should just return nothing and a status code
400 (Bad Request), effectively telling the user agent, that
1) This is your fault, your URL / input data is wrong
#! env bash
EXCLUDED='(master|staging)$'
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
@momolog
momolog / gist:5967027
Created July 10, 2013 14:58
Different ways to bind procs, depending on ruby version and whether you work with ActiveSupport.
class A
LAMB1 = lambda{ do_it }
LAMB2 = proc{ do_it }
def do_it
puts "AAA"
end
end
class B
@momolog
momolog / backtrace
Created May 8, 2013 21:43
Backtrace for Net::SSH error while transfering a binary file via SFTP
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:284:in `block in write'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:284:in `each'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:284:in `write'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:322:in `block in write_string'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:319:in `each'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:319:in `write_string'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:55:in `block in from'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/net/ssh/buffer.rb:47:in `step'
from /Users/aljoscha/.rvm/gems/ruby-1.9.3-p392/gems/net-ssh-2.6.7/lib/
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@momolog
momolog / gist:4533330
Created January 14, 2013 20:53
rails error after running nanoc gem
2013-01-13T23:58:04+00:00 app[web.1]: Started GET "/dashboard/" for 78.52.196.102 at 2013-01-13 23:58:04 +0000
2013-01-13T23:58:04+00:00 app[web.1]:
2013-01-13T23:58:04+00:00 app[web.1]: NoMethodError (undefined method `formats' for "index":String):
2013-01-13T23:58:04+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/renderer/template_renderer.rb:14:in `render'
2013-01-13T23:58:04+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/renderer/renderer.rb:36:in `render_template'
@momolog
momolog / gist:4161748
Created November 28, 2012 14:48
array section operator
if (node[:scalarium][:instance][:roles] & %w(rails-app media-encoding)).any?
@momolog
momolog / gist:4161744
Created November 28, 2012 14:47
explicit array section
if node[:scalarium][:instance][:roles].any?{|role| %w(rails-app media-encoding).include?(role) }
@momolog
momolog / gist:4088156
Created November 16, 2012 15:24
shorter checks
@saved_referer ||= params.get(:to) || session.delete(:return_to_after_login) || request.referer