is that really prime?
so, today I wrote my second python script ( big accomplishment ) which just lists prime numbers. I put it in a file called prime.py so I might be able to use it later on!! This is how it looks like:
====================================================
#printing a range of prime numbers def isPrime( n ): factor = n // 2 while factor > 1: if n % factor == 0: return 0 break else: factor -= 1 else: return 1 def listPrimes( num ): for n in range( num + 1 ): if n > 1: if isPrime( n ): print n, 'is prime' listPrimes( 100 );
====================================================
and that’s all there is to it! Well, just add the indentation yourself, I still haven’t figured out how to keep the indentation when posting scripts!
hahahaha and on a side note, I had to check all of the output numbers myself ( not thoroughly though ) just to make sure I didn’t make any mistakes in the script! funny way of debugging.
UPDATE: thanks to a fantastic blogger, Vlad Dolezal ( anamazingmind.com ) I’m able to keep the formatting of the code!
Enabling flash support for firefox in Fedora 9 for 64bit arch
ok, I admit, I got lost for less than fraction of a second ( literally ). what you do is simple, because there is no 64bit flash support from Adobe, you install the 32bit one and use it with 32bit version of nspluginwrapper. That’s all there is to it. To do that:
1) install adobe flash plugin from this link.
2) go to terminal and type:
su -c ‘yum install nspluginwrapper.i386′
3) go and test it and enjoy it!
and don’t forget to comment if it worked or not!
UPDATE: and you should also install libflashsupport.i386
su -c ‘yum install libflashsupport.i386′
thanks to Bart ( see comments ) for the reminder
A fancy keyboard
Today I was typing a little bit and then I just wanted to move my mouse to some other place on the screen. At that moment I remember the old laptops which had a dot in the middle of their keyboards and you could push that dot to a specific direction and then your mouse moved. My uncle had that kind of laptops once I was just a little kid ( as if I’m so huge now! ).
Now, that, made me think that what if there were keyboards in which you had a small, very small dot in the middle of it and if you pushed it, your mouse moved, without the need to get your hand off keyboard and reach for mouse just for a little move. It really doesn’t worth it!! A good use of this ‘dot’ would be when you’re for example scripting, and you want to just open a file and keep typing. Well, you could just get off the keyboard and move the mouse and do your stuff with it, or just set some shortcuts before hand and then use those shortcuts you made to reach your file, but it would be so much easier if you could just move your mouse with keyboard, a virtual, fast-accessed mouse right build into your keyboard. If any of you have seen those old laptop I’m talking about, you have then a very clear idea of what I’m thinking.
The built-in mouse ( that ‘dot ) could be somewhere between Y, U, and H on keyboard. It would make life soooooooooooo much easier, seriously. Not just that, maybe some people just don’t like to use mouse ( e.g. me ) but NEED to use it for just a fraction of a second ( figuratively speaking ), then you could just use that ‘dot’ in your keyboard!!!
wouldn’t that be a good idea? let me know what you think about it!
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 ).
=====================================================
<pre>
#!/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()
<pre>
======================================================
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.