Archive for the ‘Code’ Category

Kill all PHP Processes on Unix

No Comments » by Jon Hibbins on 4 January 2012
Filed under: PHP, Quick Tips, Uncategorized, Unix/Linux

You can kill all the PHP processes in Unix with the following command :

killall php

Android Mobile SDK Web Browser Testing on OSX

No Comments » by Jon Hibbins on 3 October 2010
Filed under: Code, HTML, OSX, PHP, Platform, Quick Tips, Web

Because it’s painful, here’s how I did it on OSX :

1) Download Android SDK

2) Install it

/Android/android-sdk-mac_86
cd /Android/android-sdk-mac_86/tools

3) Setup the Emulator

./android
  • A Java app opens
  • Click SDK Platform Android 2.1 and download Archive for MacOS X
  • Click Virtual Devices and New
  • Give a name (AndroidTest), set the target to the SDK you downloaded
  • Set Size to 512
  • Create the AVD (Android Virtual Device)

4) Run the Emulator

./emulator -avd AndroidTest -partition-size 128

5) Setup the Hosts file

Set the device to read-write

./adb remount
./adb pull /etc/hosts

Edit the hosts with the following

nano hosts
10.0.2.2 localhost
./adb remount
./adb push hosts /system/etc

Congratulations you should now be able to browse the hosts

TSQL Date Only Function

No Comments » by Jon Hibbins on 24 November 2009
Filed under: Code, Database, MSSQL2005, MSSQL2008, Quick Tips, Software Development, SQL Server, TSQL

CREATE FUNCTION [dbo].[DateOnly] (@DATE DATETIME)
RETURNS DATETIME
BEGIN
    RETURN DATEADD(d, DATEDIFF(d, 0, @DATE), 0)
END

TSQL Last Day Of The Month

No Comments » by Jon Hibbins on 23 November 2009
Filed under: Code, MSSQL2005, MSSQL2008, Quick Tips, SQL Server, TSQL

CREATE FUNCTION [dbo].[LastDayOfTheMonth] (@DATE DATETIME )
RETURNS DATETIME
BEGIN
    RETURN dateadd(ms, -3, DATEADD(mm, DATEDIFF(m, 0, @DATE) + 1, 0))
END

Zend Server CE on OSX 10.6 Snow Leopard

No Comments » by Jon Hibbins on 18 October 2009
Filed under: MySQL, PHP

When I installed Zend Server CE on OSX 10.6 Snow Leopard the admin interface failed, the following fixed the issue :

1. Download this: Watchdog update

2. Backup watchdog with the command

sudo mv /usr/local/zend/bin/watchdog /usr/local/zend/bin/watchdogOLD

3. Extract the new watchdog to /usr/local/zend/bin/ (I used the go to folder in finder, if you can view hidden files)

4. Run the following command to restart the Zend server

sudo /usr/local/zend/bin/zendctl.sh restart

4 Coding tips

No Comments » by Jon Hibbins on 26 August 2009
Filed under: .NET, C#, Code, Java, Objective-C, PHP, Quick Tips, Software Development

1: Delete It !
If a chunk of code comment or class is not used, don’t comment it out, just delete it.

2: Write clear code.
“make sure you document code that’s hard to understand”. Question: why is the code hard to understand?

3: Comment
Comments can indeed be useful but mostly as a summary of action

4: Don’t Repeat Yourself
Duplication is bad. If you have more than 4-5 lines of code that do the same thing in a single class, refactor to remove duplication.

Check if a Javascript function exists

1 Comment » by Jon Hibbins on 22 March 2009
Filed under: Code, Javascript, Quick Tips

If you want to check if a Javascript function exists before you attempt to call it and get an error try:

// Check if a Javascript function exists and run it if it does
if(typeof window.Function == 'function') {
    Function();
}

iPhone 3.0

No Comments » by Jon Hibbins on 17 March 2009
Filed under: Code, iPhone, Objective-C, Platform, Software Development

Apple has announced the iPhone 3.0 software update which includes an updated Software Development Kit (SDK) with over 1,000 completely new APIs.

Here are a few highlighted features:

  • Search your iPhone
  • Cut, copy, and paste
  • Send photos, contacts, audio files, and location via MMS*
  • Read and compose email and text messages in landscape

And yes, I am running it (I have an Apple Developer Account), and so far I found one bug (on safari re-highlighting the address bar can sometimes make the address disapear) and an un-announced fearure (the call history list is now much more verbose)

SVN Port TCP Port is 3690

1 Comment » by Jon Hibbins on 12 February 2009
Filed under: .NET, C#, Code, OSX, Platform, Quick Tips, Software Development, Unix/Linux, Windows

If you need to access SVN remotely, by default it runs on port TCP port 3690, so you need to make sure it is open in your firewall etc.

SQL Server Schema,Table,Function and Stored procedure Auditing

1 Comment » by Jon Hibbins on 17 December 2008
Filed under: Code, iPhone, MSSQL2005, MSSQL2008, Objective-C, Software Development, SQL Server, TSQL

If you like to know what’s changing on your SQL Server then the following code creates an audit table and the associated trigger for logging the changes

The Audit Object Table

CREATE TABLE [dbo].[AuditObjects](
 [EventID] [INT] IDENTITY(1,1) NOT NULL
,[EventData] [xml] NULL
PRIMARY KEY CLUSTERED (
   [EventID] ASC
) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

And the associated Trigger

CREATE TRIGGER [TriggerAuditObjects]
ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS
INSERT INTO [dbo].[AuditObjects](EventData)
SELECT EVENTDATA()
GO
ENABLE TRIGGER [TriggerAuditObjects] ON DATABASE

You can now use xpath queries to analyse the data