My older brother first introduced me to the idea of a pronounceable password generator. At one point I took a look at the one available here., and at one point I downloaded the C++ version to try and reverse engineer the generator. Well, fast forward to tonight when I had the opportunity to do so from the JavaScript version into Python. I suspect my engineering may not be quite so perfect, as almost all of my generated PWs start with the letter 'a'. Of course it may be a function of the random number generator. As far as programs go, it is actually fairly simple - the complexity is really in the trigram matrix - which is huge, accounting for about 620 lines. Aha! I found the issue - I was seeding with 12579.0 instead of 125729.0, whoops!
So now it works. Sweet action.
You can see the source here.
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
Tuesday, December 7, 2010
Tuesday, October 19, 2010
Fun with Python
This is really pretty useless... but a great example of something awesome you can do with Python:
It's a waste of time when the math module already contains math.factorial, but it just shows off some of the more esoteric features of Python.
def factorial(n):
n = abs(int(n))
n = 1 if not n else n
return reduce(lambda x,y: x*y, xrange(1, n+1))
It's a waste of time when the math module already contains math.factorial, but it just shows off some of the more esoteric features of Python.
Wednesday, June 16, 2010
A Tablet...
We have already got a tablet and we need no more tablet!
So I've been running Ubuntu 9.04 on my laptop since pretty much the beginning. When 9.10 Karmic Koala was released I almost upgraded, but then I realized I was very near to the end of a semester and what a dumb idea that would be. Especially since I use my laptop for nigh on everything.
But recently I stumbled (or re-stumbled, as the case may be) upon a blog that has some great posts about the x61. It would seem he's got pretty much the same laptop as I have - I'm mainly led to believe this by the fact that he has no touch screen either.
Using this post, I finally got the HDAPS working, back when I was running Ubuntu 9.04.
But now that I'm in between semesters (starting up this Thursday), I upgraded to 9.10 (mainly because Krizka posted about his experience being fairly straightforward). Of course it messed with all my custom tweaks with the tablet rotation, so I had to fix that. Using Krizka's autorotate project I pretty much had no trouble. After getting my hdaps module working again, the autorotate worked perfectly - something I had never been able to accomplish previously. The only problem is that with my previous script when the tablet display was folded down I liked the screen to be inverted - I found that was the best for my use in school. So looking through some of the documentation and inspiration that Krizka posted/provided, and using some of the tools I came up with this result:
I created a python script called "rotate" (you could name it .py if you wanted, but I didn't) and inserted the following:
Then:
After that, I created a file:
into which I put the following (taken from here)
And now I have the best of both worlds. When I flip my screen down, it auto rotates to the orientation I like best (and I also have the ability to launch some extra programs if I need (though I think I may have to re-modify the wacomcpl script to automatically launch the config dialog... whoops, forgot to save that customization!)
So, this is really a big "Thank you!" to Karol Krizka
So I've been running Ubuntu 9.04 on my laptop since pretty much the beginning. When 9.10 Karmic Koala was released I almost upgraded, but then I realized I was very near to the end of a semester and what a dumb idea that would be. Especially since I use my laptop for nigh on everything.
But recently I stumbled (or re-stumbled, as the case may be) upon a blog that has some great posts about the x61. It would seem he's got pretty much the same laptop as I have - I'm mainly led to believe this by the fact that he has no touch screen either.
Using this post, I finally got the HDAPS working, back when I was running Ubuntu 9.04.
But now that I'm in between semesters (starting up this Thursday), I upgraded to 9.10 (mainly because Krizka posted about his experience being fairly straightforward). Of course it messed with all my custom tweaks with the tablet rotation, so I had to fix that. Using Krizka's autorotate project I pretty much had no trouble. After getting my hdaps module working again, the autorotate worked perfectly - something I had never been able to accomplish previously. The only problem is that with my previous script when the tablet display was folded down I liked the screen to be inverted - I found that was the best for my use in school. So looking through some of the documentation and inspiration that Krizka posted/provided, and using some of the tools I came up with this result:
I created a python script called "rotate" (you could name it .py if you wanted, but I didn't) and inserted the following:
#!/usr/bin/python
import sys
import dbus
import pynotify
from traceback import print_exc
from libautorotate import *
D = DIRECTIONS = {'normal':1, 'left':2, 'right':8, 'inverted':4}
def main():
rotate = AutoRotate()
current = rotate.GetRotation()
if len(sys.argv) > 1:
try:
next = DIRECTIONS[sys.argv[1]]
except KeyError:
print sys.argv[1], 'is not a valid direction!'
sys.exit(1)
else:
rotate.SetRotation(next)
else:
rotate.SetNextRotation()
main()
Then:
sudo cp rotate /usr/local/bin/
sudo chmod 555 /usr/local/bin/rotate
After that, I created a file:
sudo vi /etc/acpi/events/swivel-down
into which I put the following (taken from here)
# Called when the tablet screen swivels down
event=ibm/hotkey HKEY 00000080 00005009
action=/usr/local/bin/rotate inverted
And now I have the best of both worlds. When I flip my screen down, it auto rotates to the orientation I like best (and I also have the ability to launch some extra programs if I need (though I think I may have to re-modify the wacomcpl script to automatically launch the config dialog... whoops, forgot to save that customization!)
So, this is really a big "Thank you!" to Karol Krizka
Subscribe to:
Posts (Atom)