CGI or Common Gateway Interface was created to server content over HTTP web servers using external scripting languages like Perl, Python, Ruby, or compiled binaries of C,C++, etc. Apache, the most popular web server and also others can be easily configured to run CGI scripts. In this article we'll be looking at configuring Apache to run CGI scripts and writing simple CGI scripts in Ruby. Configuring Apache In the demo example I'll be using a directory rb-bin you may change this to whatever you like, cgi-bin is very popular and generally pre-configured. Do not forget to make all your scripts in the directory executable. Add the following to Apache's config file, and then restart Apache. ... Read More →
Views: 474

Using *nix lsof Command To Your Advantage

By pradeep on Jun 08, 2013 - 12:55 AM
lsof or LiS Open Files is a very powerful command available on most of Unix-like systems, it lists all open files (in *nix everything is a file, drives, sockets, inodes, etc.). The listing can filtered using various parameters like process id, owner of the process, etc. In this article we'll discuss using example to use lsof command in various ways which you might useful according to your needs. Usage The most basic usage of lsof command is to list all open files. ... Read More →
Views: 695
Let us suppose we have a table T_APHA_NUMERIC which consists alphanumeric column as shown below ... Read More →
Views: 1,869

Understanding & Using The tee Command

By pradeep on May 14, 2013 - 1:53 PM
tee command is common on Unix like systems and on Windows PowerShell. The tee command writes the input to the file specified and also to the standard output, it was named after the plumbing T-splitter used. Here's a graphical presentation of the tee command: Source: Wikipedia.org Usage The usage can be better demonstrated than explained in theory, follow the few examples below: ... Read More →
Views: 1,519

Read & Update MP3 ID3 Tags in Ruby

By pradeep on May 03, 2013 - 7:35 PM
ID3 is a format to store metadata within MP3 files which might include album info, artist info, cover images, thumbnails, and so on. These tags help software like Windows Media Player, iTunes, etc. categorize music and build a library for you to browse. Also, there exists software like Easy ID3 Tag Editor, etc. which allow you to create and edit ID3 tags' all fields. So, what's the use? There are many, you might want to create your own web-based ID3 editor/library, or you might want to create an index of MP3 files you have and so on. In this article we'll be looking at a Ruby module called taglib-ruby which is a Ruby interface for the C++ library called taglib. We'll use the Ruby module to read & write to MP3 files' tags. TagLib also supports many other file formats like OGG, FLAC, etc, but here we will only be looking at MP3. Installing TagLib for Ruby You'll need to install taglib library (http://taglib.github.io/), if your system's package manager can install... Read More →
Views: 1,830

Access Amazon SQS using Python's Boto

By pradeep on Apr 30, 2013 - 3:04 PM
Amazon's Simple Queue Service is a highly scalable service to help cloud-based applications use a queuing system which is reliable & scalable. Amazon's queue has it's pros & cons, like the messages may not be received in the order they were queued, and you may receive duplicates, I had written an article on Amazon SQS where I had explained the features & limitations of the service. In this article we'll be looking at a Python library called Boto which makes accessing AWS services really easy. We'll go through installation of Boto and using it to perform various operations on Amazon SQS. Installing Boto Boto's git repository makes it very easy to install, just follow the commands below: ... Read More →
Views: 1,912
PDO or PHP Data Objects is a data abstraction layer, i.e. it provides uniform methods to access different types of databases, as a result switching between or moving to a different database system is relatively easier. So, in simple language the code to access a SQLite db will also work for MySQL db with minor changes. PDO provides a plethora of database drivers like MySQL, Oracle, Postgre SQL, SQLite, Firebird, etc. In this article we will look at accessing a SQLite db using PDO. Installing PDO PDO & driver for SQLite is enabled by default from PHP version 5.1.0 onwards, if not so use the following command to install PDO: ... Read More →
Views: 2,487

Introduction to HMAC & Using in Python

By pradeep on Apr 23, 2013 - 5:46 PM
HMAC stands for Hash-base Message Authentication Code, it is key based message digest algorithm which can be used for verifying the integrity of the message (i.e. the original message from which the hash is generated) or to verify the authenticity of the sender of the message or both. Nowadays, HMAC is being widely used in various systems & domains, like server-to-server communications, Web Service APIs, etc. A well known use of HMAC is in Amazon's AWS API calls where the signature is generated using HMAC. HMAC can use a variety of hashing algorithms, like MD5, SHA1, SHA256, etc. HMAC function is not very processing intensive, so it has been widely accepted, and it is relatively easy to implement in mobile & embedded devices too while maintaining decent security. Using HMAC in Python Since Python version 2.2 the HMAC module comes with Python installation, and the hashing library hashlib comes with the Python installation from version 2.5 onwards, in case you are having... Read More →
Views: 2,098
As programmers most of us today are writing programs/scripts that consume data from web services or APIs, like the Facebook Graph API, etc. Writing your own subroutines from open socket and making request and the likes are time consuming and are not worth putting effort on for all projects, so Ruby has a gem called HTTParty which will help you concentrate on the business logic instead of mundane HTTP request tasks. HTTParty is a very neat gem, it combined with the power of Ruby creates a lucid and free flowing code. HTTParty can automatically parse JSON/XML type responses on the basis of the Content-Type header. In this article we'll look at the installation of the HTTParty gem and basic usage to get you started. Installing The HTTParty Gem Installation is pretty simple, issue the following command as a root user: ... Read More →
Views: 3,228

Access Remote URLs in Python With urllib2

By pradeep on Apr 17, 2013 - 4:44 PM
Python urllib2 library contains functions with enables programmers to access remote URLs by helping out in the operations like HTTP Basic Authentication, cookies, redirects etc. It's Python's equivalent to Perl's LWP or ASP's XMLHttpRequest etc. The library allows you to add HTTP headers to requests, read response data & headers, error handling etc. Although urllib2 is not limited to HTTP we'll only be covering HTTP in this article. I'll try to explain and demonstrate the usage of urllib2 with a few examples so I am assuming that the reader has basic understanding of URLs or simply put how the web works. Using urllib To Fetch Remote URLs The code snippet below straightaway fetches an URL and prints out the received data nothing fancy about it, the simplest example: ... Read More →
Views: 2,533