IdeaMonk

thoughts, ideas, code and other things...

Sunday, August 30, 2009

Web2Hunter.py - find that awesome web2.0 name for your startup

Python inspires a lot of code-reuse, every script you write today can be imported into something else tomorrow if written well. That's exactly what happened right now! the domainhunter script I wrote yesterday, I could actually re-use it right now and make a web2.0 domain hunter :) in just 5 minutes! Seriously it took nothing more than 5 minutes. Here it is -
#!/usr/bin/env python

# Web2Hunter -- Abhishek Mishra <ideamonk at gmail.com>
#
# a web 2.0 name generator extension to domainhunter.py
#
# usage -
# $ python web2hunter.py

import domainhunter as DH
import random

A = ["Anti", "Aero", "Babble", "Buzz", "Blog", "Blue", "Brain", "Bright", "Browse", "Bubble", "Chat", "Chatter", "Dab", "Dazzle", "Dev", "Digi", "Edge", "Feed", "Five", "Flash", "Flip", "Gab", "Giga", "Inno", "Jabber", "Jax", "Jet", "Jump", "Link", "Live", "My", "N", "Photo", "Pod", "Real", "Riff", "Shuffle", "Snap", "Skip", "Tag", "Tek", "Thought", "Top", "Topic", "Twitter", "Word", "You", "Zoom"]
B = ["bean", "beat", "bird", "blab", "box", "bridge", "bug", "buzz", "cast", "cat", "chat", "club", "cube", "dog", "drive", "feed", "fire", "fish", "fly", "ify", "jam", "links", "list", "lounge", "mix", "nation", "opia", "pad", "path", "pedia", "point", "pulse", "set", "space", "span", "share", "shots", "sphere", "spot", "storm", "ster", "tag", "tags", "tube", "tune", "type", "verse", "vine", "ware", "wire", "works", "XS", "Z", "zone", "zoom"]
C = ["Ai", "Aba", "Agi", "Ava", "Awesome", "Cami", "Centi", "Cogi", "Demi", "Diva", "Dyna", "Ea", "Ei", "Fa", "Ge", "Ja", "I", "Ka", "Kay", "Ki", "Kwi", "La", "Lee", "Mee", "Mi", "Mu", "My", "Oo", "O", "Oyo", "Pixo", "Pla", "Qua", "Qui", "Roo", "Rhy", "Ska", "Sky", "Ski", "Ta", "Tri", "Twi", "Tru", "Vi", "Voo", "Wiki", "Ya", "Yaki", "Yo", "Za", "Zoo"]
D = ["ba", "ble", "boo", "box", "cero", "deo", "del", "do", "doo", "gen", "jo", "lane", "lia", "lith", "loo", "lium", "mba", "mbee", "mbo", "mbu", "mia", "mm", "nder", "ndo", "ndu", "noodle", "nix", "nte", "nti", "nu", "nyx", "pe", "re", "ta", "tri", "tz", "va", "vee", "veo", "vu", "xo", "yo", "zz", "zzy", "zio", "zu"]

if __name__ == "__main__":
while (1):
# lets shuffle our pack of cards
random.shuffle(A)
random.shuffle(B)
random.shuffle(C)
random.shuffle(D)

if (random.randint(0,1) == 1):
awesomename = A[0] + B[0]
else:
awesomename = C[0] + D[0]

print awesomename + ": \t\t",

for tld in DH.tlds:
if ( DH.domainSearch(awesomename + tld) ):
print "[+]" + tld + "\t",
else:
print "[X]" + tld + "\t",
print

$ python web2hunter.py
Photospace: [X].com [X].net [X].org
Zoomcast: [X].com [X].net [+].org
Digitags: [X].com [+].net [+].org
Jabberpath: [+].com [+].net [+].org
Kaboo: [X].com [X].net [X].org

Just press Ctrl+Z if you see an awesome domain.
You can now get domainhunter+web2hunter from its guthub repository -
$ git clone git://github.com/ideamonk/web2hunter.git

Have fun! (woah! what a find - Awesomenoodle .com/.net/.org )

Labels: , , ,

Domain hunting in Python

Since last week, we've been looking for a new name for MadeToKill Design Studios for we think its too big a name and too funky to sound serious. Cool but ahem, int abundance of awesomeness, it lacks a little business sense. Soon we would be known by our new name W3Ninjas and our team expands to 4 looking forward to better and bigger projects :)
Even FOSS-shudaan people have a tough time choosing a domain! So taking inspiration from a post on HN, I set out to write a small python script to look for domains while I'm away from my desk. Its nothing more than two simple urllib2 calls. Here it is -
#!/usr/bin/env python
# Domain Hunter -- Abhishek Mishra <ideamonk at gmail.com>
# usage -
# $ python domainhunter.py < wordlist.txt

import urllib2
from sys import stdin

def domainSearch(domain):
baseurl = "http://www.google.com/a/cpanel/domain/selectDomain?domain="
try:
handle = urllib2.urlopen(baseurl + domain)
data = handle.read()

if (data.find("is available") != -1):
return True
else:
return False

except:
print " connection error ... ",

tlds = ['.com', '.net', '.org'];
# you can modify tlds to suit your needs,
# complete list of Google Apps supported tlds -
# tlds = ['.com', '.net', '.org', '.net', '.biz', '.info'];

if __name__ == '__main__':
search = stdin.readline()

while (search):
for word in search.split():
print (word + ":").ljust(30,' '),

for tld in tlds:
if ( domainSearch(word + tld) ):
print "[+]" + tld + "\t",
else:
print "[X]" + tld + "\t",

print

search = stdin.readline()


$ python domainhunter.py < list.txt
bluebells: [X].com [X].net [X].org
itchyscratchy: [X].com [+].net [+].org
muffintops: [X].com [X].net [X].org
smokinjoes: [X].com [X].net [X].org
pizzahut: [X].com [X].net [X].org

I tried it over a list of adjectives, the output was as expected, most of the words were taken, apart from agonizing.org and ossified :)

Labels: , ,

Monday, August 17, 2009

Gwibbly, another theme for Gwibber

Damn! its 6 am already, this one tool exceptionally more time. I noticed many cool looking twitter clients on OS X have that shiny-little twitter bubble to display message. Though not that, but this one - Gwibbly, is one attempt to get those tweet bubbles into gwibber. Initially I did round corners with javascript, which actually slowed down the rendering very much, replaced that by -webkit-border-radius: 10px; and done :) Well, this time I got 3 variants -


To install the new gwibber theme:

1. Download the new theme from google code
2. Decompress it to ~/.local/share/gwibber/ui/themes/
You should end up with folders names gwibbly-* with a few files inside it.
Make that path if it not present
3. In Gwibber, open Preferences (Gwibber->Preferences or Ctrl+P).
Pull down the theme chooser and choose ‘gwibbly’, or 'gwibbly-dark' etc.
4. On my system, it took Gwibber a few seconds to apply the new theme.
Be patient, and things should shape up.

Labels: , , ,

Gwibbiquity-micro

As I switched back to 1280x800, I felt the previous theme was too big to show more than 5 tweets a page. So I just modded the old one a little bit into a micro edition.


To install the new gwibber theme:

1. Download the new theme from github
2. Decompress it to ~/.local/share/gwibber/ui/themes/
You should end up with a folder called gwibbiquity-micro with a few files inside it.
Make that path if it not present
3. In Gwibber, open Preferences (Gwibber->Preferences or Ctrl+P).
Pull down the theme chooser and choose ‘gwibbiquity-micro’.
4. On my system, it took Gwibber a few seconds to apply the new theme.
Be patient, and things should shape up.

Labels: , ,

Sunday, August 16, 2009

Gwibbiquity a theme for Gwibber

I've been using Gwibber for accessing twitter and syncing my facebook status with twitter. Earlier I was disappointed with Adobe AIR based clients for AIR itself didn't run well on amd64 :/ . Gwibber's default theme looks quite disappointing and the best you can get is Brave by Ginkyo. Gwibber 2.0's prototype looks awesome, but before we get there, I would like to add up one more theme to the project - Gwibbiquity - another theme based on Brave and inspired by the gradients of Lounge.
It didn't take more than an hour to come up with it. Thanks to Gerry Ilagan's tutorial on how to create one :) Here's how it looks -


To install the new gwibber theme:

1. Download the new theme from github
2. Decompress it to ~/.local/share/gwibber/ui/themes/
You should end up with a folder called gwibbiquity with a few files inside it.
Make that path if it not present
3. In Gwibber, open Preferences (Gwibber->Preferences or Ctrl+P).
Pull down the theme chooser and choose ‘gwibbiquity’.
4. On my system, it took Gwibber a few seconds to apply the new theme.
Be patient, and things should shape up.

* thanks to Jake Tolbert for easy installation instructions

Labels: , , , ,

Saturday, August 15, 2009

GDB, Why didn't I use you all this time.... ?!

My first introduction to gdb was through "Hacking - The art of exploitation", a book on writing exploits and many other basics of network/application security by Jon Erickson. During those days, I neither ran linux on my machine, nor did I care to go deep into tools explained in the book. Installing Gentoo, which was used to write examples of the book was a painful experience. And I did not know of the wonderful offsprings of mother Debian like Ubuntu!
Anyways coming to the point, I seriously wonder why don't they teach gdb at our colleges. I just realised that just two weeks back we had network simulation lab, one boy said "Ma'am I got segmentaton fault! I'll do it next time..." and the teacher too, aware of the mysteries of segmentation fault, let him go. Forget mysteries, everyone in my college knows debugging as a painful task that involves putting printfs everywhere in your code. And, that's not all, it alone doesn't assure where the hell things went wrong, then you start printing the values too, its more of a guesswork! Now think about this - they wrote the linux kernel in C right ? did they debug their way to every new releases by putting a printf before every damn line ?! And before the release, did they spend sleepless nights just removing those printf patches left out here n there! Nopes, not at all.
Anyways lol, coming back to the point, let me show you some nice things about gdb, the GNU Debugger that I just found out right now reading 'Developing with Gnome'
Consider this code -
#include <stdio.h>

int total;

foo(){
// calls bar() 5 times
int i=5;
while (i--)
bar();
}

bar(){
// calls baz() 2 times
int i=2;
while (i--)
baz();
}

baz(){
total++;
}

int main (){
// just calls up other funcs that do something on total
total = 0;

foo();
bar();

printf ("%d\n",total);

return 0;
}
As you can see, it increments a global integer total 5X2 times using foo() and then 2 times more by a call to bar() in main(), final output being 12. Simple enough! I've just nested the functions to stress on the fact that bigger programs can be tough to debug.

ideamonk@sacea:~$ gcc segfault.c
ideamonk@sacea:~$ ./a.out
12
ideamonk@sacea:~$

Now I'll add some weird lines to the code and try to get a segmentation fault.
Let's modify foo() as this -
foo(){
// calles bar() 5 times
int i=5;

char c1='a',*c=&c1;
while (i--){
printf ("%c ", *c);
c+=0xdeadbeef;
*c++;
bar();
}
}

What it tried to do is, have a pointer to a character, shift that pointer in insanely far that it exceeds permissible addressing, and poof! get us a segmentation fault. Here it is -

ideamonk@sacea:~$ gcc segfault.c
ideamonk@sacea:~$ ./a.out
Segmentation fault
ideamonk@sacea:~$

That's it, all I get is a segmentation fault. Now someone right from my computer programming course would go about debugging this by putting printfs before every possible suspect lines :P. But with gdb, you can actually pinpoint the line where it broke, see the source and even find out which functions were called in what order, and even more, we also get to have a look at values of local variables. What more could've anyone wanted. Let me show you how gdb makes debugging easy as a pie -

// we'll ask gcc to turn debugging flags on and optimization flags off by a -g
ideamonk@sacea:~$ gcc -g segfault.c
ideamonk@sacea:~$ gdb a.out
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
// lets run our code
(gdb) run
Starting program: /home/ideamonk/a.out

Program received signal SIGSEGV, Segmentation fault.
0x000000000040052d in foo () at segfault.c:12
12 printf ("%c ", *c);
// Look at that! there we have it, which line, what was there, we know all :)
// lets seek more
// list would give us codeblock where it occured
(gdb) list
7 int i=5;
8
9 char c1='a',*c=&c1;
10
11 while (i--){
12 printf ("%c ", *c);
13 c+=0xdeadbeef;
14 *c++;
15 bar();
16 }
// we'll take a look at local vars now
(gdb) info locals
i = 3
c1 = 97 'a'
c = 0x8000599580ff

// there you have it :) the pointer c went out of bounds as intended
// as I said we can look at the order of function calls, here it is
(gdb) backtrace
#0 0x000000000040052d in foo () at segfault.c:12
#1 0x00000000004005c4 in main () at segfault.c:34
(gdb) ^D


Now you exactly know what went wrong and where, get back to your editors and you know exactly which line number is the bug you need to squash.
Happy debugging and a Happy Independence day to one and all :)
on #linux-india one guy asked me this when I greeted with the usual "Happy Independence Day!" thingie -
"What are you happy about?", "Why so happy?"
It set me thinking, what for? I could come up with one answer, "I'm happy for the possibility of getting a free jalebi tomorrow.", for I realised that there isn't any answer to "Are we free?", I guess we're not, unless we abandon the common road on which everyone walks and take the road not taken. I would like to take it :)

Labels: , ,