Here’s a code snippet which will let you rotate multiple banner advertisements for all the ad spaces you have on your HTML pages. I wrote this because I didn’t want to use an ad server and wanted a light weight yet elegant solution. What the below code does is, it creates a SSI variable ‘slot’ which can have possible values of 1-12. Each value corresponds to a 5 second slot. Source this file at the start of your HTML file and then use the slot variable anywhere in your HTML code to rotate data according to time based slots.Continue reading
Author: Pratik Sinha
WordPress Plugin: Display File Contents Widget for your Sidebar
Recently I wrote a python script to fetch the latest tweet in the background. This would create an HTML file with the latest tweet every five minutes. Now I needed a way to display it as a sidebar widget. I couldn’t find a WordPress plugin which will display the contents of a file given a path, and hence the Display File Contents Widget plugin.Continue reading
Error While Parsing Json using Python – TypeError: list indices must be integers, not str
Jotting this down for fellow googlers. I recently started learning a bit of python and wrote a small script to fetch the latest tweet. When you are new to a programming language, it takes time to grasp some errors. If you see this error while parsing json using python and simplejson, the problem possibly is that, the json is actually encosed in a list [ ]
. If you look carefully, you’ll see your json data (pyton dictionary datatype) is actually enclosed in a python list datatype. The following code will reproduce the error.Continue reading
Retreive your Latest Twitter Update (Tweet) using Python
I used to display my latest tweet using PHP code as part of my WordPress theme’s function.php
. However that did not work reliably and used to slow down page loading a wee bit. Hence I decided to generate the html code for the latest tweet as a background/cron process and just read the generated data in WordPress. Here’s how I do it.Continue reading
Find the Length of a String Variable in Bash
I forget this one all the time! so making a record
$ STRING="test" $ echo "${#STRING}" 4 $
Detect Mobile Browser using Server Side Includes (SSI)
There’s a website dedicated for open source code in various programming languages to detect mobile browsers. However they didn’t have any code to detect a mobile browser using SSI. Thats what I needed to make the HTML pages on my website mobile friendly. Using the <!--#if expr
SSI conditional expression, I wrote up a small code snippet to detect the most common smart phones and set a variable when a mobile phone is detected. I use this variable in other parts of HTML to control what is show and what is not to make it suitable for a mobile browser.Continue reading
Restartless Addons for Firefox
Hurray! Firefox finally has restartless addons. I just noticed them when I tried to install the new Mozilla Recall Monkey extension. I have always been envy of Chrome uses for this one single reason. Not anymore.
Here’s the the complete list of resartless addons.
Check whether a port is open or not on a windows machine
netstat -na | find “LISTENING” | find “TCP” | findstr “:80\>”
Checking whether port 80 is open or not
Indirectly reference bash variable
If you know the name of a variable which contains a value of interest, you need indirect referencing to retrieve the value, this is how you do it.
#!/bin/bash j=1 #variable containg a value i=j #variable containing the name of the variable which holds the value eval k=\$$i #k now contains the value of j which is 1 echo $k j=2 k=${!i} #another way of indirectly referencing echo $k
Bash based Busy Handler for Sqlite
Sqlite is a serverless database and hence doesn’t allow multiple synchronous write requests. Sqlite API for most programming languages have a busy handler functionality which lets you define a busy handler function or a timeout value, thus enabling your program to wait for a certain amount of time and then access the database again.
Continue reading