Thursday, 17 February 2011

Yüksek Sadakat - Haydi Gel İçelim

Yüksek Sadakat
Recently found this song - Haydi Gel İçelim. It's in turkish, but sounds very good, I think.

Images, python and base64

Kari - embeded as base64 :)
Look at the image on the left. It's embedded. The idea is very simple.

Open some image file.

Read it in a string.

Encode it with base64.

Now you can use the result as src in the img tag. This image can be used in html email messages or can be used in the css.



Friday, 11 February 2011

Random python thoughts, sorted by number of occurrences

This is just a memo about ease of working with ranges, random choices and sorting.
Let's see a piece of code:
import random
import string
from operator import itemgetter

sample_dict = {}
for x in range(random.choice(range(2,25))):
    r_num = random.choice(range(0,x+1))
    lst = random.sample(string.letters,r_num)
    for l in lst:
        if l in sample_dict.keys():
            sample_dict[l] += 1
        else:
            sample_dict[l] = 1
print sample_dict
itms = sample_dict.iteritems()
print sorted(itms,key=itemgetter(1),reverse=True)
This is python, so there is no need for explaining. But it's worth to mention some cool things for newcomers.
When you need a list of numbers just choose your range - range(2,25).
And if you need just a random number from this range - random.choice(range(2,25)).
And if you need a few letters, you can get them from string.letters, like this random.sample(string.letters,5). Now you have five random letters.
The script above is counting, how often these random letters are repeated, by using them as dict keys. When you have such dict you must sort it by values in order to show occurences of every key - sorted(sample_dict.iteritems(),key=itemgetter(1),reverse=True)

Friday, 26 November 2010

Ayo - Down On My Knees

Joy Olasunmibo OgunmakinRecently I discovered Joy Olasunmibo Ogunmakin.
More information about her can be found in wikipedia and on her Official website.

Sunday, 21 November 2010

Organize your photos by date in nautilus

I already know how to use the exif information in pyhton to group photos in folders by date the picture was taken( see here ). The problem is that you must run the script in a terminal and the script must by in the python path. So I changed it a bit. Now the script can be used in the Nautilus. To group photos in any directory I can select Scripts-> Group By Date.

Tuesday, 2 November 2010

Simple way to organize photos by date

I have a lot of pictures. Like most people today. They were all dumped in one directory. It was very difficult to view them. So I wrote a very short python script that reads from the EXIF date the photo was taken. Create a directory for that date and move the photo in this directory.
Here's the script:
import os
from PIL import Image
import shutil

cdate_tag = 0x9003

files = [f for f in os.listdir('.') if f.endswith('.JPG')]

for f in files:
    if os.path.isfile(f):
        img = Image.open(f)
        date = img._getexif()[0x9003].split(' ')[0].replace(':','_')
        if not os.path.isdir(date):
            os.mkdir(date)
        shutil.move(f,os.path.join(date,f))
        print f,date
        img.fp.close()