Thursday, January 24, 2008

Confirming a Delete using Javascript Confirm

(taken from: http://www.codetoad.com/javascript/forms/confirm_delete.asp)

If you have a page which deletes records from a database, or indeed have any kind of link that you want the user to be doubly certain that they 'mean what they click', using the Javascript confirm event handler is a simple and effective way to get the job done. Here's the effect we're going to achieve:

Click here to return home

Assuming you're still with us and didn't after all return to the home page, you can see that the confirmation makes doubley sure you're aware of what you're doing. (Apparently some sites also use it for asking 'Are you over 18'...)

Now let's look at the script:

Select All Code


Keep all the above on one long line to ensure it works properly.

The key to this code is the phrase return confirm. Just putting confirm by itself wouldn't do much, we have to tell the browser what to do with it's confirmation. Once we tell it to return the users selection (either true for Yes or False for No), the code now simply returns false -- does nothing -- if a No is selected, and if it's true -- a Yes response -- completes the link command and zooms off to the delete page or whatever - Magic!

Tuesday, January 22, 2008

Do a diff on 2 directories

This is a good way to see which files are different in 2 different directories

diff httpdocs httpdocs_test -q -r

Monday, January 21, 2008

SSH Without Password

(taken from: http://www.linuxhorizon.ro/ssh-wo-passw.html)


Sometimes we need a ssh connection that do not ask for passwords. It is use frequently in scripts that involve ssh, scp or sftp connections. I do not encourage this kind of logging but sometimes is very useful...

So, those are the steps to make such connection.

1. Login as user1 on computer1 and generate a pair of authentication keys. Note: even if is unsecured to work without password, do not enter it. Let it empty...

[user1@computer1]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1

2. Login to the remote computer (computer2) as user2 and create the .ssh directory (many Linux distributions create this folder by default. No problem with that.). You still need the password for now...

[user1@computer1]$ ssh -l user2 computer2 mkdir -p .ssh
user2@computer2's password:

3. Copy the user1 public key to user2@computer2 .ssh folder into authorized_keys file. And, type the password again for the last time, hopefully...

[user1@computer1]$ cat .ssh/id_rsa.pub | ssh -l user2 computer2 \
>'cat >> .ssh/authorized_keys'
user2@computer2's password:

4. If all things are OK, you don't need the password

[user1@computer1]$ ssh -l user2 computer2
[user2@computer2]$

..or optionaly (see the troubleshooting section of this page):

[user1@computer1]$ ssh -i $HOME/.ssh/id_rsa user2@computer2

NOTE:
This is the way not only for ssh but also for scp and sftp as well...

TROUBLESHOOTING:
If the password prompt will be shown again check the /etc/ssh/ssh_config and uncomment or insert the following option:

IdentityFile ~/.ssh/id_rsa

As you can see, the above option is for RSA type keys. If you want to generate the key pairs using DSA change the "id_rsa" with "id_dsa". Sound logic, right?
This modification in /etc/ssh/ssh_config file can be avoided if you will use the parameter "-i" followed by the location of the key file as in example:

[user1@computer1]$ ssh -i $HOME/.ssh/id_rsa user2@computer2

Also, if you do have write permissions for either the .ssh directory or for the authorized_keys file on the remote machine, then sshd will consider that the procedure is not safe enough, so it will abort the RSA challenge-authentication mode (mode 3) and will go to the default mode (mode 5) asking you for the password on the remote machine. Set chmod 700 for .ssh folder and 600 authorized_keys file. See http://cag.lcs.mit.edu/~rugina/ssh-procedures/ for more or e-mail me at linuxhorizon@linuxhorizon.ro

Tuesday, January 15, 2008

Apple Mighty Mouse Won’t Scroll Down

(from: http://www.tinyscreenfuls.com/2006/09/apple-mighty-mouse-wont-scroll-down/)

A few times now, the Mighty Mouse on my Mac (the one with the tiny little scroll ball on it) has lost the ability to scroll down. It scrolls upwards, and horizontally, with no problem. Seemed like a software problem to me, and in the past, restarting the app I was using, or the whole Mac, seemed to fix the problem.

It started doing it again this morning, and this time, no amount of rebooting, unplugging/replugging, etc. would work. I figured it had to be a software (or maybe electronic) problem, since if it was just gunked up and dirty, I figured it would impair scrolling in all directions. Not just one.

Well, it turns out, when the Mighty Mouse scroll wheel gets dirty, it stops being able to scroll down. Apparently, it’s a common problem, as a quick Google search turned up tons of pages, like this one at MacOSXHints.com.

The fix? Blow compressed air around the scroll ball, or just push on it really hard and roll it around (that worked for me). If you’re lucky (I was), it will start working again. If it keeps doing it, though, I’m going to have Apple replace it.

What a weird problem. Design flaw? Who knows. I guess it would be better if it were easier to remove and clean the scroll ball. Apple’s official directions for cleaning it are “hold it upside down and roll it around”. Seriously. They even have a video to show you how to do it.

Tuesday, January 1, 2008

Min-Height Fast Hack

(from http://www.dustindiaz.com/min-height-fast-hack/)

Wednesday, September 21st, 2005

I’ve never been one too keen Grey’s css min-height hack, mainly because of the bulky workaround in your html. Sure hacks can cause bulkier CSS, but I’m ok with that. The problem with Grey’s is that it’s not only a ‘CSS‘ hack (which I’m totally fine with), but it also involves changing your html. I’m none too delighted that you need to add two separate empty div elements just to get this working correctly. Nevermind the matter, he thought of this ages ago when I was still learning how to count to twelve on sesame street. Ok so I learned that like last year, I’m catching on.

A New Solution

Assuming each and all you folk know how min-height is ’supposed’ to work, would it be all that bold that it’s safe to say that…well… can’t we just do this? (because that’s what I’ve decided to do after throwing IE5.x out the window)

CSS: min-height with !important

selector {
min-height:500px;
height:auto !important;
height:500px;
}

Assuming IE6 will not fix the correct implementation for the !important declaration and assuming that if IE7 does, they’ll also implement min-height correctly since at the pace they’re going they’re fixing CSS like mad crazy cows. Is that too many assumptions? But wouldn’t you agree?

The above snippet of CSS works like a charm in IE6, Mozilla/Firefox/Gecko, Opera 7.x+, Safari1.2

Update: 2006-05-01 This patch is now fully supported across IE6 and IE7. Gosh, I guess I should have named the hack when I thought of it. Enjoy :)