CodeChef Problem: Feedback

Lots of geeky customers visit our chef’s restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters ‘0’ and ‘1’. Now since chef is not that great in deciphering binary strings, he has decided the following criteria to classify […]

How to Find the Real URL Behind a Redirect in Java

Say you have a URL that redirects to another (e.g., bit.ly). How do you find the real URL behind the redirect? You can do this in Java using the HttpURLConnection class. Like this: String url = "http://bit.ly/23414"; HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setInstanceFollowRedirects(false); con.connect(); String realURL = con.getHeaderField(3).toString(); You basically create a connection, disable […]

How to Search and Find Files on Linux

As a Linux user you’ll inevitable need to search around for a specific file once in a while, be it a configuration file you need to edit or a version of a document you somehow lost. There are three basic ways to search for files using the command line: 1. locate The locate command is […]

vi/vim Basic Commands

As far as I know there are 10 types of programmers around: emacs programmers and vi programmers. Jokes aside I think both text editors are fine, but I prefer vi/vim. The problem is that getting started with it is not trivial, as once you open it you’ll be presented with a blank screen and a […]

Linux Text Processing Commands and Programs

Below you’ll find some useful Linux tools and commands you can use to manipulate and process text. 1. less In my opinion the best tool for visualizing text files. It allows you to easily scroll back and forward (using both lines and pages), and it also comes with search and other functions. Use: less file.txt […]

Basic Regex Patterns in Java/Perl

Below you’ll find the basic Regex patterns you can use to match, edit and replace strings. I am using the Java/Perl Regex flavor, so the patterns might be slightly different if you are using another programming language or platform. Java Implementation Here’s a simple Java sample that uses the Regex library. It will try to […]

Solution to Problem 29 on Project Euler

The problem: Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024 52=25, 53=125, 54=625, 55=3125 If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 […]