Standard String Library functions in string.h in C

strlen Finds the length of the string.
strlwr Converts string to lower case.
strupr Converts string to upper case.
strcat Appends one string at end of another.
strncat Appends first n characters of a string at end of another.
strcpy Copies a string to another.
strncpy Copies first n characters of a string into another.
strcmp Compares two strings
strncmp Compares first n characters of two strings.
strcmpi Compares two strings without regards to case.
stricmp Compares two strings without regards to case.
strnicmp Compares first n characters of a string without regards to case.
strdup Duplicates a string.
strchr Finds first occurrence of a given character in a string.
strrchr Finds last occurrence of a given character in a string.
strstr Finds first occurrence of a given string in a string.
strset Sets all characters of a string to given character.


strnset Sets first n characters of a string to given character.
strrev Reverses the string.

Adding Functions to Library in C

This might be known to many but  I recently tried it and got it working.

Suppose you make a function in C(for example here we take a simple function which calculates the square of a number).

Its a fairly simple one and I want to add in in a library thus making its reuse possible.

(Please note I am taking a very simple scenario because the actual program is not the point of focus here, but the procedure is)

The function:

int square(int n)


return n*n;


Compile the file:

Compile the file in which you have written this function. Lets call it “sqr.c”. A new file called “sqr.obj” is created contained compiled code.

Add the function to Library:

Add the function to the library “maths.lib” using the following command.

C:\>tlib maths.lib + c:\sqr.obj

Please note the paths. Your paths may be different than mine!

here, maths.lib is the library and + is a switch which indicates that we want to add a new function to the library and the object file is at the given path.

Header file:

Add the prototype of square() function in a header file (lets say “square.h”) This file should be included in the program where we want to use the function. we can use it as:

#include “c:\square.h”

Thats all !

Use the function and enjoy !!

Hope it helps.

Paperclip Resizing options…

Paperclip allows us to specify image dimensions in the  model iteself. This makes life very simple in cases where we only want image resizing.

Here is a list of things we can do to get the best out of it….

Please note : it applies to image magick also.

The basic specification is <width>x<height> in pixels, optionally followed by a modifier. In some cases you can omit either width or height.

    • 256×256
      This specifies the Maximum dimensions for the image, while preserving the aspect ratio of the image. So if your image were actually 512×256 it would be resized to 256×128 in order to fit inside the specified size.
    • 256×256!
      This specifies the Exact image size, so a 512×256 image would be changed into 256×256, losing the aspect ratio.
    • 256x
      This specifies the desired width of the target image, leaving the height to be set so as to preserve the aspect ratio.


    • x256
      This specifies the desired height of the target image, while preserving the aspect ratio.
    • 256×256^
      This specifies the Minimum size for the target image, so the resized image may be larger than these dimensions.
    • 256×256>
      This specifies that the image will be resized only if it is Larger than the dimensions.
    • 256×256<
      This specifies that the image will be resized only if it is Smaller than the dimensions.

Deploying with Pasenger and apache

Recently had come accross the task of deploying a rails application with apache and passenger.

I did everything as prescribed in the way I used to but for some reasons I was shown the directory listing of the application instead of application being executed.

The change I had taken from my conventional way of giving the paths to using symbolic links.

Finally i figured out the solution as an issue with passenger and the way it treats symlinks:


here is what you need to put between the <directory> tags to get stuff working:


PassengerResolveSymlinksInDocumentRoot on



Hope it helps !

Why not to use Strings in Cucumber

Cucumber allows you to define step definitions using strings instead of regular expressions.

This might seem simpler at first, but it has other problems, which I’ll illustrate with an example.

Here is a step definition that uses a plain string.

Given “I have 100 in my Account” do


We couldn’t write $100 here, because the $ has a special meaning when you define step definitions with strings.

Any $ signs—including any letter or number following it—will be interpreted as an argument, .

This step definition uses an argument:

Given “I have $amount in my Account” do |amount|



This step definition would match both of the following Gherkin steps:

Given I have 100 in my Account

Given I have $100 in my Account


In the first case, the Step Definition’s amount argument would have the value “100”. In the second case it would have the value “$100”. If our Step Definition expects a string with only digits, this can be problematic. We have no way to enforce a consistent way to write Gherkin steps, and the step definitions have to anticipate many kinds of input.


This is why using strings instead of regular expressions is not as advantageous as you might think. They give far less control over what gets matched and what arguments a step definition can receive.

Resizing the image without chaning its dimensions using paperclip


In a recent application, the need of the hour was to reduce the file size of an image without changing its dimensions.

Now, this can be acheived by reducing the quality of the image.

ImageMagick library has a “convvert” command which does exactly the same..

for eg(on the terrminal) : convert image1.jpg -quality 10 image2.jpg

image1.jpg—>original image

image2.jpg—->final image


According to the paperclip wiki there is a :quality parameter which is allowed.

I tried that but for some reasons , I was not able to get it running.

I also tried using :convert_options but it did not work too.


Thus , I wrote my own processor and got the stuff working. Here is the model and processor code :

#######Model code###########

class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {
: original => {
:geometry => “256×256<“,
:processors => [:qresize]
belongs_to :pcontent


###################Processor code########################

make a file called qresize.rb in #{Rails.root}/lib/papaerclip_processors

The path is mentioned because this path is loaded automatically….

module Paperclip
# handles compression of image by reducing its quality
class Qresize < Processor
def initialize file, options = {}, attachment = nil
@format = File.extname(@file.path)
@basename = File.basename(@file.path, @format)
def make
src = @file
dst =[@basename, @format])
parameters = []
parameters << “:source”
parameters << “-quality 10”
parameters << “:dest”
parameters = parameters.flatten.compact.join(” “).strip.squeeze(” “)
success =“convert”, parameters, :source => “#{File.expand_path(src.path)}[0]”, :dest => File.expand_path(dst.path))
rescue PaperclipCommandLineError => e
raise PaperclipError, “There was an error during the Size Reduction  for #{@basename}” if @whiny


This is a general code for image resizing and probably at this stage, we may not require to write a processor.

But the advantage of doing this is that we can extend this to do a lot more as and when requirement comes.

Also, we can handle our video and audio processing by this easily.

The other option is to pass a block(lambda or Proc) to :styles hash but I personally feel this is a much cleaner approach.


Hope it helps.

Installing sun (oracle) jdk in precise pangolin..

Finally, after doing many things unsuccessfully,

this method works for me:

sudo rm /var/lib/dpkg/info/oracle-java7-installer* 
sudo apt-get purge oracle-java7-installer* 
sudo rm /etc/apt/sources.list.d/*java* 
 sudo apt-get update 
sudo add-apt-repository ppa:webupd8team/java 
 sudo apt-get update 
sudo apt-get install oracle-java7-installer

Getting graphics.h to work on mingw32 gnu C++ compiler

Some schools and colleges still use the old Turbo C++ IDE (with compiler) for C/C++ programming. It does not seem surprising. But problems arise if the student has a modern PC running 64-bit(x64) windows operating system. The OS simply refuses to run old 16-bit dos programs (one of them being Turbo C++ IDE whose product line was put on hold after 1994).

Since the Turbo C++ IDE cannot be run on 64-bit(x64) windows OS, the user may choose to use a modern IDE like Microsoft Visual C++, Netbeans (Yes, even for C/C++), Bloodshed Dev C++ (outdated), Eclipse or Codeblocks. However, the problem is still not solved. The header graphics.h and its library are not available with other compilers (not even Borland 5.5). For the purpose of compatibility, a free utility called WinBGIm is available. Follow these steps to get graphics.h working with mingw32 gnu C++ compiler (which is very popular).

  1. Get an IDE. Some of them are mentioned above. (I use Codeblocks, Netbeans as examples here).
  2. Get mingw32 GNU C++ compiler from here. OR it is optionally available with Codeblocks IDE here (be sure to check whether the file has mingw in it).
  3. Install the compiler and the IDE (in this order). Configure your IDE to work with the mingw GNU C++ compiler. Codeblocks if downloaded with mingw automatically sets it as default so that Codeblocks users just have to download and install the setup file. If you use Netbeans (with C/C++ plugin), go to Tools menu > Options > C/C++. Click on Add and paste the address of the bin folder of your compiler (in my case it was C:\MinGW\bin). Additionally you need to install MSYS for netbeans from here. Version 1.0.11 is enough. Configuration is explained in the netbeans community release.
  4. Download WinBGIm and extract the files.
  5. Copy the header files (with extension .h) in WinBGIm to the include directory of your compiler. In my case it was C:\MinGW\include.
  6. Copy the library files in WinBGIm (with extensions like .a, .o) to the lib directory of your compiler. In my case it was C:\MinGW\lib.
  7. If your IDE can add link libraries (like Codeblocks, Netbeans), add these files which are found in the lib directory mentioned in step 6 to your linker libraries (in same order) :
    libbgi, libgdi32, libcomdlg32, libuuid, liboleaut32, libole32. If they are not found, try l instead of lib (it is the letter ‘l’ not one). For Codeblocks, use Project menu > Build Options > Linker Settings tab > Add to add each library one by one. For Netbeans (right click on Project) > Properties > Linker > Libraries entry > …(button) and add the above libraries. If your IDE does not support that, you can add these to your linker command (try the l letter instead of lib if it does not work) -libbgi -libgdi32 -libcomdlg32 -libuuid -liboleaut32 -libole32. An example of a command : g++ bgidemo0.cpp -libbgi -libgdi32 -libcomdlg32 -libuuid -liboleaut32 -libole32 -o bgidemo0.exe
  8. Write and execute the program as you normally would, including graphics.h header file in your program.

netbeans and rails 3.0.x

I just found out that netbeans 6.8 has a bug.

It does not support rails 3.x

The bug is probably fixed in 6.9.1

The error is while creating the project, one gets error as rake file not found…

This error is due to the fact that the command to create a new app in rails 3.x is ‘rails new app_name’

but in older version it was rails app_name’

The bug is due to this difference.

However this is solved in netbeans 6.9.1