Suspend/Lock your mac (the missing Windows + L Shortcut)

 

I tried looking for a quick lock button on my mac just like (Windows +L) on my PC and I couldn’t find anything decent. Finally found a terminal command that would suspend the mac. Using the apple script editor you can make this in to a custom app.

/System/Library/CoreServices/"Menu Extras"/User.menu/
Contents/Resources/CGSession –suspend

(All in one line)

Link to previous post with Apple Script example

Posted in Uncategorized | Leave a comment

Mac SSH terminals with saved passwords (how make your own scripts)

This is probably not the best way to do this, but this allowed me to create several click-able shortcuts on the DOCK that opens the terminal app, connects to the correct server with the password, sets the correct directory and is ready for me to do anything else I like. Its rather simple.

  1. Open ‘Apple Script Editor’ (Use spotlight to find it (cmd+space))
  2. Copy and paste the code below, change it to match your server details.
  3. Test it and then save as application (and save a copy as a script so that you can make new ones from the source in the future)

tell application "Terminal"
	activate
	do script "ssh delta@dckzone.com" in window 1
	delay 2
	do script "mysuper password" in window 1
	delay 2
	do script "cd /www/mysite/" in window 1
end tell
Posted in Apple, OSX, Unix | Tagged , , | Leave a comment

PHP: Get Client IP address

	function getIP(){
		$ip ="";
		if (getenv("HTTP_CLIENT_IP")) {
			$ip = getenv("HTTP_CLIENT_IP");
		} else if(getenv("HTTP_X_FORWARDED_FOR")) {
			$ip = getenv("HTTP_X_FORWARDED_FOR");
		} else if(getenv("REMOTE_ADDR")) {
			$ip = getenv("REMOTE_ADDR");
		} else {
			$ip = "UNKNOWN";
		}
		return $ip;
	}
	$clientIP = getIP();
Posted in PHP | Tagged , | Leave a comment

CSS – Embedding Custom Fonts

Adding your own or 3rd party fonts

@font-face {
      font-family:myfont;
      src:url(http://valid_url/my_font.eot);
}
Posted in CSS, HTML | Leave a comment

Drag and drop (draggable) desktop apps – Adobe Air

This bit of code in your main html header will allow your Adobe Air app to to draggable.

document.onmousedown = function() { window.nativeWindow.startMove(); }}
Posted in Adobe Air, HTML, JavaScript | Tagged , | Leave a comment

PHP: Get uploaded file extension

Here is a bit of code to quickly get the letter after the last dot of a file.

$ext = end(explode('.', $_FILES['formElementName']['name']));

Split the name by dots and pick the last one!

Posted in Uncategorized | Tagged | Leave a comment

Manipulate multiple rows of data with a single query

The following query can be used to update multiple rows of of data in relation to existing data in the same rows. I only needed to add +1, but you can perform almost any operation. E.g. increasing the price of items in a table by 10%.

UPDATE `ranks` SET `rank` = rank+1 WHERE `id` >= 3

 

To update a column with an unique index you’ll have to update the highest value or lowest value (depending on what you’re doing) by ordering correctly.

Just sharing a bit of code I found helpful.

Posted in Database | Tagged | Leave a comment

Replacing MacBook Optical drive with a hard disk

I expanded my MacBook hard disk space by replacing the Optical drive with a enclosure that can hold a second hard drive.

http://www.ebay.co.uk/itm/270778424788?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649#ht_855wt_893 is what I used on my mid 2010 15’ MacBook Pro here.

First things first, I need to remove the cover.

P1100174

 

Insides of my Mac

P1100054

 

Optical drive removed

P1100057

 

Preparing the replacement drive

P1100063

 

You need to attach a few extra screws to

P1100061

 

And finally placing the replacement drive inside the MacBook Pro.

P1100133

Posted in Apple | Tagged , , | Leave a comment

Skipping Open Office Registration Screen

Had a bit of trouble with the Open Office registration screen. It just didn’t want to go away even after entering details.

Finally got rid of it by adding -nofirststartwizard to all the shortcuts like this.

“C:\Program Files\OpenOffice.org 3.0\program\sbase.exe” -nofirststartwizard
“C:\Program Files\OpenOffice.org 3.0\program\scalc.exe”  -nofirststartwizard

Posted in Open Office | Leave a comment

Cleaning out all $_REQUEST ($_POST and $_GET)

This is a lazy way to make sure you won’t forget to escape date before adding them to a query string.

foreach($_REQUEST as $key => $value){
    if($_REQUEST[$key] != mysql_real_escape_string( $value )) die('Bad command');
}
Posted in PHP | Leave a comment