Wednesday, November 30, 2011

putty + screen = meant to be

I am getting used to the screen command for my Linux development environment and I find it to be a great tool for detaching and reattaching sessions - but that's just scratching the surface from what I see on the net. As there are many useful posts out there explaining why screen is something that you've been missing if you are working via putty, I will let them do the talking.

Introduction

A redhat magazine post

I am a newbie to screen and this is all that I have been doing:
  1. Open multiple putty sessions via Putty connection manager
  2. Foreach tabbed session I do a: $ screen -S session_name
  3. Code
  4. While leaving for the day, disconnect all sessions - I don't "exit"
  5. When I want to come back again - I open the tabs once again and reattach to previous session - I normally name my sessions "tab1", "tab2", etc. so reattaching is equivalent to: $screen -d -r tab1
All this is good enough. I had just one rant while using screen - I did not know how to scroll back. Say I run a find command and the output spews out to more than 80 lines - the size of my terminal window. If I am running in screen mode - by default I can scroll back only upto 100 lines. And then, this post came to my rescue:

Saturday, June 4, 2011

Stray thought

The difference between an average programmer and a good one is the same as the difference between an optometrist and an ophthalmologist.

Friday, June 3, 2011

The easiest way to recover admin password of BSNL ZTE DSL modem

In my previous post, I had described how to recover the admin password of your BSNL ZTE DSL modem, provided you have the modem configuration backed up.

But if you don't have the config file backed up - recovering the admin password is all the more easier. Read on to know more.

Model: BSNL Dataone ATE ZXDSL 531B modem.

This post shows how you can get the admin password of the modem without any backed up configuration. You just need to know the modem IP. Let me know if the link is broken - I will write a new post describing those steps.

If your modem/router's basic security is flawed to this extent, then deploying its in-built security measures is like trusting a visually impaired lame duck, one suffering from suicidal tendencies, arming it with banana skins, and telling yourself: "That ought to keep me safe from fire-breathing dragons and the 15 feet tall goblins who ride them!" (a justified exaggeration the "sitting duck" analogy).

Sunday, May 29, 2011

Recovering admin password of your modem from backed up configuration file

Model: BSNL Dataone ATE ZXDSL 531B modem. (Below points worth a shot for any other modem also)

Assumption: You have saved your modem settings locally on your machine. If not, don't be disheartened (Do slap yourself thrice though), this post will help you out.

If you don't know how to upload/save your modem/router's configuration file, read this.

I had forgotten the admin password and I didn't want to reset my modem. Just wanted to see if I could get any info from the configuration that I backed up.

I opened up the file and searched for the keyword "admin" and I came across this block:
<sysusername value="admin">
<syspassword value="YWRtaW5fcGFzc3dk">
Took a blind shot to see if it is a base64 encoding and <insert your jumping-with-surprise word here> it was base64 encoded!

Securing my DSL modem

I had a BSNL modem installed at my home quite some time ago. The guy who installed it did the minimal configuration - just enough to connect to the internet. He did nothing on the front of basic security - hiding the wireless network, changing the default password, etc.

As with all standard modems, this one had a web interface at http://192.168.1.1 The interface was easy to navigate and through it I hardened a few of the settings. I am going to share them in this post.

The security measures that I describe will be available on any standard DSL/ADSL modem. The UI navigation will vary across different models. But the ideas - like changing your modem's IP from 192.168.1.1 to some non-standard value e.g. 10.2.3.44 will stay the same.

The changes are limited by my own experience and I'd appreciate if you could share any other security measures that you took. If you are happy with the way things are going on - your wireless network is not hidden, your modem's IP is 192.168.1.1, default password is "admin" - stay happy and go back to watching that skating cat video on youtube, while I download the entire LOTR trilogy on your connection :). If you want to get your hands dirty and learn a few things in the process, read on.

The author is not responsible for temporary/permanent loss of internet connectivity or inadvertent establishment of communication with alien life forms resulting from the changes described in this post.

Modem: BSNL Dataone - ZTE - ZXDSL 531B

Before moving on to the changes, I'd recommend that if you are going to do them as you read this post, please read the whole post first. And the changes don't come into effect until you save them or in some other cases restart the modem (changing the modem IP for instance). So if you want to experiment with the changes, do them one at a time - change the config, save it, check it and move on. Doing multiple changes and not knowing what went wrong is not worth the debugging time. You can also keep on saving changes as you move through the post, creating snapshots of the configuration file.

The first thing to do before messing around with any settings is to insure yourself against the destructive streak of the geek in you - the one which prods you with the "Go on, try it out, let's see if it blows anything up" thought. Hence I backed up the minimal configuration that was done by the BSNL guy.

Friday, December 24, 2010

Alpha(bet) Geek


#/usr/bin/perl
use strict;
use warnings;
my $str = $ARGV[0];
my @alpha_arr = ('a' .. 'z');
my %str_tok_hash = map { lc($_) => undef } 
                   grep { /[a-z]/i } 
                   split(//, $str);
my @diff = grep { not exists $str_tok_hash{$_} } @alpha_arr;
$str = "'The string ($str) contains all the letters of the alphabet";
$str .= " except (".join(' ', sort @diff).").' - contains all the letters"; 
$str .= " of the alphabet. :)";
print "$str\n";

Sunday, December 12, 2010

The "Read More" plugin and how blogger beat me to it

For those who are searching for a way to add a "Read More" link to their blogspot blogs - click here

The rest of the post discusses the other "Read More" plugin that I found on the net, its limitations and how I wrote one myself (similar in its functionality to one in the above link) and its source code. Its a good study on how to preprocess your post after you click "PUBLISH POST" button but before blogger actually publishes it. The geeks may continue reading.

Quite some time ago, I was writing a humor article on my blog - Barberic Creatures It badly needed a "Read More" link because as per the the setting I had, I display 10 posts on a page and if one of them is too long (this one was) it dissuades the reader from scrolling all the way down to see the other ones. I couldn't find any plugins at that time (2008/11) and left it at that.

But it came back to haunt me when I wrote Schwartzian Transform Explained. This time I got a hit - Snaphow read more plugin

The instructions were clear and it works. But it didn't address my needs because:

Schwartzian transform used in a C Program

If you are looking for an in depth explanation of the Schwartzian transform with an example, please refer to my earlier post - Schwartzian Transform Explained

I was getting bored and asked a friend to give me something interesting to code in C. He being who he is, told me to write an implementation of the Schwartzian Transform (henceforth referred to as ST) in C. During the process of writing that program, I realized how Perl makes us focus on the problem at hand rather than the nuances of the language. This post aims provide the source and explain it.

The source is uploaded here - schwartz.c

Now that the (fo|sou)rce is with you, I shall explain the main() function because all the other functions are called from main() and their body is easy to understand once you know their purpose in the main(). Or rather, their main() purpose. :)

Sunday, November 28, 2010

Schwartzian transform explained

Did you google for "explain schwartzian transform"?

If yes, then you've come to the right place. If no, then you've come to the right place (I wouldn't want to loose out on a prospective reader now, would I?). Please read on - you will find this worth your time.

This post aims to dissect the Schwartzian Transform, and explains it through an example. And while doing this, it shows how cool Perl is.

But what is the Schwartzian Transform? - A way to efficiently sort a list of items.

Why the name? - Legend has it that Randal "Merlyn" Schwartz (wiki page) demonstrated a Perlish version of a Lisp idiom to speed up sorting. And since that day, every time you use the word "Schwartzian Transform", somewhere far beyond the distant seas, the Randal smiles.

How does it speed up sorting? - Patience my child. The blooming of a flower is an analog process, revealing each petal gracefully unlike the open-throw-catch-roll-close process of a frog's tongue. (Yummy?)

Why do I need to know it? - Because it's fun.

Will each line be preceded by a question in the bold font? - Not from now on.

Suppose you have an array of salesman objects - @salesmen, each of which consists of the following attributes:

1. name           # salesman name
2. base_salary    # base salary
3. n_cust_conned  # number of customers conned
4. comm_per_sale  # commission per sale

And the sub routine which calculates the total salary of the salesman is:

sub get_total_sal {
    my ($obj) = @_;
    my $total_salary = $obj->{base_salary} + 
                       $obj->{n_cust_conned} * $obj->{comm_per_sale};
    return $total_salary;
}

If you were told to sort this array based on the total salary, what would be your code snippet which does the sort?

Without prior knowledge of the transform, maybe something like this:

my @sorted_salesmen = sort { $a->get_total_sal() 
                             <=>
                             $b->get_total_sal() } @salesmen;

This would do the job. But what limitation does it induce in your code?

Think about it.

Perl program to simulate tail -f

Created a github account to share my bin with the rest of the world.

Had written a perl program to simulate tail -f quite some time ago. Put it up there. Enjoyed writing it. Hope you feel the same while playing with it.

Here it is: simtail.pl