Rails 3 on debian with Sqlite 3

October 13, 2010

Decided to move to Rails 3 recently and get up to speed on the new framework version.

I list here the process I followed to install it on Debian (Lenny).

*Note, some of these commands need root / administrator privileges. Notably the apt and install commands. Use sudo, su or a root shell.

Install dependancies

# optional VCS, we use Mercurial Locally and Git for deployments to Heroku (hosting)

apt-get install git-core mercurial

# libmysqlclient15off libreadline5-dev
apt-get install build-essential libreadline5-dev libssl-dev zlib1g zlib1g-dev

#optional Database, I have detail for getting Sqlite3 later
#apt-get install mysql-common mysql-server

Install Ruby

wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar xzf ruby-1.9.2-p0.tar.gz
cd ruby-1.9.2-p0
./configure
make
make install

Install sqlite 3

wget http://www.sqlite.org/sqlite-amalgamation-3.7.2.tar.gz
tar xzf sqlite-amalgamation-3.7.2.tar.gz
cd sqlite-3.7.2/

./configure
make
make install

gem install rails sqlite3-ruby

Create your rails app

rails new Items
rails g scaffold Item name:string detail:text
rake db:migrate
rm public/index.html
vim config/routes.rb

add this line:

root :to => "items#index"

then start the server:

rails s

Open your browser and go to http://localhost:3000/

And that’s it!


Favicon/URL/Bookmark icon for you website

October 7, 2010

You can easily create a bookmark icon / URL icon / Domain Icon / favicon.ico for your website.

This is usually called favicon.ico, and usually exists in your web root folder (htdocs, public_html, etc).

Why would you do this?

  1. Your Brand is present in the users Browser URL/URI field in browsers and/or on the browser window or tab title
  2. Your Brand is present in the users browser bookmarks
  3. You user can easily find Your Brand in their bookmarks list – from my perspective, this is a big win.
    1. I have a couple of options bookmarked for the types of online service I use most, and in the cases where one of the sites has no favicon and another does, I inevitably end up using the site that has the favicon, simply because their favicon stands out immediatly in my list of bookmarks.

Your favicon can be a .ico, .gif or .png file.

I use .png more and more. I use a 32×32 pixel file but you can use 16×16 also.

http://en.wikipedia.org/wiki/Favicon

Generally, for the simple/default case, you just name the icon as “favicon.ico” and upload it to the root directory of your website. The broswers will check for it there (http://www.yourdomain.tld/favicon.ico).

You can also use this markup, per page, to have a favicon per page.

<link rel=”shortcut icon” href=”/img/favicon.ico”/>

 


Hibernation Woes – Sleep after Hibernate on Windows 7

May 31, 2010

I have a laptop (Dell Studio 1557) that I have set to go into hibernation when the lid of the laptop is closed.

I have been annoyed for the last while that when I turn on the computer to resume from hibernate, it would immediately shutdown again, but this time in sleep mode.

Today I had a look at the power options, and saw that sleep was set to occur automatically after a number of hours, specific timing depending on whether it was being powered by the mains or battery at the time.

I have disabled automatic sleep and hibernated the computer. This time, when I resume from hibernate, the computer no longer goes into sleep mode. I would have assumed that waking from hibernate would have reset the sleep count-down, but obviously not. Perhaps this will be fixed in a patch sometime ?


Getting longtitude and latitude coordinates from the centre of a google map

August 20, 2009

Googles long/lat is degrees only and a fractional component.

This script
javascript:coord = [gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];
output = '';
for (x in [0,1]) {
neg = (coord[x] < 0);
if (neg) coord[x] *= -1;
deg = Math.floor(coord[x]);
minr = (coord[x] - deg) * 60;
min = Math.floor(minr);
sec = Math.floor((minr - min) * 60 * 100000)/100000;
output += (x==0?'Lat':', Long') + ': ' + deg + "° " + (min < 10?'0':'') + min + "' " + (sec < 10?'0':'') + sec + '" ' + (x==0?(neg?'S':'N'):(neg?'W':'E'));
};
void(prompt('', output));

decomposed that into degrees, minutes and seconds. The output was like the bellow.

Lat: 51° 40' 23.49798" N, Long: 8° 30' 06.43386" W

I wanted it to output degrees, minutes, and then a fractional component like the below, as was required by my Garmin mapping software (I was pulling location coordinates from google maps and inserting them as waypoints/route-vias in my Garmin app for uploading to my GPS device).

N51 40.39163302364358 W8 30.10723114013672

I tweaked it to return same.

I created a bookmark on the Bookmark Toolbar of my browser, and set the code below as the target/URL.

To use it I simply click the bookmark button for it when looking at a google map, and the coordinates for the location at map centre are given in a pop-up box.

Here is my ammended version of script.

javascript:coord=[gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];
output='';
for(x in [0,1]){
neg=(coord[x]<0);
coord[x]=Math.abs(coord[x]);
deg=Math.floor(coord[x]);
minr=(coord[x]-deg)*60;
//min=Math.floor(minr);
//sec=Math.floor((minr - min)*60*100000)/100000;
min = minr;
output+=(x==0?(neg?'S':'N'):(neg?'W':'E'))+deg+" "+(min<10?'0':'')+min+" ";
};
void(prompt('Coordinates',output));

Update: http://netsharc.wordpress.com/2007/06/11/google-maps-latitude-and-longitude/ has the original and a few tweaks.


Mac : Open Terminal/iTerm here

August 19, 2009

Using Mac OS X and browsing the file system with ‘Finder’, I often want to open Terminal or iTerm and have the default path set to the current Finder folder.

Firstly Terminal. I found a script called ‘Open Terminal Here’ at http://jo.irisson.free.fr/?p=59

This seems to suffer from an issue where two windows are opened if Terminal was not already running.

Then I started using iTerm, it has a few more/different options than Terminal. For it I found a script ‘Open iTerm Here’ at http://snippets.dzone.com/posts/show/961

This seems to suffer from a similiar issue to above, where two tabs in a new iTerm window are opened if iTerm was not already running. I tried to modify it (my first apple script attempt) but managed only to get two windows open instead of a single window with two tabs.

Then I found an update to the Open iTerm Here script at http://www.danns.co.uk/node/226

This version successfully solves the issue of the two tabs. If you are a Terminal user, I imagine it should be easy to apply the patch to the Terminal Here script, or just use this script and have it invoke Terminal instead of iTerm.

Finally, to use the script  you then need to save it as an executable app. This is fairly straightforward:

  1. Open the Script Editor application
  2. Past in the source
  3. Save it
  4. Then chose save as
  5. Selected File Format of “Application”
  6. Save it again

You can now use QuickSilver or Silverlight to invoke the script.

However, I wanted to find out if I could add a button to Finder that could be clicked to run it. I eventually found out how to do this and here is how. You can simply drag the script .app file onto the top of the Finder application, and a button is created for it there.

So, when looking at a folder, just click the new button you created and a new iTerm is opened at the current path.

Lastly, I wanted to change the icon from the default. I wanted to use the iTerm icon. To do this, follow these steps to copy and paste the icon from the iTerm application:

  1. Go to Applications
  2. Navigate to iTerm
  3. Select the More Info… button
  4. Find your iTermHere.app and do the same
  5. Click the small icon at the top of the iTerm more info window and click cmd-c (apple-c, the shortcut to copy text)
  6. Click the small icon at the top of the iTermHere.app more info window and paste! (apple-v)

That’s it, you now have the script as an app, with a button in the Finder windows, and a nice iTerm icon.

Many thanks to all the folks involved in creating and refining these scripts I found, as linked to above.

Enjoy.


Clearing the MySql Logs

August 19, 2009

mysql> show master logs;

+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000023 | 1074039776 |
| mysql-bin.000024 | 1023334365 |
| mysql-bin.000025 | 1073742100 |
| mysql-bin.000026 | 4254255    |
| mysql-bin.000027 | 117        |
| mysql-bin.000028 | 98         |
+------------------+------------+
6 rows in set (0.00 sec)

mysql> purge master logs to ‘mysql-bin.000028′;
Query OK, 0 rows affected (10.35 sec)

mysql> show master logs;
+——————+———–+
| Log_name         | File_size |
+——————+———–+
| mysql-bin.000028 | 98        |
+——————+———–+
1 row in set (0.00 sec)

 

mysql>


On demand “Tailing” of a database log table: select the last x records

August 19, 2009

Recently I had to monitor some data being output to a log table while an application was running.

The log table was quite large, and being written to constantly and also by portions of that system I wasn’t interested in.

So I only wanted to see the 10 or 20 most recent rows / records written.

There are quite a few ways to do this, but this is what I threw together. It assumes the ordering is based on an incrementing unique record id.

select count(*) into @rowcount from prodlog; select id, source_id, created_on, message from prodlog where id > (@rowcount-20) order by id;

I put the latest count of records in the table into a temporary variable. I then use that figure, minus the number of rows I want to see, to offset into the data.

Note that if the count of rows and row ids don’t match (e.g. because you used truncate) the above method will fail.

In this case you may use:

select id into @last_id from prodlog order by id desc limit 1; select id, source_id, created_on, message from prodlog where id > (@last_id-20) order by id;

This is still potential issues with this, for instance you may get less than you expected if there are gaps in the id sequence.

But it sufficed for my needs at the time :)


Hash/Pound/# characters in links, alternative links that don’t change the URL in the users broswer !

August 18, 2009

An interesting alternative to href="#thisgoesnowhere", which causes the insertion of the “#” character and any following characters (“thisgoesnowhere” in this silly example) to the end of the URL, is to use a null javascript link target.

href="javascript:void(0);"

In this case, your onclick or other events are treated as before, but your page URL hasn’t needlessly changed.

Example 1 – null javascript link: Cannot prove here as wordpresss filtering removes the “javascript” piece from “javascript:void(0)”. So there you go, a caveat to the use of this sor tof thing. But on your own site, without filtering of the html, it’s pretty handy, esp for some dynamic sites with background actions, animations, etc.

Example 2 – hash link: Note the current URI, now try this link. Thee URI has changed to have “#thisGoesNowhere” appended to the end, right ? Not very nice, and if your URI is shared or bookmarked, this may have unintended consequences.


VNC server : Fatal server error: could not open default font ‘fixed’

August 18, 2009

Trying to run vnc-server recently on a debian system, I ran into the following issue:

cat .vnc/debian-dev\:1.log
14/08/09 14:40:01 Xvnc version 3.3.7 - built Dec 30 2006 12:50:35
14/08/09 14:40:01 Copyright (C) 2002-2003 RealVNC Ltd.
14/08/09 14:40:01 Copyright (C) 1994-2000 AT&T Laboratories Cambridge.
14/08/09 14:40:01 All Rights Reserved.
14/08/09 14:40:01 See http://www.realvnc.com for information on VNC
14/08/09 14:40:01 Desktop name 'X' (debian-dev:1)
14/08/09 14:40:01 Protocol version supported 3.3
14/08/09 14:40:01 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/truetype/' not found - ignoring

Fatal server error:
could not open default font 'fixed'

I solved the issue with some apt-get for dependancies as per below

apt-get install xutils xbase-clients xfonts-base xfonts-75dpi xfonts-100dpi

Ref:  http://www.debianhelp.org/node/5720


QuickSilver-esque shortcuts application on Ubuntu Debian GNU/Linux

October 6, 2008

Some of my colleagues have Apple Macs and use an application called ‘Quick Silver’ for managing frequently use application/scripts/text files/notes/ims/etc.

I was impressed with what one could do with it and began looking for something similar on Ubuntu.

There is a clone for Gnome called Gnome-Do [ http://www.gnomedo.com ] that lives up to the task pretty well from what I can gather so-far. There are some good updates in the ‘Intrepid Ibex’ release (8.10) that are not in the ‘Hardy Heron’ release (8.04), such as a more complete and useful preferences menu, more plugins and managing them individually through the applications preferences.

Try it out, after installing gnome-do, you need to set it up to launch at gnome login (easily done via the preferences in the intrepid version). Then you can invoke it with the SUPER+SPACEBAR short-cut.


Follow

Get every new post delivered to your Inbox.