Generate Date from a range in Mysql and pad the results where no date is present

If you want to generate dates, MYSQL doesn’t have a range function, so I wrote a work around for the same. So how  it works is I have reused a code to generate numbers from my previous post. So I added date function to that query and reduce the generated numbers from the date. Hence effectively its Currrent Date – x number of days. Thus we generate the dates from the date we provide to the x number we generate. So here is the code:

Continue reading “Generate Date from a range in Mysql and pad the results where no date is present” »


, , , , , , , ,

No Comments

Generate 1 to 1000 in mysql

Sometimes its necessary to have thousand rows to join or generate new values, we need to get the thousand rows first. For this I used union of numbers 0-9.  I have joined four of these to get to four digit values. So here is the code:

Continue reading “Generate 1 to 1000 in mysql” »


, , , , , , , ,

1 Comment

Web page Performance for a Blog – Part 1

I have always under the notion that page performance for big websites or websites that have a sole server and various resources like CDN and load balancers. So I wanted to know if this is true. I set out to try web page performance my blog. I just wanted to see how much I can reduce the roundtrip time of this blog. I will be doing the analysis and optimization in parts. So here goes whatever I have done till now.

Continue reading “Web page Performance for a Blog – Part 1” »


, , , , , , , , , , , , , , ,

No Comments

Sort according to the nth Column in Shell Script

You have a file that has multiple columns separated by a specific delimiter and you need to sort it according to a specific column which need not be the 1st column. If its not the 1st column then ordinary sort wont work. So we need to use the parameters of sort to specify the exact column so that it will sort according to that column only. There are parameters in sort like -t and -k, we use this for the sorting. So -t is to specify the delimiter and -k to specify the column needed. For example : We need to get the 3rd column of a csv file(csv file has , as delimiter) the option should be -t, -k3. We can use two more options for the same. -n for sorting the values as numbers instead of considering as text and -r for sorting in descending order ie biggest value on the top. So the final command is :

Continue reading “Sort according to the nth Column in Shell Script” »


, , , , ,

No Comments

Check the port in which the Mysql is running on

Mysql can be configured to run other ports other than the default port (of 3306). So what will you do when you need to find the port on which a mysql server runs on. If you don’t have access to the server files and can access the server only using the mysql client, the only way to know this is by checking the Global Variable set. We can see all variables by issuing the command:

Continue reading “Check the port in which the Mysql is running on” »


, , , , , , , ,

2 Comments

Group by Date when Stored in Mysql DataBase as Date Time

I have a table called date_count with 2 columns one is a value and another is a date time, say called date_time in mysql. Date Time in mysql is stored as dd-mm-yy hh:mm:ss. The issue comes when I need to get the number of rows per day. As its stored as date time format in mysql , you need to specify both date and time when you specify a group by. So grouping by day is not possible in that case. So we need to use the in-build mysql function DATE(). The function accepts date time as parameter and returns only date back. So we just need to use the DATE() function where we need to group by date and all the date time values are converted to date and can be grouped by date. So here is the implementation of it.

Continue reading “Group by Date when Stored in Mysql DataBase as Date Time” »


, , , , , , ,

1 Comment

Pass cookie from script to firefox

I had a requirement to get firefox to open a logged in page in firefox. I used it for automated opening of some logged in pages. But there is another use for it. It can be used for opening mail or any other site that needs to be logged in. The only issue, this method works on sites that relies on cookies only. This is fine as almost all websites run using cookies. So what the script does is, it has the username and passwords. It logs into your account and gets the cookie and passes the cookie to your browser. So when we open the page again in browser it already has valid cookie and there is no need to login. You will go thought to the logged in page and thats it. You just need to run the script and you can make the script to take any number of sites. Currently I have configured only to automate for Yahoo! . It can be easily extended to add any more sites.

Continue reading “Pass cookie from script to firefox” »


, , , , , , , , ,

2 Comments

Print Array in PHP

There are various methods and commands used in PHP to print an array of elements. They are different in the way they print the array elements.
I will cover three main ones I usually use.
Lets assume an array as follows to explain the various types of printing.

Continue reading “Print Array in PHP” »


, , , , ,

2 Comments