Skip to content

Instantly share code, notes, and snippets.

View skorfmann's full-sized avatar

Sebastian Korfmann skorfmann

View GitHub Profile
@skorfmann
skorfmann / spider.rb
Created November 28, 2010 13:31
spider.rb
require 'rubygems'
require 'anemone'
count = 0
Anemone.crawl("http://www.immobilienscout24.de/immobiliensuche/wohnen-auf-zeit/nordrhein-westfalen.htm", :storage => Anemone::Storage.TokyoCabinet("/tmp/spidr.tch")) do |anemone|
anemone.focus_crawl do |page|
page.links.select do |link|
link.request_uri =~ /(wohnen-auf-zeit)|(\/\d+$)/
def is_a_power_of_two?(n)
return false if n.is_a?(Float)
(n-1)& n == 0 if n != 0
end
def logb2(n)
if is_a_power_of_two?(n)
return n.to_s(2).match(/1(0*)/)[1].length
else
false
@skorfmann
skorfmann / brew-doctor.sh
Created January 21, 2011 12:15
brew install qemu
~/ ruby-1.9.2@fashmob_poc $ brew doctor
You can install Homebrew anywhere you want, but some brews may only work
correctly if you install to /usr/local.
@skorfmann
skorfmann / application_helper.rb
Created February 11, 2011 10:28
force format temporary in views
module ApplicationHelper
def with_format(format, &block)
old_formats = formats
lookup_context.send(:_set_detail, :formats, [format])
result = capture(&block)
lookup_context.send(:_set_detail, :formats, old_formats)
return result
end
end
@skorfmann
skorfmann / gist:1189736
Created September 2, 2011 20:05 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
Day job: Web-Engineering (Ruby on Rails, Freelancer)
Favorite Python project: Django
Favorite Conference: euruko
Python Experience Level: few test-drives
require 'rubygems'
require 'faster_csv'
require 'net/http'
require 'open-uri'
class String
require 'iconv' #this line is not needed in rails !
def to_utf8
Iconv.conv('utf-8','ISO-8859-1', self)
end
@skorfmann
skorfmann / gist:4958466
Created February 15, 2013 03:52
Lastminute Rubyconf Ticket
Due to changes in my travel plans, I have to sell my ticket for Rubyconf Australia.
I got my ticket in the first batch at the early-bird price.
If you wanna buy the ticket get in touch with me: [email protected]
Price: 495 AUD
class Invitation < ActiveRecord::Base
belongs_to :invitable, primary_key: :email, foreign_key: :invitable_id, class_name: 'User'
end
class User < ActiveRecord::Base
has_many :invitations, :primary_key, :email, foreign_key: :invitable_id
end
user = User.create(email: '[email protected]')
invitation = Invitation.create(invitable: user)
@skorfmann
skorfmann / speedtest.md
Last active December 14, 2015 20:08
Speedtest to different locations from Nha Trang, Vietnam

San Francisco

San Francisco

Berlin

Berlin

Sydney

Sydney

@skorfmann
skorfmann / authentication_events.rb
Last active December 14, 2015 21:19
Track authentication events from devise (warden)
# this gets called every time a user is authenticated
# either via an actual sign in or through a cookie
Warden::Manager.after_authentication do |user,auth,opts|
auth.params.has_key?('user') ? 'trigger direct sign in' : 'trigger cookie sign in'
end
# this gets called every time a user is fetched from session.
# happens on every request!
Warden::Manager.after_fetch do |user,auth,opts|
'trigger user request'