Skip to content

Instantly share code, notes, and snippets.

View momolog's full-sized avatar

Alexander Presber momolog

View GitHub Profile
@momolog
momolog / throw-catch-final.rb
Created March 29, 2012 10:09
"valid" action - throw-catch-final
def valid
failure = catch :fail do
code = Code.find_by_value(params[:id]) or throw :fail, 'unknown'
code.unused? or throw :fail, 'used'
nil
end
respond_with({:valid => !failure, :reason => failure}.compact)
end
@momolog
momolog / hash-compact.rb
Created March 29, 2012 10:10
Hash compact
module HashExtensions
def compact
self.reject{|key, value| value.nil? }
end
end
class Hash
include HashExtensions
end
@momolog
momolog / gist:2802574
Created May 27, 2012 07:16
config.yaml
data_sources:
27 -
28 # The type is the identifier of the data source. By default, this will be
29 # `filesystem_unified`.
30 type: filesystem_unified
31 encoding: utf-8
32
33 # The path where items should be mounted (comparable to mount points in
34 # Unix-like systems). This is “/” by default, meaning that items will have
35 # “/” prefixed to their identifiers. If the items root were “/en/”
@momolog
momolog / gist:2802698
Created May 27, 2012 07:53
type error
identical [0.03s] output/projekte/wohnen/tillia/index.html
identical [0.00s] output/projekte/wohnen/tillia_mehr/index.html
identical [0.03s] output/projekte/index.html
identical [0.00s] output/start-1.jpg
identical [0.00s] output/start-2.jpg
identical [0.00s] output/start-3.jpg
identical [0.01s] output/start-4.png
identical [0.00s] output/start-5.png
Captain! We’ve been hit!
From cde3f1f066196f93fe6bfe99801c9138b94447d3 Mon Sep 17 00:00:00 2001
From: Alexander Presber <[email protected]>
Date: Sun, 27 May 2012 12:27:41 +0200
Subject: [PATCH] ido not count dir itself in its entries
---
lib/vfs/entries/dir.rb | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/vfs/entries/dir.rb b/lib/vfs/entries/dir.rb
@momolog
momolog / gist:2803431
Created May 27, 2012 10:45
compile error
aljoscha :) % bundle exec nanoc co /Users/aljoscha/rails/nanoccer
Loading site data...
Compiling site...
Captain! We’ve been hit!
=== MESSAGE:
ArgumentError: undefined class/module ActiveSupport::
@momolog
momolog / gist:4088112
Created November 16, 2012 15:18
verbose checks
@saved_referer ||= if params[:to].present?
params[:to]
elsif session[:return_to_after_login]
session.delete(:return_to_after_login)
else
request.referer
end
@momolog
momolog / gist:4088140
Created November 16, 2012 15:21
short checks
@saved_referer ||= params[:to].presence || session.delete(:return_to_after_login) || request.referer
@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
@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) }