Just stumbled upon the following trick to get the basename without an extension in Ruby:
(I didn't know you could use ".*" to remove any extension).
File.basename( "filename/sample-filename.html", ".*" ) => "sample-filename"
Software development articles
There are 125 posts filed in Hacking (this is page 11 of 25).
Just stumbled upon the following trick to get the basename without an extension in Ruby:
(I didn't know you could use ".*" to remove any extension).
File.basename( "filename/sample-filename.html", ".*" ) => "sample-filename"
Today I discovered my Ruby on Rails development environment database migrated with the wrong character encoding. It was using the MySQL default encoding latin1.
I didn't feel throwing my database away because it contains a lot of stuff.
I used the following snippet to convert all columns to utf8
ActiveRecord::Base.connection.tables.each do |table| ActiveRecord::Base.connection.execute( "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") end
I'm working on a rails website that requires me to specify a class in an initializer.
config/initializers
spree.searcher_class = MySearcherClass
I'm currently developing this searcher class. Every time I change this class I get the following message:
A copy of MySearcherClass has been removed from the module tree but is still active
This sucks big time! Because I need to restart my rails application every time I change something.
My workaround for the moment is this:
spree.searcher_class = class.new do def new(*args,&block) return MySearcherClass.new( *args, &block ) end end end
I'm not very keen on this, but it does the trick for now :)
Today I struggled with a string replace that didn't do what I expected it to do.
Consider the following code:
"xyz".gsub("y","a\\'b") => "xazbz"
Because gsub can be used with a regular expression the replace value can use regular expression backrefs.
I assumed (assumption is the mother of all fuckups) when using a plain string as search term, (which cannot result in back refs) it didn't use backrefs..
Well I was wrong..
A solution is to use the block-variant:
"xyz".gsub("y") { "a\\'b" } => "xa\\'bz"
I think the behavior of gsub is wrong...
When you don't have a regular expression you cannot have backrefs and you can have a dumb string replace.... What's your opinion about this?
Don't you just hate it when installing ports on a live server fail!
Well I do. Today the following happened:
===> Installing for perl-5.16 ===> Checking if lang/perl5.16 already installed ./+INSTALL: Permission denied pkg_add: install script returned error status *** Error code 1
Big panic, couldn't install perl on my server.
On my server the /tmp drive is mounted with noexec. This script seems to need execute rights in the temporary directory
The work-around I used is the following:
mkdir /usr/tmp export TMPDIR=/usr/tmp
Finally my make install works again :D
make install