Inner shadows in CSS3

-webkit-box-shadow (in Webkit nightly) and -moz-box-shadow support inner shadows with the inset keyword. Both also support multiple shadow declarations separated by commas.

Want to achieve the box pictured above?

div.box {
   -webkit-box-shadow: 0 3px 3px rgba(0,0,0,0.20), rgba(0,0,0,0.12) 0px 0px 10px inset;
   -moz-box-shadow: 0 3px 3px rgba(0,0,0,0.20), rgba(0,0,0,0.12) 0px 0px 10px inset;
   -webkit-border-radius: 10px;
   -moz-border-radius: 10px;
   border: 1px solid #fff;
   padding: 6px;
   width: 200px;
   background: #fff;
}

This post has 8 responses

Get ssh-copy-id in Mac OS X

There’s a very convenient shell script bundled with some distributions of OpenSSH called ssh-copy-id. It seems not to be the case with Leopard’s SSH.

In order to get it, we can simply check it out of a SVN repository. Execute this two commands:

sudo curl "http://www.chiark.greenend.org.uk/ucgi/~cjwatson/cvsweb/openssh/contrib/ssh-copy-id?rev=1.8;content-type=text%2Fplain" -o /usr/bin/ssh-copy-id
sudo chmod +x /usr/bin/ssh-copy-id

And you’re done!

This post has No responses

Symfony tip: Watching your logs on mac with Console


Not a big fan of the Web Developer toolbar? Me either! But I do use the logging system quite a bit. Thankfully, OS X ships with an useful application called Console that comes to the rescue.

  1. Open the Console application
  2. Go to File > Open and browse to your frontend_dev.log or desired log file in the symfony logs directory
  3. Click Show Log List and select your newly opened file to avoid the clutter of the rest of the OS logs
  4. You’re done! You can now take advantage of features like clearing the view, search, and more :)

This post has 7 responses

Fix `ereg is deprecated` errors in PHP 5.3

If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.

To migrate ereg():

ereg('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);

Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.

To migrate ereg_replace():

$this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);

becomes

$this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body);

Again, I just added delimiters to the pattern.
If you are using eregi functions (which are the case-insensitive version of ereg), you’ll notice there’re no equivalent pregi functions. This is because this functionality is handled by RegExp modifiers.

Basically, to make the pattern match characters in a case-insensitive way, append i after the delimiter:

eregi('\.([^\.]*$)', $this->file_src_name, $extension);

becomes

preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);

This post has 80 responses

Determine if caps lock is on with MooTools

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.

This post has 10 responses

OS X Leopard command line tips and tricks

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 ~/.profile

Other available shells

  • /bin/ksh
  • /bin/tcsh
  • /bin/csh
  • /bin/zsh

Files management

Output the contents of a file

cat /some/thing

Get 20 lines from the end of a file

tail -n 20 /some/thing

Get the first 20 lines of a file

head -n 20 /some/thing

Create an empty file

touch /some/thing

Redirect the output of a command to a file (overwrites)

command > /some/thing

Redirect the output of a command to a file (appends)

command >> /some/thing

Append the timestamp to a file

touch /backups/backup_`date +%s`.txt

Change 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 ax

The first column will be the PID

Kill a process by pid

kill -9 <pid>

Kill a process or processes by name (e.g: the Dock)

killall Dock

Open an application (Mac-only)

open /Applications/iTunes.app/

This post has 1 response

Tip: High quality CSS thumbnails in IE7

IE7 supports a custom bicubic resampling mode for images. Before, resizing a 500×500 image like this:

<img src="pic.jpg" alt="This image is really 500x500 big" class="thumb" width="50" height="50" />

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.

This post has 34 responses

Tip: Create temporary files in PHP

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');

This post has 1 response

Tip: adjust php.ini settings for a single CLI command

The PHP command accepts some interesting parameters which add flexibility to how scripts that you run from your shell or cron jobs are executed.

One of them is -d, which alters a php.ini value for the duration of the command. An example is as follows:

php5 -d memory_limit=128M symfony propel:data-load

This was a real time saver considering the server was not setup with a CLI-specific php.ini, like some are.

This post has 3 responses

Make Safari create new tabs instead of new windows

Hate those _target=blank as much as I do ? Just run this command

defaults write com.apple.Safari TargetedClicksCreateTabs -bool true

Via: p@rrish blog

This post has 3 responses