• Raspberry PI Boom! What a useful tiny useful computer.

  • Enter Slide 2 Title Here

  • Enter Slide 3 Title Here

Monday, July 25, 2011

How to get the include once -php anywhere?

you can now get your script, config or class included anywhere and get the correct path using dirname and __FILE__
Here's an example:

from here you can get the absolute path of your file like the one I've shown will result in:
/home/user/public_html/inc/class/class.php and the script resides in /home/user/public_html/some/down/subdir/subdir/index.php that require the class to be included.

It will recrusively go up one level path and get the absolute path of the class name to be include. This is useful when you have lots of include that needed and want it to be accessible through out your main apps.

Tuesday, July 19, 2011

Eliminate Duplicate emails in evolution

Aim: To clean duplicated emails in evolution
Required: python
Usage: python cleanupmbox.py -i ~/.local/share/evolution/mail/local/Inbox -o ~/.local/share/evolution/mail/Inbox.ok -h inbox.h

Last steps, replace Inbox.ok with the original Inbox. Remember to do backup of your Inbox file.

cleanupmbox.py script
#!/usr/bin/env python
# author Marilen Corciovei len@len.ro, this code is offered AS IS, use at your own risk

import re, sys, email, getopt, marshal

msg_start = 'From'
cleaned = None
mids = {}

def parse_mbox(file_name):
file = open(file_name, 'r')
msg = ''
lastLine = ''
while 1:
line = file.readline()
if not line: break
if line.startswith(msg_start) and lastLine == '':
if len(msg) > 0:
msg = ''
msg = msg + line #+ '\n'
lastLine = line.strip()

def parse_msg(smsg):
m = email.message_from_string(smsg)
if 'message-id' in m:
mid = m['message-id']
if mid in mids:
print 'Duplicate Message-ID:', mid
print 'New Message-ID:', mid

if __name__=='__main__':
in_file = ''
out_file = ''
hash_file = ''
opts, args = getopt.getopt(sys.argv[1:], "i:o:h:")
except getopt.GetoptError:
print 'Usage', sys.argv[0], '-i input -o output [-h hash file]'
for o, a in opts:
if o == "-i":
in_file = a
if o == "-o":
out_file = a
if o == "-h":
hash_file = a

if in_file == '' or out_file == '':
print 'Usage', sys.argv[0], '-i input -o output [-h hash file]'

#global cleaned
cleaned = open(out_file, 'w')
if hash_file != '':
mids = marshal.load(open(hash_file,'r'))

if hash_file != '':
marshal.dump(mids, open(hash_file,'w'))

Original article from: len.ro

Saturday, July 9, 2011

Programming Gig Is Back

The Programming Gig Blog is back with a new look. Sorry for the late
update as I'm very busy with all the work and programming stuff. We will
continue discuss about the programming of PHP, Java script, Mysql and
programming stuff along this blog.