Skip to content

Instantly share code, notes, and snippets.

View unnu's full-sized avatar

Norman Timmler unnu

  • Hamburg, Germany
View GitHub Profile
@unnu
unnu / keybase.md
Last active August 29, 2015 14:03

Keybase proof

I hereby claim:

  • I am unnu on github.
  • I am unnu (https://keybase.io/unnu) on keybase.
  • I have a public key whose fingerprint is D83B 6A5E 898D 47B8 CEB0 EEB9 C418 0309 9657 1BDA

To claim this, I am signing this object:

@unnu
unnu / paperclip_redis.rb
Created December 10, 2012 21:20
Paperclip Redis Storage
module Paperclip::Storage::Redis
def self.extended(base)
base.instance_eval do
@options[:path] = ":class/:attachment/:id_partition/:style/:filename"
@options[:url] = "/dynamic/:class/:attachment/:id_partition/:style/:filename"
@redis = Redis.new
end
end
@unnu
unnu / variable_scope.rb
Created February 3, 2012 13:47
More ruby scope bewares
class A
def foo
1
end
def beware_1
puts "beware_1"
p foo # -> 1
foo = foo
@unnu
unnu / ruby_scope_problem.rb
Created February 3, 2012 12:04
Why is foo returning nil in last line?
$ irb
ruby-1.9.3-p0 :001 > def foo
ruby-1.9.3-p0 :002?> 1
ruby-1.9.3-p0 :003?> end
=> nil
ruby-1.9.3-p0 :004 > foo
=> 1
ruby-1.9.3-p0 :005 > if false
ruby-1.9.3-p0 :006?> foo = 2
ruby-1.9.3-p0 :007?> end
class A
def self.hello
p 'hello'
end
def class
(class << self; self; end)
end
end
@unnu
unnu / gist:1379254
Created November 19, 2011 19:30
Ringbuffer Implementation with Eventmachine
require 'rubygems'
require 'eventmachine'
require 'fiber'
class TcpReceiver < EM::Connection
attr_accessor :blocker
def initialize(receiver)
@receiver = receiver
super
@unnu
unnu / gist:1303319
Created October 21, 2011 07:49
JRuby ThreadPoolExecutor with FutureTask showcase
require 'java'
# setup executor
java_import 'java.util.concurrent.ThreadPoolExecutor'
java_import 'java.util.concurrent.TimeUnit'
java_import 'java.util.concurrent.LinkedBlockingQueue'
java_import 'java.util.concurrent.FutureTask'
java_import 'java.util.concurrent.Callable'
core_pool_size = 5
@unnu
unnu / gist:1084701
Created July 15, 2011 13:37
Growl Logger for Rails Debug
if Rails.env.development?
GROWL = Growl.new("127.0.0.1", "ruby-growl", ["ruby-growl Notification"])
GROWL.class_eval do
def log(object)
GROWL.notify "ruby-growl Notification", "AskWhat Debug", object.inspect
Rails.logger.debug { object.inspect }
end
end
end
@unnu
unnu / Textmate File- and Folderpattern
Created September 8, 2010 07:18
Textmate Folder and File Patterns
File Pattern:
!\.(log)|\.(sp?)|(/\.(?!htaccess)[^/]*|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
Folder Pattern:
!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|db/data.*|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
@unnu
unnu / gist:437422
Created June 14, 2010 08:10
Dotted progress bar for shell scripts
require 'stringio'
class Progress
def initialize(show)
@device = StringIO.new unless show
end
def device
@device ||= $stdout