» tagged pages
» logout
User:alex
Return to User:alex

Tips and Tricks

(or Cancel)

(Editing anonymously: to be credited for your changes, login or register a new account)

other page actions:

Tags Applied to this Topic

1 person has tagged this page:

Sometimes I find a tip or a trick that I think is cool – I’ll post them here.

Friday, September 29, 2006

Where is Frontrow?

If you are like me, and have a new Apple brand Macbook – you might have heard of this application called ‘frontrow’ that is supposed to work with your little remote and play cool movies and music and stuff.

However if you are also like me, you might not know how to get to Frontrow, you might have looked all over the fricken application folder and itunes and everywhere to find where it is, and given up on it entirely.

Well I’ve finally solved the mystery of front row: point your remote at your macbook and press ‘Menu’ – amazing 3d media center action awaits.

Monday, July 31, 2006

Using PHP's strtotime to calculate dates is a no-no

I’ve been working on a new SWiK feature, and it included some functionality to show stuff over the month, with the option to go back months and view them in more detail.

In coding up this feature, I thought I would take a shortcut around actually calculating the dates and use the strtotime function in PHP, which can take a string like ‘-1 month’ and turn it into last month’s Epoch time.

That’s what I thought at least.

Turns out, today I discover you should never actually depend on this functionality. PHP interprets ‘-1 month’ to mean ‘-30 days’. This means that on July 31st, strtotime will think that -1 month was July 1st. This of course plays havok on July 31st, and slowly but subtley over time previous to that.

Needless to say, a frustrating bug, which I’ve read on php.net is actually by design; go figure :/

Monday, July 03, 2006

Debugging Javascript in Safari

There’s a hidden ‘cheat’ menu in Safari for debugging, and since Webkit has a ways to go in bringing JavaScript support up to par, this can be a very useful menu.

Probably of most use is ‘console.log’ – a Safari function that allows a Javascript developer to write to a log while debugging, instead of the all too common alert().

To enable the cheat menu, open a Terminal window and type:


defaults write com.apple.Safari IncludeDebugMenu 1

Restart Safari and you will see a new debug menu with all sorts of nifty tools including the console.log.

BTW you can also use console.log() in Firebug for Firefox, I’ve used it and it’s a really good tool.

Wednesday, June 07, 2006

POST in PHP without cURL

If you want to do a HTTP Post in PHP, you can use this nifty function that doesn’t require cURL:


/* sendToHost
 * ~~~~~~~~~~
 * Params:
 *   $host      - Just the hostname.  No http:// or 
                  /path/to/file.html portions
 *   $method    - GET or POST, case-sensitive
 *   $path      - The /path/to/file.html part
 *   $data      - The query string, without initial question mark
 *   $useragent - If true, 'MSIE' will be sent as 
                  the User-Agent (optional)
 *
 * Examples:
 *   sendToHost('www.google.com','GET','/search','q=php_imlib');
 *   sendToHost('www.example.com','POST','/some_script.cgi',
 *              'param=First+Param&second=Second+param');
 */
function sendToHost($host,$method,$path,$data,$useragent=0) { // Supply a default method of GET if the one passed was empty if (empty($method)) { $method = 'GET'; } $method = strtoupper($method); $fp = fsockopen($host, 80); if ($method == 'GET') { $path .= '?' . $data; } fputs($fp, "$method $path HTTP/1.1 "); fputs($fp, "Host: $host "); fputs($fp,"Content-type: application/x-www-form- urlencoded "); fputs($fp, "Content-length: " . strlen($data) . " "); if ($useragent) { fputs($fp, "User-Agent: MSIE "); } fputs($fp, "Connection: close
"); if ($method == 'POST') { fputs($fp, $data); }
while (!feof($fp)) { $buf .= fgets($fp,128); } fclose($fp); return $buf; }

Wednesday, April 19, 2006

OSX Evil Black Boxes

Sometimes in OSX, evil black boxes will appear all over your screen.

Some applications will feature them more than others, and you might think this is some kind of corruption in your video card or bad RAM.

What it actually is is the voiceover accessibility feature in OSX. Those black boxes can be made to disappear by going to your settings and disabling the voiceover feature.

Sunday, March 26, 2006

Create keyword searches in FireFox

There’s a really easy way to create keyword searches in Firefox, but it’s hidden away in a context menu where you might never find it.

If you are in a search box, right click and select ‘add keyword for this search’

after that, you can just type the word in your location bar, and your custom search will execute. Super easy, but kind of hard to find if you gloss over the context menus.

Monday, March 20, 2006

Secret Textile Link Hack

Someone contributed an edit the other day that highlighted to me a cool feature I didn’t know about in Textile.

If you want to do a link, the traditional textile way to do it is:

<a href="http://linkaddress">link title</a>

but this can get messy in the formatting

a cleaner way to accomplish this is a hidden feature in textile:

<a href="linkname">link title</a>

[linkname]http://linkaddress

this creates the same link, but keeps url messyness separate.

Monday, March 20, 2006

Screenshots in OSX

It’s simple to take screenshots in OSX

The simplest way is to do OpenApple-Shift-4 (why do I want to say open apple?, it’s just the command key)—this captures a selected region of screen and conviently mucks up your desktop with another file, a pdf of the selected region.

You can read more in this article on hacking OSX screen capture to the extreme

What if you want to save a big document, such as a long HTML page, that spans many screens on your monitor? An easy method, that’s built right into Mac OS X, is to convert it the page to a .pdf file.

Thursday, March 02, 2006

Getting a Start Menu in OSX

Mac OS X doesn’t come with a start button, like in Windows or KDE.

But what you can do is drag folders to the dock.

So to get a ‘start menu’, just drag your applications folder to the dock, and then click and hold to see the contents.

It’s a good way to access your less frequently used applications and keep your dock clean.

Friday, February 24, 2006

MySQL - MD5 Schema

When you are storing MD5s in MySQL, sometimes the tendency is to go for excessively long varchars: varchar 255, varchar 128

All that is necessary for storing MD5s is Varchar (32)

this will speed things up, so next time you are creating a mysql schema that includes MD5s, just use a VARCHAR (32)

Sunday, February 19, 2006

Email Validation - Watch for + and _

Validating email addresses can be tricky.

Two characters that often trip up validators are ’+’ and ’_’, both of these are valid in an email address:

  • alex_bosworth@mail.com = valid
  • alex+bosworth@mail.com = valid

Thursday, February 16, 2006

OSX Firefox Horizontal Scroll

OSX’s version of Firefox got rid of an annoying ‘feature’ that moved you backwards and forwards in your browser history when you horizontally scrolled with the trackpad.

You may now scroll around the trackpad with impunity.

Woot.

Thursday, February 02, 2006

PHP multi-sort

I like this function in PHP:


function multi_sort($array, $akey)
{
  function compare($a, $b)
  {  
     global $key;
     if ($a[$key]>$b[$key]){
         $varcmp = "1";
         return $varcmp;
     }
     elseif ($a[$key]<$b[$key]){
         $varcmp = "-1";
         return $varcmp;
     }
     elseif ($a[$key]==$b[$key]){
         $varcmp = "0";
         return $varcmp;
     }
  }
  usort($array, "compare");
  return $array;
}

You call this function like this:
$array = multi_sort($array, $key = ‘keyName’);

this will set the array to a sorted version sorted by key ascending

Thursday, January 19, 2006

Watching a File

‘watch’ is a useful tool for watching a file:

watch tail -n 30 ./logs/access_log

you can leave that open and take a look at what is going on in a file. On httpd access logs you can see who is currently hitting your server.

Wednesday, January 18, 2006

Tag Combinations On Flickr

It’s not really obvious how to do tag combinations on Flickr. Here’s how:

First Tag

Another Tag

Photos tagged Seattle and SpaceNeedle: http://flickr.com/photos/tags/seattle,spaceneedle/

N Tags

Photos tagged Seattle and SpaceNeedle and Fireworks: http://flickr.com/photos/tags/seattle,spaceneedle,fireworks/

Thursday, January 05, 2006

Finding a command you have used before

If you are sitting at a bash terminal and are trying to remember a command that you have used before:

Typing cntrl+r will bring up a history search that will autocomplete the command you are looking for.

Can be helpful just as a time saver.

Thursday, January 05, 2006

Showing source code of PHP Files

To show the source code of php files, on many server configurations you can simply append ’s’ to the filename.

Example: To show the source of index.php, rename it index.phps

Warning: This may reveal passwords that are coded in your php file.

Username:
Password:
(or Cancel)