JavaScript Compression With YUI Compressor
Cleaning up files - Clean up shell script
Few days back I wrote a post about, how to use shell script to backup mysql database. Using this shell script you will have lot of data files which will be created every day. You can not just keep all these files as backup because generally you need DB backup of previous day or few days. You need to run another script to clean all those files which are not useful for you and for which you have latest backup files.
Following is the cleanup script you can use for removing all unnecessary files in your backup directory:
#!/bin/bash # Clean up script for db backup files DB_BACKUP_DIR="/opt/backup/mysql" FIND="$(which find)" $FIND $DB_BACKUP_DIR -type f -mtime +3 | xargs rm -f
Modify the -mtime parameter value accordingly. Above script will remove all files having modification time older than 3 days from DB backup directory.
Google Web Toolkit (GWT) - An overview
Setting up Slow Query log - MySql
Slow query log is a very useful tool using which you can identify slow running queries in your application and then tune them accordingly. This post in scope of MySql database server, which is an open source and free database server for community.
A growing application generally get corrupted by slow running queries over the time of development. This is generally not because of poor query writing skills but the changes done in DB over time or changes in use of table over the long time. Slow query log gives you opportunities to check all these instances where you can prevent the introduction of a slow query in your application. It is advisable that development or testing instance of MySql Server should run with slow query log configuration so that these queries can be caught in time and tuned accordingly.
How to setup slow query log for a mysql instance?
It is quite easy configuration which needs to be done to my.ini or my.cnf file. On windows systems my.ini generally resides in Program Files/MySql/Mysql server x.x folder which can be edited using ant text editor.
Add following lines in [mysqld] section:
[mysqld] ...... ...... # Time in seconds , All queries running more than # specified time will be logged in file long_query_time=1 # Where to create log of slow queries log-slow-queries=c:\\slow-query.log ..... .....
You need to create this file manually in C drive and then restart the mysql service (Start -> Run -> type ’service.msc’ - > Select Mysql service - > Restart )
On linux machine my.cnf file generally resides at /etc/my.cnf or /etc/mysql/my.cnf and can be edited in similar way.
Note: Mysql service generally runs under some user account and if that user account is not the owner of file created for logging slow queries, logging will not be done. This can be problem on linux machines where user management is better and strong. Even on windows machine you need to check that you should have administrative rights if mysql service is running using administrator account.
use following command to change owner ship of a file on linux system (assuming mysql is the user under which mysql service is running)
#sudo chown mysql /var/log/mysql/slow-query.log
SAX Parser - Reading CDATA
CDATA is the section in XML Document which should not be parsed by XML parser implementation. This section can be used to pass the data which generally does not comply with XML syntax like a javascript function. If you need to transfer a javascript function in your XML document or a JSON formatted data which may have some characters, which are not allowed in XML syntax, you can use this section.
This section is generally retrieved as a Node but XML parsers ignore its content so after getting the node you can extract the content of this node. Parsing is generally easier in DOM approach and you can use its API to get the CDATA node loaded into the memory. DOM approach is little bit expensive in case you are trying to parse a big XML document.
While doing the SAX parsing you generally get events when parser encounters a node and your can get callback on an handler, Use following code to retrieve CDATA for SAX parsing. Below I tried to get a JSON string from CDATA section:
import java.io.File; import java.io.IOException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import net.sf.json.JSONObject; import org.xml.sax.SAXException; import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.helpers.DefaultHandler; public class CDATAReader { private SAXParser parser; private DefaultHandler handler; public void parseXmlFile(File file) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); parser = factory.newSAXParser(); handler = new CDATAParser(); parser.parse(file, handler); } catch (SAXException e) { // A parsing error occurred; the xml input is not valid } catch (IOException e) { // Unable to read file } } private class CDATAParser extends DefaultHandler2 { public synchronized void characters(char[] cbuf, int start, int len) { JSONObject ob = JSONObject.fromString(new String(cbuf, start, len)); System.out.println(ob.toString();); } } public static void main(String[] args) { try { File file = new File(args[0]); CDATAReader reader = new CDATAReader(); reader.parseXmlFile(file); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }
Introduction to Silverlight
Mysql Bug — DatabaseMetadata.getColumns() doesn’t return the correct column names
We faced an issue recently while doing our work for making the website and our solution enabled for multiple languages. In certain feature, fields specified by users were required where user can specify any number of custom fields attached with their profile and save them in database along with the profile. As we needed to provide multilingual support for this feature, names and values can belong to any language.
We have a system in-place to save these values in DB by creating column for each name and then putting values in those columns. We did this because these custom values are generally shared by many entities and we can re-use the column in that case.
We faced issue while fetching back these fields to display to the user and we were unable to retrieve the value of non latin columns from result set. It was showing some jumbled up characters in error log that code is unable to retrieve the column value of non-latin columns.
Did some research and found that the issue is with mysql java connecter. Here is the bug posted http://bugs.mysql.com/bug.php?id=20491
Update your connector to latest version(http://dev.mysql.com/downloads/connector/j/5.1.html) for this issue fixed and your can work with non-latin columns with this.
DOM and SAX - XML Parsing
Free FTP Clients — File Transfer
FTP stands for File Transfer Protocol which become synonymous to the action of transferring your file using FTP. People generally refer like ‘FTP this tar file to xyz public server’. As internet grown so rapid in past few years, web pages become the most popular application for the users. This promoted use of HTTP for file transfer also, but still FTP is generally used when you want to transfer files reliably.
The best way to use FTP is using command line client which works really well on all platforms.For UI people, here I am listing some of the free FTP clients which can be used for getting files from FTP server or putting files to FTP Server, Most of them are similar in functionality but some have better features like using multiple connection in background or uploading multiple files together :
1. WinSCP http://winscp.net/eng/index.php
2. Fire FTP http://fireftp.mozdev.org/
3. File Zilla http://filezilla-project.org/
4. Smart FTP : http://www.smartftp.com/
5. Core FTP : http://www.coreftp.com/
6. Go FTP : http://www.goftp.com/
Most of the above are installations which will provide you another program to connect to FTP server and then do file transactions. Fire FTP is quite handy and it not a separate program but an addon to Mozilla Firefox. Most of them are open source also.
