Posts

Setting up Apache To Work with PHP and Zend Framework in Fedora for Development

To get started the first thing we need to do is install Apache and PHP. yum install httpd php You can setup Apache to run in any users public_html directory but I am the only one using my computer and I like to name my websites directory whatever I want so we have to create the folder and give Apache permissions to it: mkdir ~/websites chmod 711 /home/accessrichard chmod 755 /home/accessrichard/websites After that we have to set Apache to redirect our localhost traffic to the above website directory. Create your own Apache config file in /etc/httpd/conf.d touch /etc/httpd/conf.d/accessrichard.conf Add something similar to the following in the file we just created replacing your home directory name and your website folder name as appropriate. In the below example I am setting up 2 different websites, demo.dev and demo2.dev. NameVirtualHost *:80 < VirtualHost *:80 > ServerName demo.dev DocumentRoot /home/accessrichard/websites/demo/public SetEnv APPLICATION...

Set MySql Timezone information on Linux

In order to use the MySQL CONVERT_TZ() function on Linux which converts a datetime from one timezone to another, MySql needs timezone definitions and offsets which is dependent on the operating system in use. Otherwise CONVERT_TZ() returns NULL values. To do this on Linux, use MySQL's utility script, " mysql_tzinfo_to_sql ". Example usage: mysql_tzinfo_to_sql /usr/share/zoneinfo This returns a sql script to run to setup the timezone information. The following will setup the timezone information directly: mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql Now you can view your timestamps in local timezone: SELECT CONVERT_TZ('2010-01-02 00:00:00', 'UTC', 'America/Chicago' );

Java equivalent to MySql and PHP SHA1

The following code snippet demonstrates Java's equivalent to PHP and MySql's SHA1 function: import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class SHA1Test { public static void main(String[] args){ String hashStr = null; String password = "password"; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(password.getBytes()); BigInteger hash = new BigInteger(1, md.digest()); hashStr = hash.toString(16); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } System.out.println(hashStr); //outputs: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 } } mysql> select sha1('password'); +------------------------------------------+ | sha1('password')                         | +------------------------------------------+ | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 | +----------...

Inserting Into Sql Server Identity and Default Columns

For some reason I always try to insert default or null into Sql Server identity or default columns. So that I remember here is how to do it when not explicitly listing the columns list. When inserting into a table with an identity column, exclude the identity column from the values column list. e.g. Pretend the columns doesn't exist. When inserting into a table with a default column, use the DEFAULT keyword. DECLARE @Test TABLE( id INT IDENTITY(1,1), fname VARCHAR(30) not null, lname VARCHAR(30) not null, ts DATETIME DEFAULT GETDATE() ) INSERT INTO @Test VALUES('Joe', 'Somebody', DEFAULT) SELECT * FROM @Test GO Which results in: id fname lname ts --- ------ -------- ----------------------- 1 Joe Somebody 2011-01-30 12:37:20.353 (1 row(s) affected)

AutoItX4Java - Java AutoIt Bridge

AutoIt is a very useful automation scripting language for Microsoft Windows. It allows for GUI automation using a very simple syntax and can be useful for testing applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects. I just created a new project on Google Code for Java AutoItX bindings. The project is called AutoItX4Java and uses the JACOB Java COM Bridge to access AutoItX functions. Currently the project is in an unstable state but hopefully as time goes on things will get better tested. Using AutoItX4Java is simple: Download JACOB . Download and install AutoIt . (or register the dll. See below) Add jacob.jar and autoitx4java.jar to your library path. Place the jacob-1.15-M4-x64.dll file in your library path. A simple example of using this library is below: File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll System.setProperty(LibraryLoader.JACOB_DLL_PATH, file...

Automated web testing with Java, Selenium RC, LoggingSelenium, HtmlUnit and TestNG

I used the  Selenium  web automation framework extensively for a suite of websites I had tested. Over the course of a year I had ended up with a complete automation framework for a suite of websites. This resulted in lots of project specific code. Now that I need to use Selenium for other sites I thought I would write about setting things up at a basic level which includes using HtmlUnit, Selenium, LoggingSelenium, starting the Selenium server through java and using TestNG. Getting Setup Download Selenium RC and Selenium IDE from http://seleniumhq.org/download/ . Selenium IDE will install right into Firefox as an add-on. I am using Selenium RC 1.0.3. Download LoggingSelenium from http://sourceforge.net/projects/loggingselenium/files/ Download TestNG from http://testng.org/doc/index.html Extract the files into your projects library folder and add the following 4 jars to your project: selenium-server.jar selenium-java-client-driver.jar logging-selenium-1.2.jar ...

The SQL Server and .Net equivalent of PHP and MySQL's SHA1 function

In PHP and MySql there is an sha1(str) function which generates an sha1 hash of a string. Their usages are simple: <?php echo sha1('password'); ?> //Outputs:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 mysql> select sha1('password'); +------------------------------------------+ | sha1('password') | +------------------------------------------+ | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 | +------------------------------------------+ 1 row in set (0.00 sec) Similarly, .Net has an SHA1 method within the System.Security.Cryptography  namespace which can be used in the following manner to generate the same hash. public static string Sha1(string hashStr, Encoding encoding) { var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); var hash = sha1.ComputeHash(encoding.GetBytes(hashStr)); return BitConverter.ToString(hash).Replace("-", ""); } Console.WriteLine(S...