How to use individual lines pulled from stdin in the middle of a command when using xargs

xargs is very powerful commandline utility. Here is what Wikipedia says about xargs xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input Most common use of xargs would be to do something like, find . -type f -print0 | xargs -0 rm Let us assume that you have a file with list of files to be downloaded from a website. Read On →

How to upload files when testing using Selenium Webdriver

You can use the following code to set a file path to the file upload control. WebElement file = driver.findElement("control_id")); file.sendKeys("/full/path/to/file"); You need to pass full path to the sendKeys() for it to work. Otherwise sendKeys() fails silently.

Is Thread.Sleep() evil?

If you search for this topic, you will find lots of information and many of them claiming Thread.Sleep() is evil. However, I think this evilness is mostly dependent on which context Thread.Sleep() is used. You might have seen code like the below one. while (!exit) { DoWork(); Thread.Sleep(10000); } This code example does some work and sleeps for 1 minute before does the job again. This simple example has some potential issues. Read On →

Working with native code easily in C# with the help of C++/CLI

.NET comes with pretty good interoperability options which would enable unmanaged code to be used from a managed environment. In C#, to call a function which is available in a DLL, PInvoke (Platform invocation service) can be used. Here is what MSDN says. Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL. This is very helpful when you need to call some system functions from your C# application. Read On →

Simple, generic and dynamically allocated array in C

C is a very good language. I have been using for quite some time for my opensource project. The flexibility C offers is really good. But sometimes, lack of simple datastructures like a dynamically growing array will slow down the programmer. There are tons of implementation available online, but most of them are overcomplicated, got lot of dependencies or tough to understand and incorporate with your application. In this post, I present a simple array which grows dynamically, reuses the memory, supports any pointer type and easy to copy to your code base. Read On →

Simple egg timer on Linux for Pomodoro technique

Recently I have started evaluating the Pomodoro Technique which I found quite interesting. I am still evaluating the technique and not yet concluded on whether I should continue using it. To implement pomodoro technique, you need a kitchen timer or egg timer. Since I use pomodoro for my programming work, I obviously don’t want to use a physical timer. I couldn’t find a decent timer for linux especially one that works well with Xfce. Read On →

Circular linked list – An implementation using C#

In this post, I will explain about creating a circular doubly linked list using C#. .NET framework provides a doubly linked list implementation in System.Collections.Generic.LinkedList class . But this class is not providing the behavior of a circular linked list and it is very tough to extend for supporting circular linked list requirements. In a normal doubly linked list, each node will have a link to its previous and next nodes. Read On →

What Great .NET Developers Ought To Know (More .NET Interview Questions and Answers) – Part1

In this series of posts, I will try to answer the questions posted by Scott Hanselman here. This part we will be seeing the first set of questions he has given under Everyone who writes code heading. Q) Describe the difference between a Thread and a Process? A Thread is a small unit of code in execution. A process is an instance of program which will have multiple threads running. A process can host multiple threads. Read On →

ADO.NET best practices – Reading data from data reader

I have seen many people using DataReader incorrectly. In this post, I will try to explain some good practices that can be followed when reading from a data reader. Consider the following problematic code, SqlDataReader reader = /* ... */; while (reader.Read()) { string userName = reader["user_name"].ToString(); int age = int.Parse( reader["age"].ToString() ); /* ... */ } reader.Close(); How many problems can you figure out from the above code? There are many problems with this code, The columns “user_name” and “age” may or may not exist. Read On →