Learning python…

After quite some time not blogging anything, I though I would blog about my recent “success.”  Ok, you see it’s in quotes and that means it’s not generally a big deal.  Simply I started to learn python.  And I was able to write an addressbook (  I really needed one ) in just 4 hours, and with only 62 lines of code ( no OOP, only structured ). so, for a quick reference, I’ll just post it here.  it’s also good to say that it was written in less than 30 mins ( including debugging and including the fact that it was my first python script/program ).

=====================================================

#!/usr/bin/python

D = { }

name = ”
number = 0

print “For searching a particular phone# press 1″
print “For adding an entry press 2″

opt = raw_input()

if opt == ‘1′:
file = open( ‘adb.txt’, ‘r’ )

string = file.readline()
string = string.rstrip()

while string != ”:
rl = string.split()
fname = rl[ 0 ]
fnum = rl[ 1 ]

D[ fname ] = fnum

string = file.readline()
string = string.rstrip()

print “enter the desired name: “
name = raw_input()

for key in sorted( D ):
if key == name:
number = D[ key ]
print number
exit()

print “no entry found”
exit()

elif opt == ‘2′:
print “enter a name and a number: “
file = open( ‘adb.txt’, ‘a’ )
s = raw_input()

while s != ‘0′:
l = s.split()
name = l[ 0 ]
number = l[ 1 ]
D[ name ] = number

file.write( name )
file.write( ‘ ‘ )
file.write( number )

s = raw_input()

exit()

else:
print “inappropriate option”
exit()

======================================================

so, that’s it, 62 lines.  It still feels strange to not put if, while, for statements in blocks {}  but I will get used to it.  The indentation syntax is also good, I thought I wouldn’t like it, but turned out that it makes the code easy to read.  Not much difference though, I still did the same thing with C++.

Anyhow, that’s enough for today, I’ll keep you posted.

looking for some web space

Okie dokie, I haven’t posted anything for a while, mainly because I was busy AGAIN with compiling KDE 4.1 trunk.  I finally did it, successfully!  I just followed the tutorial at techbase!

Anyway, as I was waiting for this to compile, I wrote two useful scripts, each one only 60 lines.  One of them is a bash utility which you give a directory as an argument to it and then it backs up that folder and sends it over to a remote server ( the server should support sftp ).  It’s good for example if you have another computer and it supports sftp, and then you want to back up your files and send it over, but do not want to waste a whole amount of time on this!  It’s annoying when you have to back up everything.  Though, what I do is that I have a backup folder in my home directory, and then I put everything in it, and then I just run this script.  And it will replace the old version, which is good!!!

The other one is a c++ program that converts a string of characters ( a line of text ) into binary form!  This is also useful because sometimes I want to send some things in ‘code style’ ( being fancy here )!  Anyway, it was fun, at least I didn’t waste my time doing nothing :)

So now, the problem is: I don’t have anywhere to upload these two guys ( read: files ) so you could also use them!!  Does anyone know where can I upload them?

The real reason why we use linux

I was looking looking around the net when I ran across a very interesting post on why do some people use linux! People who use linux usually say because it’s secure, free, and because it’s customizable. But is that why we really use linux? Those reasons are all valid, though, but for us linux users, there is something more to linux than just security and customizability ( put the freedom concept aside ).

I personally have multiple reasons to use linux. One being that other OSs simply just don’t do things the way I want. Another on being that sometimes I’m curious about what is going on inside that program I’m using, so I check out the source code to see what is going on. I like using terminal, it’s fun!! There are many other reasons why I use linux which I can’t remember now, but I agree with every bit of this post by Vlad Dolezal.

Shell history meme

following the planet Fedora’s race for who got the higher number, I’ll do mine too.  My numbers are nowhere close to those numbers, but it’s fun.

armin@blk-215-88-124:~> history | awk ‘{a[$2]++ } END{for(i in a){print a[i] ” ” i}}’|sort -rn|head
32 cd
29 exit
19 ls
14 su
13 vncviewer
13 g++
10 sftp
7 vim
6 fluxbox-generate_menu
6 ./calc

‘calc’ is the name of a single-source-file, very simple but very handy calculator I’m working on to make life calculations easier!

Fedora 9 artwork: Round 3 final

This is the link if you want to see how are those Sulphuric waves doing :)

converting text to binary and vise versa

Today I found an interesting fact: the number of the ANSCII character with the base of 10, is it’s corresponding binary with the base of 2.

Now this might be overwhelming with the first look, but take a look at this chart. If you take a character ( preferably your favorite character ) and look up its ANSCII number, then convert that number to base 2 ( I hope you have learned how to do it in school ), there you have the binary! I won’t explain how you convert a base 10 to base 2, but the base 2 number you get, must be 8 bytes ( 8 ones and zeros beside each other ) and that makes up a ANSCII printable character.

for example, if you want to type ‘NAME’ your numbers according to that chart would be: 78 65 77 69 Now take this number and convert each of them into base 2 with 8 bytes: 01001110 01000001 01001101 01000101 YAY!!! THIS IS THE BINARY!!!

footnote: cheating is not generally good, but you can just copy the corresponding binary code for each character from the chart ;)

Inkscape .46 released

I think I’m a little bit too late.  It’s already 4 days that it’s out but I was too busy testing Fedora 9 beta and I for a side note, I should say, it’s stable.  Anyway, getting back to the inkscape, .46 version has a lot of new features which make life even easier for newbies like me!  one of the new features I like is ‘markers’  you set an object as a marker, set a path and tell the path to put one of those markers you created in each of its segments.  This tutorial shows you how it works.  ( it would make a good background wallpaper by the way )

The packages for Ubuntu and Fedora 9 are ready, but I’m not sure about others, ( e.g. windows, *BSD, OS X, other distributions of linux ).  You can go to inkscape.org and download them now, or just refer to your local packages! :)  simple and easy as always (TM)

-footnote:  ’simple and easy as always (TM)’ is a trademark of linux community :)  ( just kidding )

moving files through SFTP

SFTP is the brother of SSH, it transfers your files securely through an FTP port.  One computer is client and another one server.  To use SFTP on a linux system simply just type:

$ sftp username@ipaddress

for example, it would look like this:  $ sftp johnsmith@127.0.0.1

Then just press enter and enter the remote password and log in.  you can find some of the useful SFTP commands here.

If you are trying to connect to a windows server ( SFTP to/from a windows system ) you should first setup openssh on your system.  The guide on how to setup openssh on a windows machine is in the previous post ( see the P.S. section of the previous post ).  After setting that up, everything will be the same: $ sftp username@ipaddress   and done!

leave comments if you were successful in SFTPing to your machines! ;)

Some useful terminal programs

Lynx:

Lynx is a console web browser. Very simple and easy to use, just press and type a URL to go to that URL. press d to download the target. But the downfall is that it doesn’t show images ( because it’s console-based ) and therefore some websites ( e.g. facebook ) do not support it.

800px-lynx-wikipedia.png

Alpine:

An email client. Yes, that’s right, a console-based email client. You can setup IMAP and POP access to your favorite mail service provider.

SSH:

With SSH service you can connect remotely to other SSH-enabled computers ( e.g. linux system ) very securely. In terminal, just type: ‘$ ssh -l login host’ while ‘login’ is the remote login/username and ‘host’ is the IP address or host computer address.

united windows and linux screenshots

ok, I finally tried to unite my fedora system with windows XP pro SP2 ( fancy name ) and it worked. Thanks to softpedia.com for the great tutorial and thanks to virtualbox for making it possible. By the way, today I saw that Sun Microsystem has acquired Innotek.

Anyway, these are the screenshots, I just followed the tutorial ( refer to second previous post for that ):

screenshot.png

screenshot-1.png

screenshot-3.png

screenshot-4.png

« Previous entries