Tag Archives: tip
This is a quick idea I came up with. We extend the Event native like this:
Event.implement({
hasCapsLock: function(){
return ((this.code > 64 && this.code < 91 && !this.shift)
|| (this.code > 96 && this.code < 123 && this.shift));
}
});
And then access the method from a keypress event:
$('test').addEvent('keypress', function(event){
if (event.hasCapsLock()){
// do something
}
});
The only drawback is that it relies on sniffing alphabet characters and whether the shift key was pressed. This means that if the user presses the caps lock key, you won't know it until another character is inserted.
if ( comments_open() ) { ?>The default shell for Leopard users is Bash. Although many GNU/Linux users are familiar with it, not all Mac users take full advantage of its power. Here are some very useful commands and tips I use routinely.
Users and login
Use the root superuser
sudo su -Alter login variables (such as $PATH, $EDITOR)
nano ~/.profileOther available shells
- /bin/ksh
- /bin/tcsh
- /bin/csh
- /bin/zsh
Files management
Output the contents of a file
cat /some/thingGet 20 lines from the end of a file
tail -n 20 /some/thingGet the first 20 lines of a file
head -n 20 /some/thingCreate an empty file
touch /some/thingRedirect the output of a command to a file (overwrites)
command > /some/thingRedirect the output of a command to a file (appends)
command >> /some/thingAppend the timestamp to a file
touch /backups/backup_`date +%s`.txtChange to the last directory you were in
cd /var
cd /etc
cd - # will take you to /var
List file size in human-readable units
ls -lh /dir/or/file
Available editors
- /usr/bin/vi
- /usr/bin/vim
- /usr/bin/nano
Applications and processes
Run a process in the background
command &List running processes
ps axThe first column will be the PID
Kill a process by pid
kill -9
Kill a process or processes by name (e.g: the Dock)
killall DockOpen an application (Mac-only)
open /Applications/iTunes.app/IE7 supports a custom bicubic resampling mode for images. Before, resizing a 500×500 image like this:
would produce a horrible result in IE, with noticeably lower quality in the resized version.
This is easily fixed in IE7 by applying the following property to the img tag:
img.thumb { -ms-interpolation-mode: bicubic; }
Go to this demo page for a Flickr picture example.
if ( comments_open() ) { ?>PHP provides two very useful functions to create temporary files. Instead of creating unnecessary tmp directories in your applications, it’s better to rely on the global directory assigned for that matter.
To create a unique file with the right permissions use the tempnam function:
$filename = tempnam('/tmp_directory', 'filePrefix');
You can test this from the command line like this:
php -R 'tempnam("/tmp", "hello");'
The output file looks something like this:
guillermo-rauchs-macbook-pro-15:tmp willy$ ls -la hello*
-rw------- 1 willy staff 0 Mar 11 03:26 helloyvEzzb
Couple this function with sys_get_temp_dir and you’ve solved the dilemma:
$filename = tempnam(sys_get_temp_dir(), 'filePrefix');