It would appear you can set a regexp variable thus (for example): PORTSCOUT=limit:^1.4 In a ports Makefile to prevent portscout looking for newer versions, very useful if you need to put a legacy version in the tree.
One that caught me out for a while … needed to reduce the timeout the Net/HTTP library was defaulting to because the servers I was querying were liable to be offline and I didn’t want my script hanging around. I wrote something like: require ‘net/http’ res = Net::HTTP.start(‘http://www.example.com’) do |http| http.open_timeout = 4 http.read_timeout = [...]
I was writing some code akin to: case something.class when String, Symbol then 1 when Fixnum then 2 when Time then 3 end Only to find it didn’t work, always returning nil. A bit of trawling turned up the following blog post: http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/, which explains that you don’t need the .class. So my above code [...]
I’ve been working with the XML-Mapping gem and had the following error when trying to generate XML: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/element.rb:685:in `write’: undefined local variable or method `output’ for <xml_node> … </>:REXML::Element (NameError) A bit of digging lead me to this bug report, which lead me to look properly at the code and sure enough correcting the code [...]
Now this might just be my system and I certainly don’t have this problem with any of my FreeBSD machines, but I’ve got a weird problem with filenames and colons on my Mac (10.5.8) with Ruby (ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]). Anyhow if I write something like this: File.open(‘foo:bar.txt’, ‘w’) {|f| f.write("hello world") } [...]
Just installed the XML-Mapping Gem (http://xml-mapping.rubyforge.org/) and kept getting a require error every time I tried to use it. /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require’: no such file to load — xml/mapping (LoadError) Everything seemed okay, until eventually I noticed that the Gem files themselves were rather restrictive on permissions – owner read and write only. So I had [...]
I was about to do some comparisons of file version numbers, standard sorts like 1.0.4, a straight string comparison isn’t really ideal since 1.0.2 would be larger than 1.0.10. I assumed there would be a ruby class for this already created, or if not I was going to create one! A moment of searching turned [...]
I’ve just had yet another problem with PHP and its extensions on one of my servers (should have taken my own advice, this time no number of re-compiles or order tweakage of the extensions.ini file seems to work … I’ve hit the buffers with using mhash. Now that might not be a bad thing, the [...]
Want to view the documentation for your locally installed Gems? Easy, at a command prompt start the gem server thus (may need to sudo it especially under OSX) gem server Fire up a browser and visit: http://localhost:8808/
Silly mistake on my part, but took me a while before I saw the obvious. If you’re writing a daemon in Ruby using the daemons gem (http://daemons.rubyforge.org) and want to have some code run when your script exits (is stopped by the daemon control), then your first thoughts would be to use the at_exit construct. [...]
© Chillibear | Theme DePo Skinny | Header image from: Andrews, William: 'Curiosities of the Church: Studies of Curious Customs, Services and Records' (1891)