Problems with Ruby on FreeBSD
The people following me on twitter already know I had problems with Ruby on a FreeBSD 6.3 system yesterday.
It seems that the default ruby 1.8 from the ports system has a big problem with recursion. The recursion level cant go nearly as deep as it can on other operating systems.
And if the limit is reached the ruby process crashes with a signal 4 (a SIGILL) instead of raising a SystemStackError as it is supposed to be.
So if you see your ruby processes (and this includes your mongrels) die without any reason on FreeBSD 6 you know what is wrong.
Posted in Ruby, Daily annoyances, Software, Hardware and the Mac | no comments |
How to install gem with native libs on FreeBSD with ports
just do
sudo gem install curb -- --with-opt-dir=/usr/local/
Posted in Ruby, Software, Hardware and the Mac | no comments |
Object#methods: Looking at the difference
When I play around with a new API or library in Ruby, I usually use IRB, the interactive Ruby shell, to do so. Creating an Object, writing a mini-Class or somthing like that, just to get a feel for the object.
Often I use Object#methods to look at the interface of an object. The annoying part is, that you alway see plenty of methods intorduced by the base class (Object), wich every Object has.
So I added a method to Object, thorough monkey patching it:
[code lang="ruby"] class Object def methodswithoutdefault (self.methods - Object.new.methods) end end [/code]
and put that into my .irbrc file.
So now someobject. methodswithout_default gives me an array of all non-Object-inherited methods of that objcet :-)
Posted in Ruby | no comments |
You will never miss Perl when using Ruby
This is valid Ruby syntax
?{*?{%?{-?{**?{+?{||?{|?{&?{&&
?}|?}**?}-?}%?}&&?}+?}*?}||?}&
?[&?[||?[|?[-?[%?[&&?[**?[+?[*
?]|?]*?]&&?]||?]**?]%?]-?]&?]+
?;&?;-?;%?;+?;*?;||?;**?;&&?;|
?:*?:&&?:&?:||?:**?:+?:|?:%?:-
?'-?'&&?'+?'|?'||?'%?'&?'*?'**
?"%?"+?"&?"*?"-?"||?"**?"&&?"|
?/||?/|?/&?/-?/+?/&&?/*?/**?/%
??-??&??&&??||??%??|??*??**??+
?.*?.&?.%?.-?.+?.|?.&&?.||?.**
?,&&?,-?,||?,%?,**?,+?,|?,&?,*
?<-?<+?<&&?<%?<||?<|?<&?<*?<**
?>**?>+?>|?>%?>||?>*?>&&?>-?>&
?=**?=|?=*?=&&?=%?=+?=-?=||?=&
?-&&?-&?-+?--?-%?-|?-**?-||?-*
?+*?+%?+||?+|?+&&?+-?++?+**?+&
?_|?_+?_%?_&&?_||?_&?_*?_-?_**
?)%?)*?)&?)&&?)-?)|?)||?)+?)**
?(%?(+?(-?(**?(*?(|?(&&?(||?(&
?*&&?*+?*-?**?***?*|?*%?*||?*&
?&|?&-?&&?&&&?&%?&||?&+?&**?&*
?^%?^&?^||?^*?^+?^-?^&&?^**?^|
?%*?%+?%**?%||?%%?%&?%-?%&&?%|
?$%?$|?$*?$-?$**?$&&?$&?$||?$+
?#&&?#**?#*?#+?#-?#&?#||?#%?#|
?@+?@%?@&&?@&?@|?@-?@*?@**?@||
?!&&?!||?!&?!**?!*?!%?!|?!+?!-
?~|?~&&?~&?~-?~||?~**?~%?~+?~*
?`&?`||?`**?`*?`%?`&&?`|?`+?`-
?||?|+?|-?|**?|||?|&?|%?|*?|&&
??
it evaluates to
[code lang="ruby"] -114374367934617190099880295228066276746218078451850229775887975052369504785666896446606568365201542169649974727730628842345343196581134895919942820874449837212099476648958359023796078549041949007807220625356526926729664064846685758382803707100766740220839144 [/code]
BTW: The ruby syntax colorer does not like this blob ;-)
Posted in Ruby, Notes to myself (and the rest of the world) | no comments |
Bratwurst for Everyone
This year I'm attending the RailsConf Europe in Berlin.
Of course I attended Bratwurst on Rails, the pre-conference get together inspired by last years Pizza on Rails in London.
I have to say it was pretty cool, I met a bunch of cool people and so I'm looking forward to attending keynote by Dave Thomas in about an hour.
I'm posting all the pictures I took on my new picture gallery, so have a look.
Posted in Ruby | no comments |
Men are from MARS
"Boys are from LAMP, men are from MARS"
MARS is MySQL + Apache + Rails + Solaris and it's manly.
Posted in Ruby, Fun | no comments |
Ruby just rocks
These days I often get reminded why I love ruby so much.
Easy things are easy, complex things are possible and it works just the way you think it will – most of the time at least.
An example: How to shuffle any array (the numbers of 1 to 10 in this example)
[code lang="ruby"] (1..10).sort{|a,b| rand(3)-1 } [/code]
Updated:
kev of the guys at gluttonous had the same idea a some month back. From the comments and a Usenet discussion from December 2005 about the same code snipplet I learned that
[code lang="ruby"] (1..10).sort_by {rand} [/code]
is 4x to 5x times faster and at least as elegant.
the really optimized
[code lang="ruby"] def shuffle3 h = Hash.new self.each { |v| h[rand(1000000000)] = v } h.keys.sort.collect { |k| h[k] } end [/code]
seems to be even faster, but only by a knifes edge.
Posted in Ruby, Art and Beauty | no comments |
Railgun
After several attempts, wich failed, I finally managed to upgrade this blog to the latest bleedin' edge Typo svn version.
I just had to remeber
- That there is something like
rake migrate- wich is a wonderfull invention to migrate your database - And that I have to check my own typo template - wich renders this wonderfull layout - aginst the latest bleedin' edge azure default template - maybe they changed something that breaks your blog.
So now I'll be rememberd
Posted in Ruby, Daily annoyances, Software, Hardware and the Mac | no comments |
Ruby on Rails
Everybooy who has followed this blog on a regular basis has noticed taht I'm a big fan of the Ruby programming-language.
Some weeks ago I noticed Ruby on Rails, wich is a rapid-(and clean)-webdevelopment-framework for Ruby.
Today I looked into the whole thing. Man I can tell you this rocks. It is like a PHP-MySQL combo on steroids. It devlivers everything promised by all of the scripting languages in a clean, easy way and reliefes the developer of most of the hassle with all of those mysql_connect(); hassles.
I will clearly do something with it. Not shure exactly waht, but it will be uefull. Something with pictures and links... You'll see.
Rail on!
Posted in Ruby | no comments |
Growl for a Ruby
Hey, sorry for the long silence. I was quite busy the last weeks. universtiy stuff. and a bit lazy, too. Of course.
Today I finally found time to do something usefull and hacked together some Ruby bindings for the Growl notification system. Now everybody can include beautifull notifications in their Ruby-scripts.
Here is the source:
### Copyright
#
# Copyright 2004 Thomas Kollbach <dev ÄT bitfever.de>
#
# Released under the BSD license.
#
### Descreption
#
# A ruby class that enables posting notifications to the Growl daemon.
# See <http://sourceforge.net/projects/growl/> for more information.
#
# Requires RubyCocoa (http://www.fobj.com/rubycocoa/) and Ruby 1.8
# (http://ruby-lang.org).
#
### Versions
#
# v0.1- 25.11.2004 - Initial version, this is less more then a ruby translation of
# the python bindings
#
# TODO: transform this into a ruby-module, so it is usable as a mixin
# for ruby-scripts
#
### Usage
#
# Here is a short example how to use this in a script
#
# n = GrowlNotifier.new('bla',['Foo'],nil,OSX::NSWorkspace.sharedWorkspace().iconForFileType_('unknown'))
# n.register()
#
# n.notify('Foo', 'Test Notification', 'Blah blah blah')
#
###
require 'osx/cocoa'
$priority = {"Very Low" => -2,
"Moderate" => -1,
"Normal" => 0,
"High" => 1,
"Emergency"=> 2
}
class GrowlNotifier
# A class that abstracts the process of registering and posting
# notifications to the Growl daemon.
#
# `appName': The name of the application
# `notifications': an array of notifications - default is an empty array
#
# `defaultNotifications': optional - defaults to the value of
# `notifications'
# `appIcon' is also optional but defaults to a senseless icon so
# so you are higly encouraged to pass it along.
#
def initialize(appName='GrowlNotifier', notifications=[], defaultNotifications=nil, appIcon=nil)
@appName = appName
@notifications = notifications
@defaultNotifications = defaultNotifications
@appIcon = appIcon
end #initialize
def register
if @appIcon == nil then
@appIcon = OSX::NSWorkspace.sharedWorkspace().iconForFileType_("txt")
end
if @defaultNotifications == nil then
@defaultNotifications = @notifications
end
regData = {
'ApplicationName'=>@appName,
'AllNotifications'=> OSX::NSArray.arrayWithArray(@notifications),
'DefaultNotifications'=> OSX::NSArray.arrayWithArray(@defaultNotifications),
'ApplicationIcon'=> @appIcon.TIFFRepresentation
}
dict = OSX::NSDictionary.dictionaryWithDictionary(regData)
notifyCenter = OSX::NSDistributedNotificationCenter.defaultCenter
notifyCenter.postNotificationName_object_userInfo_deliverImmediately_("GrowlApplicationRegistrationNotification", nil, dict, true)
end #register
def notify(noteType, title, description, icon=nil, appIcon=nil, sticky=false, priority=nil)
# Post a notification to the Growl daemon.
#
# `noteType' is the name of the notification that is being posted.
# `title' is the user-visible title for this notification.
# `description' is the user-visible description of this notification.
# `icon' is an optional icon for this notification. It defaults to
# `@applicationIcon'.
# `appIcon' is an optional icon for the sending application.
# `sticky' is a boolean controlling whether the notification is sticky.
@notifications << noteType
if icon == nil then icon = @appIcon end
notification = {'NotificationName'=> noteType,
'ApplicationName'=> @appName,
'NotificationTitle'=> title,
'NotificationDescription'=> description,
'NotificationIcon'=> icon.TIFFRepresentation()}
unless appIcon == nil
notification['NotificationAppIcon'] = appicon.TIFFRepresentation
end
if sticky
notification['NotificationSticky'] = OSX::NSNumber.numberWithBool_(true)
end
unless priority == nil
notification['NotificationPriority'] = OSX::NSNumber.numberWithInt_(priority)
end
d = OSX::NSDictionary.dictionaryWithDictionary_(notification)
notCenter = OSX::NSDistributedNotificationCenter.defaultCenter()
notCenter.postNotificationName_object_userInfo_deliverImmediately_('GrowlNotification', nil, d, true)
end #notify
end #class growlnotifier
Posted in Ruby | no comments |