Git: Untracked working tree file would be overwritten by merge

I ran into a merge conflict when a branch had changed a file and I was merging in another branch where the file had been deleted and placed in gitignore.   Some suggestions on handling this here:

I used:

  • git checkout <your-branch> -f

I then need to “git rm” the file in the branch where it had been modified.  I’m not sure what exactly happened to the file since I didn’t care much about it.

Determining if a string is a float

Using to_f has the problem of returning 0.0 for invalid strings.  So for a project I needed to know if a string was a valid float or not and came across this helpful page: ruby on rails – Determine if a string is a valid float value – Stack Overflow.  My favorite option was this:

 


class String
def valid_float?
# The double negation turns this into an actual boolean true - if you're
# okay with "truthy" values (like 0.0), you can remove it.
!!Float(self) rescue false
end
end

Accessing MS SQL Server from Rails without ODBC

I found myself looking through the code for activerecord-sqlserver-adapter and noticed a new mode called “dblib”.  It turns out this mode can be used when using the tiny_tds gem along with FreeTDS to avoid using ODBC altogether.  I decided to try it out on a project and have found it to work very well so far.  The update_sql call no longer has to make a call to get the number of affected rows, something which was slowing down the code significantly.  I don’t have many benchmarks yet but it looks like performance is up or has remained constant across the board.  I’m not sure if there are any problems that might come up, certainly TinyTDS is a relatively new project.  But for now I’m enjoying not having to use ODBC and hopefully this will continue to work well moving forward.

Ruby regexp surprise: w is not equivalent to [0-9A-Za-z_]

Despite ample documentation to the contrary I was surprised to learn that by default ruby matches w to all unicode characters.  This lead to some strange results in one of my apps where unicode quotes were present and matching w.  I found the solution is to use /w+/n to specify the n kcode rather than the u kcode.  But this was still distressing to find as the default in 1.8.7 and 1.9.2.  It was further complicated by trying to get information.  The following websites all report that w is equivalent to [0-9A-Za-z_]:

According to these links, this behavior is spec but not documented anywhere:

Rails marshal data too short

I ran into an error when trying to save an object in flash between Rails actions.  I’m still not sure why marshal data too short happened as the session storage is mysql using the text type which should be 64kb.  I can’t imagine the object taking more size than that but it would be worth checking.  I resolved the issue by not storing the object but other options would be figuring out why the object is so large (Marshal.dump(object) maybe) or switching to mediumtext type which has a limit of 16MB.  To do this via a migration can be found here:

ruby on rails – marshal data too short!!! – Stack Overflow

Resetting postfixadmin password

I had a client using postfixadmin but no one knew the password.  Simple enough to go into the db to reset:

dovecotpw -s MD5-CRYPT -p password | sed ‘s/{MD5-CRYPT}//’

Then in the database:

update admin set password=’CRYPTED PASSWORD” where username=’USERNAME’;

I found how to do this here:

SourceForge.net: Postfix Admin: Topic: Postfixadmin mysql password storage method

Will I end up having to write my own Linux twitter client?

I am not at all happy with the state of GNU/Linux twitter clients.  It seems this is all too common in the open source world, too many people working on different products, none of which end up being very good.  I’ve counted 10 native GNU/Linux clients (not counting Adobe Air) and not one of them suits my needs (Gnome, multiple account support, decent interface, works).  Here are some thoughts on each of them:

Continue reading ‘Will I end up having to write my own Linux twitter client?’ »

Working with devise for Rails authentication

I’ve begun using devise for authentication for my various Ruby on Rails applications.  It is based on warden which seems a sensible choice.  There is also a fairly large community and active development.  Devise plays nice with authorization libraries such as CanCan and can be integrated with OmniAuth for oauth/oauth2 authentication.  I’ve run into a number of issues so I thought I would track some of the useful links that have helped me out.

Continue reading ‘Working with devise for Rails authentication’ »