Wednesday, April 16, 2008

Adding a Column to JSON using Coldfusion8

I use Spry to output a lot of queries that I use in my projects.

So I call my coldfusion function from Spry


var ts = new Date();
var spry_ContactList = new
Spry.Data.JSONDataSet("module_contacts.cfc?method=qry_ContactsList &returnFormat=json& queryFormat=column&TS=" + ts.toString(),{path:"DATA", pathIsObjectOfArrays:true});


There are a couple of things to note here, first of I am using Coldfusion 8's new returnFormat=json to return the query that resides in my function, as well as this I am also using queryFormat=column. Finally I have added on a date string to prevent browsers such as IE6 from caching the request.

So based on the above I can return my query as JSON, however I found that any dates were being returned in a fairly ugly way eg. March 21, 2008 00:00:00. I wanted to remove the dates and on consulting with a couple of people I came to the conclusion that doing this in Javascript would not be the best solution so I added the following after the query in my function.


<cfset tempArr = arrayNew(1) />
<cfloop query="qry_ContactsList">
<cfset arrayAppend(tempArr, "#DateFormat(qry_ContactsList.visitdate,'dd-mm-yyyy')#")/>
</cfloop>
<cfset qry_ContactsList.addColumn("PRETTYDATE", tempArr) />


This created an additional column in the JSON that was returned, and I could now display the date as I wanted to.

Tuesday, April 15, 2008

Change the Date and Timezone in Centos

Log into your server then retrieve the current date and timezone by typing in

date


all timezone information is stored at /usr/share/zoneinfo you can browse to this by typing

cd /usr/share/zoneinfo


you should see a list of all the available timezones including folders for countries which have multiple time zones eg. America

so to change the time zone just enter the following

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime


If you then want to manually set the time to 30/03/2008 09:57, the format to enter the date is 'mmddhhmmyyyy'
033009572008


The following command will update your hardware clock
hwclock --systohc


And now when you type in 'date' you should see an up to date clock

Saturday, March 29, 2008

Setting up VSFTPD

The virtual machine I used was a centos 5 linux distribution, I then installed VSFTP

1. Install VSFTPD
[root@localhost]# yum install vsftpd


2. Make sure vsftpd starts on bootup
[root@localhost]# chkconfig vsftpd on


3. Switch of anonymous ftp access
[root@localhost]# vi /etc/vsftpd/vsftpd.conf

then change the line to
anonymous_enable=no


4. You can change the greeting you see when you connect to the ftp server by changing the line
tpd_banner= New Banner Here


5. Create a user group and shared directory. In this case, use /var/www/vhosts and a user group name of ftp-users for the remote users
[root@localhost]# groupadd ftp-users
[root@localhost]# mkdir /var/www/vhosts


6. Make the directory accessible to the ftp-users group.
[root@localhost]# chmod 775 /var/www/vhosts
[root@localhost]# chmod 775 /var/www


7. Add users, and make their default directory /var/www/vhosts
[root@localhost]# useradd -g ftp-users -d /var/www/vhosts user1


8. Change the permissions of the files in the /var/www/vhosts directory for read/write only access by the group
[root@localhost]# chown root:ftp-users /var/www/vhosts*


9. Restart the VSFTPD service using
[root@localhost]# service vsftpd restart


10. Make sure you are not blocking ftp ports to the server (ftp requires port 21 to be open)
system-config-securitylevel


11. After configuring the vsftpd server on an Amazon ec2 server , I was not able to connect to vsftpd in one server from my ftp client. It throws the error:

500 OOPS: vsf_sysutil_recv_peek

The solution for this problem is to load capability module:

# modprobe capability


12. If you are having trouble connecting with an FTP client (such as FileZilla) and receiving an error like below

Error: Could not read from socket: ECONNRESET - Connection reset by peer
Error: Disconnected from server
Error: Failed to retrieve directory listing

Then make sure you change the connection settings in the client to 'active' rather than 'default'

Friday, February 29, 2008

Import a CSV file into MySql

I recently received a CSV file that I needed to import into MySQL, I tried to use Navicat on a Windows machine but the file was large enough to cause it to hang. So I went to the command line on the server and created it as follows

mysqlimport --fields-terminated-by="," --fields-optionally-enclosed-by="\"" --lines-terminated-by="\n" databasename /pathtocsvfile/csv.csv -u mysqlusername -p

note that the name of the file I was importing was csv.csv, in order for this to work you must have created a table that will accept this data wit the same name as the file you are importing (minus the extension)

Thursday, February 28, 2008

Install Flex 2 Alpha for Linux on Ubuntu

Make sure you have a copy of Eclipse 3.3 Classic (Europa Installed)

Download this from http://www.eclipse.org/downloads/

Create a directory in your home file called eclipse3.3

Extract eclipse into this directory

Make sure you have the latest version of Java Installed (ie. Version 1.6)

and make sure it is set as the default Java sudo update-java-alternatives

Download Flex for Linux http://labs.adobe.com/technologies/flex/flexbuilder_linux/

chmod +x flex* (to allow you to execute the download file)

follow the installation process and select the eclipse installation that you have created above when prompted by the flex installer

Friday, January 18, 2008

CSS and Transparent PNG's

I use the simple solution for Transparent PNG's


<div id="newsletter_subscribe">
<form action="" method="post">
<input type="text" name="email" id="subscribeemail" />
<input type="submit" name="submit" />
<a href="">This is a link</a>
</form>
</div>


Non-IE6

div#newsletter_subscribe
{
position:absolute;
top:150px;
right:15px;
background-image:url(../images/site/subscribe_home.png);
background-repeat:no-repeat;
width:150px;
height:139px;
z-index:80;
}

Conditional Statement for IE6

div#newsletter_subscribe
{
background-image: none; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/site/subscribe_home.png,sizingMethod='scale');
}


This works well, except I was finding that links and text boxes within this particular div had been disabled altogether. It is a known glitch that in IE6 any child link tag within a AlphaImageLoader filtered tag will be rendered useless. So my work around was to do the following.


<div id="newsletter_subscribe"></div>
<div id="newsletter_subscribe_container">
<form action="" method="post">
<input type="text" name="email" id="subscribeemail" />
<input type="submit" name="submit" />
<a href="">This is a link</a>
</form>
</div>


I then altered my CSS as follow

non-IE6

div#newsletter_subscribe
{
position:absolute;
top:150px;
right:15px;
background-image:url(../images/site/subscribe_home.png);
background-repeat:no-repeat;
width:150px;
height:139px;
z-index:80;
}
div#newsletter_subscribe_container
{
position:absolute;
top:150px;
right:15px;
width:150px;
height:139px;
z-index:80;
}

Conditional Statement for IE6

div#newsletter_subscribe
{
background-image: none; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/site/subscribe_home.png,sizingMethod='scale');
}


This then rendered a seperate div with no child elements and just positioned the Links and Input boxes in another div over the top of my transparent PNG.