Deploying your Rails 3 app to Heroku from Debian GNU/Linux

October 11, 2010

Deploying apps to Heroku is as simple as

git push heroku master

But you need a little bit of setup first.

If you haven’t got git, install it with

apt-get install git-core

You will also need the Heroku gem

gem install heroku

Then set up your app, adding the files to the git repository

cd myapp
git init
git add *
git commit -m 'first commit, using git for pushes to heroku which hosts rails apps free and uses git'

Create a key for secure authentication to Heroku

ssh-keygen -t rsa -C "me@mycompany.com"
heroku keys:add

Create your heroku app

heroku create

And push your new rails app to it

git push heroku master

Now browse to the url you were given in previous steps as feedback from heroku, and you should see your app, now live !


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”/>

 


Debian : Apache : PHP : Database Error: Unable to connect to the database:The MySQL adapter “mysql” is not available.

May 28, 2010

Got this today when I browsed to my Joomla site, which I had just imported from elsewhere.

Database Error: Unable to connect to the database:The MySQL adapter "mysql" is not available.

Setting the correct database password in the joomla configuration file fixed the issue.


Sed and Print in Perl

February 15, 2010

I recently needed a sed-like script for a web based perl app doing to internally convert request ports and came across some interesting print code in the process of testing it

#!/usr/bin/perl

sub println
{
$\ = "\n";
@_ = ($_) unless @_;
print @_;
}

 

my $sec = "https://dmom.domain.com:633/confirm/me/";
$sec =~ s/:633/:81/;
println $sec;


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.


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.


Spoofing your Browser user agent in Firefox

March 31, 2008

Web servers sometimes behave differently for different browsers, for compatibility reasons usually, but not neccessarily.

If you want to test how a system or site behaves for different browsers, plugins for firefox such as the ‘User Agent Switcher‘ can help. With it you can enter any data for the User Agent string.

The User Agent String is essentially a text string that your browser sends with each request to tell the server what browser, operating system, extensions/plugins, etc you are using.

I didn’t initially find the format or usage of this plugin to be very intuitive, but thankfully there are importable files online with settings for many of the more common combinations of browser/os etc. One such list I have used is at http://qainsight.net. Check for updates to the version of the script. Right now the site is offline, but the latest (March 2008, from internet caches) appears to be here.

Last I read it does not properly cater for the different User Agent String formats of other browsers, for instance the IE and Firefox string are quite different in both content and organisation. So while it will usually work, it may sometimes fail, and will probably not hide the fact of what browser you are actually using from those who might really want to know…


Follow

Get every new post delivered to your Inbox.