Skip to content

Instantly share code, notes, and snippets.

View remvee's full-sized avatar

Remco van 't Veer remvee

  • 52°N, 5°E
View GitHub Profile
@remvee
remvee / twit.el
Created September 24, 2008 07:36
Emacs interface for twitter.com
;;; Twit.el --- interface with twitter.com
;; Copyright (c) 2007 Theron Tlax
;; (c) 2008 Jonathan Arkell
;; Time-stamp: <2007-03-19 18:33:17 thorne>
;; Author: thorne <[email protected]>, jonnay <[email protected]>
;; Created: 2007.3.16
;; Keywords: comm
;; Favorite Poet: E. E. Cummings
@remvee
remvee / gist:24951
Created November 14, 2008 15:40
bookmarklet to fix line-height for current page
javascript:(function(){var%20d=document;t=d.createElement(%22style%22);t.appendChild(d.createTextNode(%22*{line-height:2}%22));d.getElementsByTagName(%22head%22)[0].appendChild(t)})();
@remvee
remvee / font-zoom.el
Created February 24, 2009 08:53
font-zoom.el
;; Font zooming with Hyper--/=/0 for Mac
;; Inspired by: http://www.emacswiki.org/cgi-bin/wiki/CycleFontSizes
(defconst font-zoom-list
(mapcar (lambda (n) (format "-*-monaco-*-*-*-*-%d-*-*-*-*-*-*-*" n)) '(6 8 10 13 17 18 24 36 48)))
(defconst default-font-zoom-index 3)
(defvar font-zoom-index default-font-zoom-index)
(defun font-zoom-increase-font-size ()
@remvee
remvee / gist:131946
Created June 18, 2009 15:12
thank god for tests
--- a/app/controllers/security.rb
+++ b/app/controllers/security.rb
@@ -10,7 +10,7 @@ module Security
# Ensure somebody is logged in. Takes the same options as
# +before_filter+.
def authenticate(options = {})
- before_filter options.dup { |controller| controller.send(:authenticate) }
+ before_filter(options.dup) { |controller| controller.send(:authenticate) }
end
@remvee
remvee / elf_proef.rb
Created November 19, 2009 11:32
validate dutch social security and bank numbers
# Methods to validate dutch social security numbers
# (burgerservicenummer) and back account numbers
# (bankrekeningnummers) using the "elf proef".
module ElfProef
def valid_burgerservicenummer?(val)
num = val.to_s.scan(/\d/).join.to_i
return false if num == 0
digits = ("%09d" % num).split(//).map(&:to_i).reverse
return false unless digits.size == 9
@remvee
remvee / deploy.rb
Created November 23, 2009 09:03
cap avoid too fast restart of mongrel-cluster
namespace :deploy do
task :start, :roles => :app do
sudo "mongrel_rails cluster::start -C #{mongrel_conf}"
end
task :stop, :roles => :app do
sudo "mongrel_rails cluster::stop -C #{mongrel_conf}"
y = {
"port" => 3000, "servers" => 2, "pid_file" => "tmp/pids/mongrel.pid"
@remvee
remvee / autocomplete_select.js
Created December 4, 2009 14:25
JS onchange hack for input[type=hidden]
// make sure you call field.fire('hidden:change') when a hidden field changes
document.observe('dom:loaded', function() {
$$('input[type=hidden]').each(function(e) {
var onchange = e.getAttribute('onchange')
if (onchange) {
if (typeof(onchange) != 'function') {
eval("onchange = (function(event){(function(){" + onchange + "}).bind(Event.element(event))()});");
}
e.observe('hidden:change', onchange);
}
@remvee
remvee / application.js
Created December 4, 2009 15:42
JS App.with_resource
// Usage: App.with_resource('user', 567, function(user) { $('report_user_name').value = user.name })
var App = {
with_resource: function(name, id, func) {
new Ajax.Request("/" + name + "s/" + id + ".json", {
method: 'GET',
onSuccess: function(transport) { func(transport.responseJSON[name]) }
});
}
}
@remvee
remvee / with_scopes.rb
Created December 8, 2009 11:34
combine scopes from a hash
# Allow query usings scopes and arguments from a hash. Useful for
# making index actions.
#
# Example:
#
# User.with_scopes(:search => "Fred")
#
# Where +search+ is a named scope on +User+ which excepts a parameter.
module WithScopes
# Determine if named scope exists.
@remvee
remvee / post.rb
Created December 24, 2009 13:11
Simple all words named_scope
# Matches posts containing all words in the body.
named_scope :search, lambda { |q|
if connection.adapter_name == 'MySQL'
q = q.split(/\W/).map{|q| "[[:<:]]#{Regexp.escape(q)}[[:>:]]"}
{:conditions => [(['posts.body REGEXP ?'] * q.size).join(" AND "), *q]}
else
raise NotImplementedError
end
}