Google Chrome and 1Password

The new Google Chrome Beta for mac and the alpha 1Password extension work perfectly together!

This post has No responses

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

Turn /etc into a version control system repository

I just discovered a gem called etckeeper, which I’m sure will change the way we’re used to work with server configurations.

The official website describes it pretty well:

etckeeper is a collection of tools to let /etc be stored in a git, mercurial, darcs, or bzr repository. It hooks into apt (and other package managers including yum and pacman-g2) to automatically commit changes made to /etc during package upgrades.

All it took me to set it up on my Debian Lenny slice was:

$ aptitude install etckeeper
# aptitude will install Git as the version control system, which is pretty neat!
$ cd /etc/
$ sudo etckeeper init -m "initial commit"
Initialized empty Git repository in /etc/.git/

The best part is that it’ll detect changes made by apt, commit whatever changes you had made previously, and even enable you to make your own commits, after your manual modifications. Do try it out!

This post has 1 response

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

How to change Wordpress default emoticons

  1. Install the Smilies Themer plugin
  2. Activate it.
  3. Go to Settings > Smilies Themer and pick a theme pack. If you want to create a custom one, keep reading
  4. Create a folder with the name of your theme pack in wp-content/themes/smilies-themer/. In my case I called it devthought
  5. Place your emoticons in that folder and a file called package-config.php

    art

  6. Place a code like this in package-config.php

    <?php
     
    /*
     * Package-Name: Theme name
     * Package-URI: http://yourwebsite.com
     * Package-Description: Your theme description
     * Package-Author: Your name
     * Package-Author-URI: http://yourwebsite.com
     */
     
    $wp_smilies = array(
    	'>:o'      => 'angryface.png',
    	'>:-O'   => 'angryface.png',
    	':-['       => 'blush.png',
    	':['         => 'blush.png',
    );
    // add as many as you want respecting the same format:
    // 'emoticon' => 'file.jpg',
  7. Go to Settings and choose your package!

Now you’re done! :) :[ >:o :o :X :-/ ;) :D o:)

This post has 7 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

Improve your 404 pages with Google

Google Webmaster Tools has a very interesting widget to improve the usefulness of your 404 pages with little or no effort. It brings something like “Did you mean?” for your URLs, suggests links like pages in a higher hierarchy, and adds a Google Search form.

Google 404 Webmaster Tool

First, include this snippet where you want the suggestions to appear. For Wordpress blogs, this is typically the 404.php file in your themes folder1.

<script type="text/javascript">
  var GOOG_FIXURL_LANG = 'en';
  var GOOG_FIXURL_SITE = 'your website url here';
</script>
<script type="text/javascript" 
   src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>

Optionally, edit its look and feel by extending this base stylesheet. Tip: you can hide, for example, the search box, by adding display: none to #goog-wm li.search-goog

<style type="text/css">
    /* Widget content container */
   #goog-wm { }
 
    /* Heading for "Closest match" */
   #goog-wm h3.closest-match { }
 
    /* "Closest match" link */
   #goog-wm h3.closest-match a { }
 
    /* Heading for "Other things" */
   #goog-wm h3.other-things { }
 
    /* "Other things" list item */
   #goog-wm ul li { }
 
    /* Site search box */
   #goog-wm li.search-goog { }
 
    /* Search text input */
   #goog-wm-qt {}
 
    /* Search button */
   #goog-wm-sb { }
</style>

Then you’re done! Check mine out (deliberately wrong url) for an example.

  1. The full path would be /wp-content/themes/yourtheme/404.php. Create it if it doesn’t exist []

This post has 7 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