Categories
Ruby

Ruby 1.9/2.0 rvm fix for SSL_connect returned=1 errno=0 state=SSLv3 error

Check the status of your installed certs to see if they are out of date:


$ rvm osx-ssl-certs status all

If any are out of date update them automatically by running:


$ rvm osx-ssl-certs update all

NB: You may find that if you check the status again one or more cert locations are still out of date – just manually overwrite them with the one that is now up to date.

For example:


Certificates for /Users/example/.rvm/usr/ssl/cert.pem: Old.
Certificates for /Users/mpapis/.sm/pkg/versions/openssl/0.9.8x/ssl/cert.pem: Up to date.


$ cp /Users/mpapis/.sm/pkg/versions/openssl/0.9.8x/ssl/cert.pem /Users/example/.rvm/usr/ssl/cert.pem

Categories
Rails Ruby

No such file or directory error with ruby tempfile and heroku cedar

Bit of a strange error had me puzzled, the app worked great on Bamboo but was erroring on cedar with:

No such file or directory - /app/tmp/csv_export_120120806-2-1bnlu8h.csv.lock
/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/tempfile.rb:346:in `rmdir'

The actual line of code was this:
temp_file = Tempfile.new(["csv_export", '.csv'], Rails.root.join('tmp') )

It turns out on Cedar the Rails tmp directory isn’t created by default so you need to manually check for & create it:

temp_dir = Rails.root.join('tmp')
Dir.mkdir(temp_dir) unless Dir.exists?(temp_dir)
temp_file = Tempfile.new(["csv_export", '.csv'], temp_dir)

Categories
Rails

Windows + IIS + Rails + Paperclip + Uploaded files give Errno::EACCES (Permission denied)

This was driving me nuts – not my preferred setup, especially now-a-days Rails + Windows really don’t play nice together.

I was having an issue with uploaded files (or in my case generated pdf files that were attached to the model using Paperclip) giving Permission Denied errors after they’d been created.

The Solution

Find the temp folder for the user of the application pool (or the user account for the web app) for me it was:

C:\Users\invoicing.IIS APPPOOL\AppData\Local\Temp

Then change the Temp folder permissions to include the IIS_USRS account.

Why?

Paperclip/Ruby creates the uploaded file in the temp folder location before copying to the relevant location in your Paperclip folder structure.  Unfortunately, when it does this, it takes the permissions from where it was first created (in this case the Temp folder). By adding the IIS user account to the folder permissions these get copied across too.

NB: If you really do need to deploy to Windows do yourself a favour and use Helicon Zoo – works great with IIS.

Categories
Ideas

When to use NoSQL/key-value store?

I’ve been meaning to look into this for some time to get my head around these fancy new databases and find out when I should consider using them. I’ve come to the conclusion that you generally wouldn’t use an object/key-value database on it’s own.  You have your main relational database for important data that is definitely required, and then you can have multiple key-value databases to do a lot of the firehose-data grunt work across multiple servers.

A setup might look like:

Relational Database:

You need your relational database for things that a user absolutely has to have every request (e.g. you always need to access the users login details).

NoSQL/Key-Value Database:

However for things that don’t really matter (like posts, tweets, comments) then you can use a key-value store because who cares if all the comments/tweets etc aren’t listed every request as long as you show something and you know it’s going to be correct at some point.

I believe this is how reddit works it has postgres server(s) and then multiple cassandra servers for submissions.  I assume it’s similar for facebook except, I think, they use mysql & cassandra.

Conclusion:

For your next web app I’d start with your usual relational database of choice.  Once you get to the stage when you have the performance/scalability issues to deal with then you might take a bigger look into the NoSQL/key-value stores.

Some interesting links:

Categories
Firefox

Getting Live HTTP Headers to work with Firefox 4

UPDATE: The official Live HTTP Headers add-on now works with Firefox 4:

Download Here: http://livehttpheaders.mozdev.org/


Note this is a temporary solution, and worked for me with Firefox 4 b12:

  • Download the .xpi file (Use right-click save as or Firefox will try to install the add-on)
  • Rename .xpi to .zip
  • Unzip the contents
  • Edit install.rdf
  • Under the <–Firefox –> Section change <em:maxVersion>3.6.*</em:maxVersion> to <em:maxVersion>4.0.*</em:maxVersion>
  • Rezip the files
  • Rename it back to .xpi from .zip
  • In Firefox do file open, and open the .xpi file.

The add-on should install, just restart Firefox and use as normal.

Note: It works on my machine, however your mileage my vary.  Obviously, I recommend that you keep an eye out for an official update and install the proper version as soon as it’s available…

Categories
Firefox

Firefox Tip: Quick selection of awesomebar item

Can’t believe I didn’t notice this before; after typing in a few letters of the site you are looking for rather than pressing the down arrow key, you can just press Tab to highlight the next item in the selection of sites (and Shift-Tab to go backwards).  Yey for keeping your fingers on the home keys!

On an partially related note, I’ve been giving the Firefox 4 Beta (12) a try today – if you are using Firefox daily, and don’t mind losing some of your add-ons – upgrade now.  It’s rock solid, and like lightning compared to 3.6!

Categories
Apple

Mac OSX Tip: Mirror menubar to Dual Display / 2nd Monitor

Found this nifty program today ‘SecondBar‘ it creates an extra menubar on your 2nd monitor which means you don’t have to move your mouse across both screens to access a menu item.

http://blog.boastr.net/?cat=1

NB: Currently your usual menubar icons aren’t copied across, however there are some nifty extras like enabling you to right-click the maximise button to give a full-screen maximise (rather than the usual resize of ‘as big as OSX thinks you need it’).

Categories
Linux

Linux Tip: Truncate multiple files using find

Assuming you have a find command of

find . -type f -name '*.log'

Then it’s as simple as:

for item in $(find . -type f -name '*.log' ) ;do cat /dev/null > $item ;done

Handy for truncating log files…

Categories
Apple Mac Rails Ruby

Switching from Windows to Mac, a developers view

[Note: I originally wrote this almost 2 years ago (about 3 weeks after buying a Mac) and only now got around to getting a blog together so I’m going to intersperse with notes as to my thoughts now.]

After a lifetime of using a PC for development I’ve taken the plunge and bought a new Mac Pro for my every day work.

Main reasons for switching:

  • I really like the iPhone (this was my first foray into the Apple world).  The interface is great, it’s been really well thought out which led me to reason that the Mac must be pretty good too.
  • I tried Ubuntu again, and whilst good, it’s still not quite ready for full-time desktop work in my opinion.  For me, there are still too many times when something doesn’t work quite right and you have to get down and dirty messing with config files.  To be blunt I’d rather get on with my work than be tinkering with the OS.
  • I host sites using Linux via ssh and I enjoy using the Linux commands.  With the Mac it seemed like I get the best of both worlds; a Linux style command line and a well thought out and tested UI.
  • I wanted to do some iPhone development.
  • I’ve moved away from .Net/MS specific programming now and tend to do a lot of development using open source solutions i.e. Ruby & Rails development using MySQL or PostgreSQL.
  • Ruby seems to be much faster on Linux/Mac and a lot of the Ruby/Rails community seem to be using either Linux or Mac.
  • My old PC seemed to be dying it’s death with blue-screens (probably hardware related).  Although I don’t think Vista is as bad as is made out it’s still resource hungry, applications seemed to crash more frequently than on XP, the damn hard-disk thrashing (although definitely improved in SP1) still annoys me and not forgetting problems with sleep just  not working.  I will add that this is probably my own fault as I did a home build and my Wife’s Dell seems to work pretty well however I’ve just had too many little niggles.
  • I’d been in contact with Apple over a sound-sync problem with an iTunes video and their customer service were awesome (albeit a little slow) – giving me 3 free video downloads and monetary credit to make up for the problem video.  You can’t beat that for customer service. [Since then I had a WiFi issue with my original iPhone but my warranty was 2 weeks out of date, taking it to the Apple Store, the Apple Genius Bar guy noted that I’d taken good care of of it and just exchanged it free of charge!]

Ultimately though, I just knew I fancied a change and I wanted to try something new.

Buying

I just want to add Apple’s customer service were excellent again.  I ended up phoning them as I needed to setup a proper business account.  Not only did I get 5% discount off the current Apple Store prices the rep very kindly phoned me back twice to help get the transaction sorted.  If only more companies were like that.

Making the Switch

I think what surprised me the most was the switch was a lot easier than I would’ve thought.  There is definitely some convergence between features in Windows & OSX e.g. similar home folder setup, Spotlight/Windows Startbar Search etc.

File Transfer

I could connect to my Vista PC over the wireless network and copy any files I needed.  Although you can’t write to an NTFS partitioned drive you can read okay; so I just connected to the PC and copied all the required files from OSX.

iTunes

Extremely easy; I just ran iTunes once to setup a profile, quit then just straight copied the Windows My Music/iTunes folder to the OSX Music/iTunes folder.

Email

I could’ve bought Office 2008 for the Mac which would have made this very easy (I think you can just import your PC outlook.pst file).  However I thought I’d give the Mac equivalents a go for the moment.  I imported my Outlook emails into Thunderbird on the PC copied the profile to the Mac and could have just used Thunderbird but in the end decided I wanted to try the default mail.app.

Here there were problems because although mail.app will import the email from Thunderbird it seemed to miss out a lot of my emails.  I found this program which sorted that out instantly though.

After a few tweaks to mail.app – I noticed that you can customize the toolbar functionality (I didn’t like that the search bar is way out on the right and ‘get mail’ button way out on the left) and I added the widermail plugin mail.app to get the 3 column layout.  It’s good enough for me at the moment and it’s certainly a lot faster than opening Outlook 2007 on my PC.  It also has some added bonuses like highlighting the related emails and the upload/download progress bar is a lot better than Outlook.

[I’m still using mail.app just to add to this auto-detection of calendar appointments in an email message is magic!]

Web

Safari seems perfectly functional however I still love the plugins for Firefox (Firebug, Web Developer, Tab Mix Plus, Download Status Bar, ColorZilla are my must haves).  This was just a matter of moving my Windows Firefox profile to OSX (on Mac its Library/Mozilla/Firefox).

Office

As mentioned, I didn’t buy Microsoft Mac Office 2008, although I bought iWork with the Mac so I’ve been giving that a go.  I’m also trying out NeoOffice which is basically OpenOffice with the usual Mac UI.  Actually it seems a lot better than the default OpenOffice UI on Windows at first glance and I’m surprised they didn’t take some of the UI on board for the Windows version.  I’m not totally convinced by either but considering how much office work I do now I think I can live with it for the moment.  They both open MS formats so there have been no issues so far.

[Still using this combo; I not overly fond of Pages, however Numbers (Spreadsheet) & KeyNote (Presentations) are excellent. I’ve noted that formatting is occasionally an issue from MS docs and iWork will constantly ask you to review the missing fonts when opening a file which get’s old pretty quickly.]

Development

Textmate is a great program basically like e-texteditor for Windows but seems a lot more stable and after watching the peepcode screencast for Textmate and Rails I’m loving it all the more.  I haven’t had the need to yet but I can always go back to Aptana if required.

XCode the default Mac development environment is free and pretty easy to use.  I’ve been working through the Beginning iPhone Development book and I’ve begun to see one of reasons Mac programs tend to look good is the nice touches like guides so when designing your app – it automatically helps you to line up controls and gets you to think about the design/layout of your app.

Also I haven’t had to yet but it looks cheap and easy enough to set up Parallels/VMware Fusion and install Windows on them. Also from what I’ve read you can even setup SQL Server on it and connect to it from the Mac which is handy.

[I’ve since installed VMware Fusion which works great on the Mac Pro, so good in fact, I couldn’t really tell the difference in speed from old PC even when using Visual Studio or SQL Server Management Studio.]

Ruby

Is one of the default frameworks to OSX so it’s ready to go out of the box.

[Make sure you look into homebrew as this is a great management tool to get all the apps you end up needing e.g. git, RMagick, and even postgresql/mysql.]

Ruby on Rails

I know I have a new and faster computer however this deserves a special mention.  I set up a Rails app and did a full migration and it finished in a few seconds…cough!  Anyone who’s done Ruby on Rails work on Windows knows this is not the norm.  Usually you have to wait around 20-30 seconds for Rails to load then it’ll start chugging through the migrations which can take a few seconds each.

Adobe

This has probably been my only major expense so far.  I do some film work and had a copy of Production Premium CS3 for Windows.  Fortunately Adobe will let you cross-platform upgrade to Mac as long as you sign a letter of destruction for your previous Windows version.

Cool stuff I wasn’t expecting

Sites Folder

Apache is configured & installed by default and you have a folder in your home directory /Sites which you can put your static websites into.  Just enable web sharing in the Sharing section of System Preferences and you can open them up in your browser.  Very Handy.

[Note: PHP isn’t configured by default.]

Terminal

The out of the box terminal (i.e. Windows Command Prompt) is tab-able, has Linux style commands, it’s easy to configure and you can even add your own styles.  Also ssh is built in already – no more cygwin fab.

Time Machine

Plugged in my usb hard-drive and Time Machine asks if you’d like to use it as a backup drive for your data.  It keeps a backup of changes every hour, daily backups for the last month and monthly until the disk runs out of space.  All automated; cracking!

[This saved a load of work recently where an uncommitted file from over a year ago had been deleted on my system but was still on Time Machine, phew]

Also interestingly you can do a similar thing if you sign up to Apples’ MobileMe service except you can have your home folder synchronized to online storage.  Having your settings sync between Macs seems like a cool idea too.

[This isn’t quite true it’s more like manual syncing of your home folder which is a bit disappointing.]

Remote Desktop

Free download from Microsoft so I can still connect to the Windows servers when I need to.

FileZilla

Works on Mac too so it was easy to import all my ftp site settings.

WinSCP

Cyberduck is a handy Mac equivalent for doing sftp using key based logins.

TortoiseSVN

Although it doesn’t seem to have all the features of TortoiseSVN, SCPlugin is an able free replacement.

[I’m generally using git now however I didn’t get on with the interface of SCPlugin and when I first tried I couldn’t get Versions App playing nicely (I have had it working since though). I’ve ended up using SmartSVN which does the job nicely, but it doesn’t really have a Mac-like interface.]

Keyboard Shortcuts

I’m probably using more keyboard shortcuts on the Mac than I did after years of use on Windows.  Very weird; I think it’s because of how OSX UI works it really helps your productivity if use the command shortcuts.

The Dock

I didn’t know if I would like it but actually its great.  What you don’t get to see in the pictures is that the dock will automatically resize to accommodate more or less icons as you add and remove applications.  It’s also makes it easy to see & run the applications you commonly use.

Spotlight

One of the things I liked about Vista was the quick search functionality (press Start, type the first few letters of the program and press Enter to run).  On OSX you have Spotlight which does the same thing (Command-Space and start typing).  I will add that for me it seems a lot more user friendly as it categorizes applications, emails, to-dos, folders etc and lays them out a lot more cleanly than in Vista.

Expose

This is cool basically you can configure the corners of the desktop to do different actions when you place the mouse there.  So for me bottom left shows the desktop (just move the cursor back to bottom left to restore the windows), top right and left will show all the windows of the current application (e.g. all the current firefox windows, open emails etc) and bottom right will show an overview of all windows.  This is extremely useful on a Mac because you don’t have the tabs showing each instance of a program on the task bar that you would be accustomed to in Windows.

Preview

This will open most common files (including PDF’s no Adobe Acrobat required!) and it will even do basic image manipulation.  You’ll be surprised how much this gets used, it’s a quick and handy multi-tool.

Printing

Plug in a printer and Mac OSX does zilch, nothing, no popups, no nothing.  You try printing and realise it really does “just work”. When printing you also have the option to just save to a PDF file which is really handy sometimes.

Dual Monitors

Thought this was pretty cool.  If you unplug one of the monitors (as I happened to do to control my windows box) the Mac automatically changes the display setting to a one screen desktop and then back to two when I re-plugged it back in – it’s the little touches that make you smile!

Not So Cool Stuff

Well it can’t all be perfect…

Firewall

The firewall was completely open on my Mac Pro by default.  This isn’t generally as much of a problem as it was in the old days with people now sitting behind routers with built-in firewalls.  I’m assuming this is not the case with an iMac or MacBook however I was surprised though; Microsoft would get a flaming for doing that these days.

Mighty Mouse

You can configure it to have the usual left & right mouse buttons and the wheel is actually more like a ball which quite nifty however after gaving it a go for a day or so it wasn’t good enough for me.  I prefer something that moves faster and I seemed to end up having the right mouse button being pressed too often when I really wanted the left button.   Not a problem though I just plugged in my trusty Razor mouse.

Mouse Movement

Very strange one this; the default mouse movement just doesn’t feel right.  I played around with the settings but couldn’t quite get it how I wanted.  In the end I found SteerMouse and after a bit of playing around I found some settings I enjoyed.  This also allowed you to configure the 3rd/4th buttons to be back/forward in the browser which I’m accustomed to.

Maximizing Windows

The maximize button doesn’t actually maximize in the Windows sense it changes the window size on the Macs best guess of how the window should be laid out.  Actually this isn’t as bad as it sounds but it’s certainly odd when you’ve been using Windows all your life.  I was also a little put out that there isn’t a keyboard shortcut for it.

[Worth mentioning Divvy, SizeUp and Cinch here; I find Divvy really useful on a Mac Book]

Resizing Windows

This is very minor; you can only resize a window by holding the bottom right corner of a window.  What’s wrong with having resizable borders all the way around?

Installing/Uninstalling Applications

Basic apps are simple; once you understand the process.

You can just download a .dmg file it’ll open up and either autorun and it’ll generally open up a Finder window (Finder=Windows Explorer window) with the app icon so you can drag it to your Applications folder (or the decent ones have a shortcut to the applications folder there too).  You can then remove the .dmg file by dragging it to the Trash icon or clicking an eject button in finder.  To uninstall you just drag the application from the applications folder to the Trash.

Once you’ve got it it’s easy and you wont think twice about it however I could just imagine a new user ending up with either a desktop full of .dmg files that they never manage to get rid of or they just running the application from the .dmg file and not realizing it needs to be dragged to the applications folder for it to be permanently installed.

You also have .pkg files which are seem to be the same as a normal windows install file, lots of okays, click agree etc.  Unfortunately (unless I’m mistaken) there is no default uninstall or add/remove programs area for these – how mad is that!?

NB: There are programs that will do this AppZapper & DesInstaller – still odd that something like this isn’t included by Apple though.

Keyboard Shortcuts

Now I’m still learning so take some of this with a pinch of salt however I do find it a little more taxing for my fingers to remember the modifier for commands.  For most of the commands it’s just a case of changing Ctrl for Command e.g. Command-C is copy and Command-V is paste which is all good.

However if you want to move the cursor forward or back one word Command-Left Arrow will actually take you to the start of the line, Command-Right Arrow to the end of the line so you’ve got to move position/use a different finger and use the Option/Alt key instead.

To top it off pressing the Option/Alt key with a letter will produce a symbol…so far too many times at the moment I’ll select some text and not hit the Command key properly or knock a key accidently whilst the Option/Alt key is still down and end up replacing the selected text with Ω or ç or some other random character.

[All the shortcuts are pretty much ingrained now, using Cmd for the modifier key is actually a lot more comfortable than Ctrl key.  I still find the Alt key for word highlighting slightly awkward, however you do get used to being able to do Cmd-Arrow keys so much (Up=top of page, Down=bottom of page, Left/Right=Beginning/End of line) you’ll miss them when you use a Windows machine again]

Where’s the # Key?

I’ll also add it’s a bit strange that there is no # key on the default UK Mac keyboard; you have to use Option/Alt 3.  This is made a bit more annoying because ruby’s comments use # so you tend to use it a reasonable amount.

[Still annoying, but you get used to it.]

Conclusions

I must admit I’m surprised out how easy it was to switch from Windows to Mac apart from getting used to the new keyboard shortcuts it’s been plain sailing.  I can understand that this wouldn’t be as easy if you rely on many Windows specific programs however if you didn’t mind running through a vm or rebooting it wouldn’t be a show stopper.

I’m definitely enjoying the experience and I guess the ultimate question is would I go back to Windows?  Now I’m here I can definitely say when buying a computer again and I wouldn’t even think twice about it; I’ll be buying a Mac.

[

In fact I did!  I’ve since bought a 13″ Mac Book Pro.

Things I love:

  • Adjustable backlit keyboard; great at night
  • Those function keys you never use on a PC Laptop?  I find myself always using them on a MacBook can’t put my finger on it but maybe they just seem integrated better.
  • Extremely fast startup/sleep time, you open the lid it’s on, you close the lid it’s off within a second or two.
  • The multi-touch trackpad is fantastic – you’ve got to try it really get it.  Two-finger window scrolling, double-tab and hold to drag, three-finger swipe to go back and forward in the browser it all works so well you’ll really miss these going back to a Windows laptop.
  • Battery life – 8 hours or more; enough said.
  • Mag-safe power adapter; handy for when the cord gets yanked as it doesn’t take your Mac Book with it.
  • MobileMe Syncing; all your contacts and appointments are synced between your iPhone and Macs (without needing to connect your iPhone).

Things I don’t:

  • Glossy screen; for the most part its fine but next time I’ll get a matte screen.
  • VMware Fusion; for me it really hogs the resources on the 13″ (sounds like it’s better on a 15″ model).

]