Back in CPSC 101, we did a lot of image editing. We only used PPM images in class and I was thinking the other day about how even though I hated the project at the time, it was pretty interesting. So, I decided to re-code some of it in Python. Basically, all I’ve done is written a script that will allow the conversion of any color PPM image into greyscale. I feel like this can be pretty handy, as it’s fast and seems to do a pretty good job.
Here’s the before image (Ironically, I had to convert to another image format before posting):
And here’s the output:
A few particulars about the files and scripts:
I used the P3 header, which is easier because it allows you just to write ASCII into the file.
Also, you must ensure that the header of the input photo must only have 3 lines. I’ve found that if you convert a JPEG from Gimp, it adds its on line in the header. It was easy to just do ‘nano in.ppm’ in terminal and remove the line they put in.
The script can be run using ‘python grey.py <input filename>’
This ONLY works on PPM images. Maybe someday I’ll look into another image format.
So this week, I’ve been in a crunch to get some last minute cash for spring break. My Dad had a little opportunity for me to write a Python script for him to use at the office. The back story is basically that the warehouse where he works has to take inventory using some sort of hand-held scanning devices.
He wanted me to write a script that, when placed in a directory with any given number of output files from the devices, generates a document stating each file and how many cartons are in each pallet. Sounds like a perfect job for Python, right? Exactly right. It literally took me about 45 minutes to 1 hour and I had the thing completely off the ground running. I’ve decided to post it not so much because this exact program is really useful to anyone else, but because I definitely learned some cool I/O stuff while doing it.
First, I think it’s useful to get an idea of how the files looked coming in. They were basically Wordpad documents generated by Windows CE and didn’t have much format to them. Here’s a little example:
As you can see, It’s a little hard to decipher. Also, keep in mind that this is not a full file as I didn’t want to post 600 lines in there. Anywhere there is a ‘\par’, except for the lone one at the end, there is a carton in the warehouse. All I had to do was figure out a way to add.
My program gave the following output:
So, as you can see, it seems to work pretty well. I can also imagine this is WAY easier than counting by hand. So, here is the code that converts one to the other. Be sure to notice the usefulness of the calls like getcwd(), which proved to be awesome for finding all the files in the directory.
I am in a Distributed Computing class this semester. We just had to write a brute-force password cracker using the Condor grid we have on-campus. It really took forever to generate an 8 character (a-z) code even though I ran it 676 different times. Total run-time was about 25 minutes. Anyways, we also had to create a password cracker using a dictionary file. I thought this was an awesome project and it was so much faster! I’ve decided to post the dictionary Python script. It should crack any word, given that it is in whatever dictionary you choose to use it against. My word for the project was “schnecke”, which is German for “snail”. Knowing that, I checked it against the Ubuntu New German dictionary. The run-time was ~.3 secs.
Check it out!
P.S. In order to get language dictionaries to check against in Ubuntu, it is as easy as “apt-get install ngerman” or whatever language package you need. I found a list of these packages with a quick Google search. If you’re doing more evil than good, you can also easily find a list of “common passwords” in text form.