:)
Saturday, May 22, 2010
Friday, June 12, 2009
Putting watermark to images in batch
Yesterday I bought Sony H50 point and shoot, how could I resist taking bulks of pictures! After filling up my PC with scores of pictures, my next task was watermark them IN BATCH. PIL striked my mind and the function in the end of the post followed.
While goolging, I have seen many tiny softwares doing same thing, but 1) none of them were capable with my Linux machine 2) and even on Windows, why should I make my registry dirty. So, here is the solution, only Python is needed.
import Image, ImageEnhance, os
from os.path import join
def test():
batch("/media/disk/pics", "/home/hasanat/outputfolder/", "/home/hasanat/watermark.png")
def batch(infolder, outfolder, watermark):
mark = Image.open(watermark)
for root, dirs, files in os.walk(infolder):
for name in files: try:
im = Image.open(join(root, name))
if im.mode != 'RGBA':
im = im.convert('RGBA')
layer = Image.new('RGBA', im.size, (0,0,0,0))
position = (im.size[0]-mark.size[0], im.size[1]-mark.size[1])
layer.paste(mark, position)
Image.composite(layer, im, layer).save( join(outfolder, name))
except Exception, (msg):
print msg
if __name__ == '__main__':
test()
This is self explanatory. Function batch takes path of input folder, output folder and path to the watermark picture. Output folder must exist, it won't create it automatically.
Happy watermarking!
Wednesday, May 6, 2009
Cool way to ask a CS major to vote
//Author: Saleem Ullah
//Not yet compiled but positive results expected
import org.politics.students.council.elections.Vote;
import org.politics.students.council.elections.Cast;
import org.politics.students.council.elections.Rules;
import God.utils.Bless;
public class Main{
private AndayList andayList = null;
static void main(){
Vote vote = new Vote();
vote.setDate("07", "may", "2009");
vote.startsAt("11", "am");
vote.endsAt("05", "pm");
vote.setVenue("RecRoom");
setCandidates();
castVote(vote);
}
public void setCandidates(){
andayList = new AndayList();
andayList.add(Abdul Rehman Qureshi);
andayList.add(item2);
andayList.add(item3);
andayList.add(item4);
andayList.add(item5);
}
public void castVote(Vote vote){
if(Rules.IDCARD.present || Rules.SMARTCARD.present){
Cast castVote = new Cast("Anonymous");
castVote.castFor(andayList[0]); // Please Please Please
for(int i=0;iBless.godBless(andayList[i]);
}
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PLEASE VOTE FOR ABDUL REHMAN QURESHI (MY DEAR ROOMMATE)!!!
Time: 1100 Hrs, Thursday, 07 May 2009
Venue: Rec Room
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Saleem.
Friday, April 24, 2009
Ditch Network Sharing
I always use to think that there should be some HTTP based solution to it as HTTP is proven protocol for file transfer, so I found a way and luckily dam easy way.
All you need is to install python on your system, even if you are not a coder, 20 - 30 MB setup of Python wont bite you. After you install it (generally Linux has it by default), go to command line, change directory to the directory you want to share and write:
Python -m SimpleHTTPServer
thats it. Now you have exposed that folder on port 8000. Open web browser from a computer on the network, open http://your-ip:8000 and you can download any file from that computer you want :)
Wednesday, April 22, 2009
Sahana Proposal
Sahana
Disaster Management System
Google Summer of
Code 09
P2P
Synchronization of Shana Servers
(ShanaPHP <>
ShanaPy, ShanaPHP <> ShanaPHP, ShahaPy <> ShanaPy)
Name Syed
Hasanat Ali Kazmi
Email
hasanatkazmi@gmail.com
Freenode
IRC Nickname: hasanatkazmi
IM
gtalk/jabber: hasanatkazmi@gmail.com
Biographical
information:
Present
Address: Room 102, M3, Lahore University of Management Sciences,
Lahore, Pakistan.
Country:
Pakistan
TimeZone:
GMT+5
Education:
BSc Computer Science Major, Junior year.
CV: http://hasanatkazmi.googlepages.com/hasanat-cv.pdf
Overview
of your exposure to similar technologies and/or FOSS in general:
I
have hands-on experience of web development using LAMP (both Python
and PHP), MVC, Python, Linux (Debian), web services, .NET.
“Why
would you like to help the Sahana project?”:
I
hail from Muzaffarabad which was the center of 2005 Pakistan
earthquake. I have seen miseries and Sahana helping on ground.
Besides emotional reasons, I have interest in cloud computing and
clustering, synching two servers is first step in clustering and I
want to take first step.
Have
you reviewed the Important Dates and Times?
Yes,
I will be free in the whole coding part of project except first few
days (up to 5 days)
Do
you have any significant conflicts with the listed schedule? If so,
please list them here.
No
Will
you need to finish your project prior to the end of the GSOC?
No
Are
there any significant periods during the summer that you will not be
available?
No
(except for the first few days, around 4 days)
Syncing
two Sahana servers is basically about syncing their databases. It
cannot be simple database dump because we also have different
database semantics at SahanaPHP and SahanaPy. So first I'll create a
module in SahanaPy which exports database as in SahanaPHP. The idea
is to build upon presently exporting mechanism. I will also extend
Synchronization module in each Sahana server to add automatic
synchronization by adding a new feature called 'Sync Pool' (As shown
in diagram). It will basically list all those pools which that
instance of Sahana belongs to. A user (admin) can join new pools,
edit the relationship with different pools (like type of data to
import, time lag for each sync attempt etc).
Software
which implements Zero Configuration runs continuously in the
background. It has a search mechanism which is implemented by two
tasks, 1: It exposes services with the name of all those pools which
the instance of Sahana has subscribed to. 2: It 'searches' all those
Sahana instances which have also subscribed to its pools. Once it
finds servers which are in the same pool as it is, it fetches their
database using Synchronization methodologies currently present (HTTP
GET/POST). User can also specify server by IP/URL. Then it parses the
XML and adds unique records in the database. At the time of
installation, software needs to know administrative password of
database.
This
section is to provide the detail of your project proposal. Take as
much space as is necessary.
Project
Deliverable - What is the essence of the project? What capability are
you looking at adding to Sahana that will expand its capability for
emergency/disaster management?
The
core of the project is to implement automatic syncing between
different instances of Sahana servers irrespective of the fact that
whether they are PHP or Python servers. Syncing of Sahana servers is
very important because there are many cases when multiple instances
of Sahana servers are installed, e.g. in the event of Kashmir
earthquake, different groups leave for different villages. Each group
has a laptop with instance of Sahana server installed. Other group
members access the server using PDA and add data on the go. When all
groups return to the base camp, they have to export their data
manually and the central server imports the data manually. This
process needs to automate. This will dramatically increase the
capability of system in emergency as everyone will be able sync with
other servers on the go. Technical requirements of the system will
also be very low, as in most of the cases, admin/user needs not to
know IPes of other instances of Sahana (though this option will also
be provided to override automatic search of IP adresses).
Project
Justification - What is the relevance of your idea to the project?
Why do you think it’s important to *have* this idea integrated
to the Sahana system.
This
project is very much relevant to Sahana and the community has been
taken in confidence about this project. Community expressed a dire
need for automatic syncing. This project will enhance the
capabilities of the Sahana in practical situation as it will make two
different types of servers compatible with each other and will
streamline synching between them.
Implementation
Plan - How are you going to implement your project? Use this section
to expand in as much detail as possible how it should be constructed.
(Refences
for explanation: http://hasanatkazmi.googlepages.com/sahana-mod.jpg
http://hasanatkazmi.googlepages.com/sahana-rough.jpg
)
Here
is step to step implementation of this project:
1.
Manual synchronization module in SahanaPy:
The
first part of the system would be to make almost same synchronization
module in SahanaPHP as present in SahanaPy. SahanaPy is based on
web2py which provides smooth access to database. Converting the data
to XML would be carried out using XML libraries in Python. I will
implement same XML conversion mechanism as present in SahanaPHP so
that it is totally compatible with each other. Similarly importing
feature will also be implemented where XML will be parsed and data
will be added in database. I will closely follow all conventions
followed in SahanaPHP so that if a programmer with experience on
SahanaPHP starts developing on SahanaPy, he feels familiarity with
the system.
An
important point of this system is that this can be embedded in a
programmatic system and data can be imported and exported
automatically. As importing and exporting is completely based on HTTP
GET/POST requests, this can be embedded in automatic system, as I
will do.
2.
Sync Pools:
After
implementing manual synching, I will expand this module in both
versions of Sahana and will introduce “Sync Pool” in both
types of servers. As shown in the figure, Sync pool defines the
relation with that instance of Sahana has with other instances of
Sahana.
What
is sync pool?
Sync
pool can be basically understood as a table. A user (say admin) of a
system can add all those pools which he/she wants to join. He also
checks those types of data which he wants to import from that
particular pool. He also enters a time lap after which he wants to
look for new data. For simplicity, consider there is only one pool
which he can join. When he joins that pool, the system will raise a
flag in the network that server is in that pool, moreover, system
will also look for all those machines with that flag. When found,
system will fetch the type of data which he has checked. Software
will repeat the process after each said time.
Sync
pool will also give choice to add IP address / URI of the server in
case if the user wants to override automatic server searching
process.
A
practical use case: NGO wanting to sync all instances of Sahana.
There
is an NGO which has deployed many instances of Sahana, some run on
Python, other run PHP and NGO wants that all of its Sahana servers
must sync. In that case, the admin of NGO will instruct admins of all
instances of Shana that they must join a pool called "abc NGO".
When everyone (including that admin of NGO) joins the pool, checking
all option for data import, it will result in complete
synchronization between the all instances of that NGO. If the admin
wants that it should be one way synchronization, i.e. all data must
come to his main server and no data should be sent to field servers
(as this is not required in some cases), he can ask admins of Sahana
instances to uncheck all data import option and checks all options at
his main server, this will result in all data coming towards his main
server only.
Please
note that once you join a pool, you expose you data for importing at
other machines of the same pool.
How
will this be implemented?
The
whole system is based on Zero Configuration. Sahana community has
already worked on it. Zero Configuration automates the process of
finding machines which offers particular service.
Please
note the point that for this system to work, it has to continuously
expose services to the network, this can only be achieved if we have
software running continuously. So, it cannot be implemented as a
website, though we can append its executable in the executables of
server to make its execution apparent (I do not promise if I will do
this as my concentrations will not be on this part)
An
example can show how it works.
Suppose
we have multiple instance of Sahana where each instance has joined a
pool called “abc NGO”, checking all data type to be
imported after x hours. The software which now runs as a daemon will
interact with the network in two ways.
a:
It will expose service with the name of “abc NGO” to the
network.
b:
It will continuously look to servers which have exposed service with
the name “abc NGO”, for all those servers which expose
this service, it will fetch checked type of data (as described in
sync pool) using manual synchronization module not this software. As
I told earlier, you can fetch data using HTTP requests.
One
of the most important hatches in network communication is data
unavailability, server downtimes etc, therefore a log will be
maintained logging all data communication. The current data
synchronization module in SahanaPHP provides sync history that will
also be implemented in SahanaPy. As the system will use same module
for seamless data synchronization, therefore it will automatically
list past data synchronizations.
Documentation
is essential part of a software specially FOSS. A standard
documentation will be done with the code.
Future
Options - Identify some aspects of the project that may not be within
the scope of this submission, but could form the basis for future
work that would build upon the outcomes of your project.
The
implementation will be generic and expandable. Potential future
buildups include:
In
case Zero Configuration doesnt seem to meet the challenges (as feared
by someone on the mailing list), it can be plugged off as it will be
implemented as a 'plug-in' to the system and new codebase can be
introduced.
This
project will create the basic framework for inter server
communication, in future if the need for exchanging other data
between servers is required, that can be implemented on its
infrastructure. It can provide API for the system (SahanaPHP and
ShahaPy) to communicate with remote servers.
For
much larger system, exchanging large XML files can be impractical;
therefore, binary diffs can be introduced in the present
architecture.
Relevant
Experience - Please list all experience you have that is directly
relevant to the proposed project, and how they would help you deliver
the project. If you have contributed to the Sahana project
previously, please clearly outline your contributions.
I
have deep knowledge and expertise with PHP, Python, Linux, MVC. This
project basically requires Python, web2py, PHP, web development and
basic networking understanding. I have extensively coded in Python,
PHP, and made many websites. I have used MVC mode of web development
in JSP. So, I believe I am completely equipped with the knowledge
required to complete this project.
Work
already undertaken - What research have you undertaken in this area
in advance? (These can just be bullet points and are not required to
follow the SMART methodology)
I
have gone through web2py as I haven’t previously worked on it.
I
used python implantation of Zero Configuration to test if it works,
it worked across my router.
First trimester (20
April - 22 May) - identify the SMART goals you have for the
community bonding period. Most of these are likely to revolve around
further scoping of the project with the community, engaging with the
community, and updating and finalizing the project plan.
(I
have already discussed my idea on sahana-dev, but it definitely needs
further development)
Due
Data SMART Goal Measure
27
April Understanding of XML conventions / protocol used for XML
conversion write-up describing step by step method used for
conversion to XML
3
May Understanding of present work done by community for ZeroConfig
a write-up describing present ZeroConfig status in the project and
step by step description that how it is going to be used
10
May updating the proposal for last time with feedback from community
Confirmation email from mentor in support of all changes
22
May discussing my whole implementation plan with community, taking
their notes, giving final touch to project workflow a
technical write-up with step by step description on how the coding
will be done, confirmation email from mentor
Second trimester
(23 May - 6 July) - identify the draft SMART goals you have for the
first half of the project. These will be used to assess project
process and form the basis for the mid-term evaluation.
Due
Data SMART Goal Measure
8
June import part data of synchronization module completed demo
of import part
15
June beta version web2py module for manual data
synchronization a working (though buggy) and complete demo of
manual synchronization module for SahanaPy
6
July manual synchronization module completed. Demo
final version of web2py synchronization module
Third trimester (7
July - 10 August) - identify the draft SMART goals you have for the
second half of the project. These will be used to assess the whole
project and in conjunction with the mid-term goals, form the basis
for the final evaluation.
Due
Data SMART Goal Measure
11
July sync pool implementation in SahanaPHP without the software
Demo of working system
25
July sync pool implementation in SahanaPy without the software
Demo of working system
5
August beta of complete software Demo
10
August Final version/ Bug free and totally integrated Final
Demo, Confirmation from mentor
Monday, February 16, 2009
Aitheistism or Monotheism: What science says
Professing to be wise, they became fools . . .. "
"Let me explain the problem science has with God." ...The atheist professor of philosophy at Oxford University pauses before his class and then asks one of his new students to stand.
" So you believe in God?"
"Absolutely."
" Is God good?"
"Sure! God's good."
"Is God all-powerful? Can God do anything?"
"Yes."
"Are you good or evil?"
"The Koran says I'm evil."
The professor grins knowingly. "Ahh! THE KORAN!" He considers for a moment. "Here's one for you. Let's say there's a sick person over here and you can cure him. You can do it. Would you help them?
"Would you try?"
"Yes sir, I would."
"So you're good...!"
"I wouldn't say that
." "Why not say that? You would help a sick and maimed person if you could... in fact most of us would if we could... God doesn't.
[No answer.]
How is this God good? Hmmm? Can you answer that one?"
[No answer]
The elderly man is sympathetic.
"No, you can't, can you?" He takes a sip of water from a glass on his desk to give the student time to relax. In philosophy, you have to go easy with the new ones.
"Let's start again, young fella." "Is God good?"
"Err... Yes."
"Is Satan good?"
"No."
"Where does Satan come from?" The student falters.
"From... God..."
"That's right. God made Satan, didn't he?"
The elderly man runs his bony fingers through his thinning hair and turns to the smirking, student audience.
"I think we're going to have a lot of fun this semester, ladies and gentlemen." He turns back to the Muslim.
"Tell me, son. Is there evil in this world?"
"Yes, sir."
"Evil's everywhere, isn't it? Did God make everything?"
"Yes."
"Who created evil?
[No answer]
"Is there sickness in this world? Immorality? Hatred? Ugliness? All the terrible things - do they exist in this world? "
The student squirms on his feet. "Yes."
"Who created them? "
[No answer]
The professor suddenly shouts at his student.
"WHO CREATED THEM? TELL ME, PLEASE! "The professor closes in for the kill and climbs into the Muslim's face. In a still small voice: "God created all evil, didn't He, son?"
[No answer]
The student tries to hold the steady, experienced gaze and fails. Suddenly the lecturer breaks away to pace the front of the classroom like an aging panther. The class is mesmerized.
"Tell me," he continues, "How is it that this God is Good if He created all evil throughout all time?" The professor swishes his arms around to encompass the wickedness of the world. "All the hatred, the brutality, all the pain, all the torture, all the death and ugliness and all the suffering created by this good God is all over the world, isn't it, young man?"
[No answer]
"Don't you see it all over the place? Huh?" Pause. "Don't you?" The professor leans into the student's face again and whispers, "Is God Good?"
[No answer]
"Do you believe in God, son?"
The student's voice betrays him and cracks. "Yes, professor. I do."
The old man shakes his head sadly. "Science says you have five senses you use to identify and observe the world around you. Have you? "
"No, sir. I've never seen Him."
"Then tell us if you've ever heard your God?"
"No, sir. I have not."
"Have you ever felt your God, tasted your God or smelt your God...in fact, do you have any sensory perception of your God whatsoever?"
No answer
"Answer me, please."
"No, sir, I'm afraid I haven't."
"You're AFRAID... you haven't?"
"No, sir."
"Yet you still believe in him?"
"...Yes..."
"That takes FAITH!" The professor smiles sagely at the underling.
"According to the rules of empirical, testable, demonstrable protocol science says your God doesn't exist. What do you say to that, son? Where is your God now?"
The student doesn't answer
"Sit down, please."
The Muslim sits...Defeated.
Another Muslim raises his hand.
"Professor, may I address the class?"
The professor turns and smiles. "Ah, another Muslim in the vanguard! Come, come, young man. Speak some proper wisdom to the gathering."
The Muslim looks around the room. "Some interesting points you are making, sir. Now I've got a question for you. Is there such thing as heat?"
"Yes," the professor replies. "There's heat."
"Is there such a thing as cold?"
"Yes, son, there's cold too."
"No, sir, there isn't."
The professor's grin freezes. The room suddenly goes very cold. The second Muslim continues. "You can have lots of heat, even more heat, super-heat, mega-heat, white heat, a little heat or no heat but we don't have anything called 'cold'. We can hit 458 degrees below zero, which is no heat, but we can't go any further after that.
"There is no such thing as cold, otherwise we would be able to go colder than 458. You see, sir, cold is only a word we use to describe the absence of heat. We cannot measure cold. Heat we can measure in thermal units because heat is energy. Cold is not the opposite of heat, sir, just the absence of it."
Silence. A pin drops somewhere in the classroom.
"Is there such a thing as darkness, professor?"
"That's a dumb question, son. What is night if it isn't darkness?
What are you getting at...?"
So you say there is such a thing as darkness?"
"Yes..."
"You're wrong again, sir. Darkness is not something; it is the absence of something. You can have low light, normal light, bright light, flashing light but if you have no light constantly you have nothing and it's called darkness, isn't it? That's the meaning we use to define the word. In reality, Darkness isn't. If it were, you would be able to make darkness darker and give me a jar of it. Can you...give me a jar of darker darkness, professor?"
Despite himself, the professor smiles at the young effrontery before him.
This will indeed be a good semester.
"Would you mind telling us what your point is, young man?"
"Yes, professor. My point is, your philosophical premise is flawed to start with and so your conclusion must be in error...."
The professor goes toxic." Flawed...? How dare you...!""
"Sir, may I explain what I mean?" The class is all ears.
"Explain... oh, explain..." The professor makes an admirable effort to regain control. Suddenly he is affability itself. He waves his hand to silence the class, for the student to continue.
"You are working on the premise of duality," the Muslim explains.
"That for example there is life and then there's death; a good God and a bad God. You are viewing the concept of God as something finite, something we can measure. Sir, science cannot even explain a thought. It uses electricity and magnetism but has never seen, much less fully understood them. To view death as the opposite of life is to be ignorant of the fact that death cannot exist as a substantive thing. Death is not the opposite of life, merely the absence of it."
The young man holds up a newspaper he takes from the desk of a neighbor who has been reading it. "Here is one of the most disgusting tabloids this country hosts, professor.
Is there such a thing as immorality?"
"Of course there is, now look..."
"Wrong again, sir. You see, Immorality is merely the absence of morality.
Is there such thing as injustice? No. Injustice is the absence of justice.
Is there such a thing as evil?" The Muslim pauses... "Isn't evil the absence of good?"
The professor's face has turned an alarming color. He is so angry he is temporarily speechless.
The Muslim continues. "If there is evil in the world, professor, and we all agree there is, then God, if he exists, must be accomplishing a work through the agency of evil. What is that work, God is accomplishing?
The Koran tells us it is to see if each one of us will, of our own free will, choose good over evil."
The professor bridles. "As a philosophical scientist, I don't view this matter as having anything to do with any choice; as a realist, I absolutely do not recognize the concept of God or any other theological factor as being part of the world equation because God is not observable."
"I would have thought that the absence of God's moral code in this world is probably one of the most observable phenomena going," the Muslim replies.
"Newspapers make billions of dollars reporting it every week! Tell me, professor. Do you teach your students that they evolved from a monkey?"
"If you are referring to the natural evolutionary process, young man, yes, of course I do."
"Have you ever observed evolution with your own eyes, sir?" The professor makes a sucking sound with his teeth and gives his student a silent, stony stare.
"Professor. Since no one has ever observed the process of evolution at work and cannot even prove that this process is an on-going endeavor, are you not teaching your opinion, sir? Are you now not a scientist, but a priest?"
"I'll overlook your impudence in the light of our philosophical discussion. Now, have you quite finished?" the professor hisses.
"So you don't accept God's moral code to do what is righteous?"
"I believe in what is - that's science!"
"Ahh! SCIENCE!" the student's face splits into a grin.
"Sir, you rightly state that science is the study of observed phenomena. Science too is a premise which is flawed...
"SCIENCE IS FLAWED..?" the professor splutters. The class is in uproar. The Muslim remains standing until the commotion has subsided.
"To continue the point you were making earlier to the other student, May I give you an example of what I mean?"
The professor wisely keeps silent. The Muslim looks around the room. "Is there anyone in the class who has ever seen the professor's brain?" The class breaks out in laughter. The Muslim points towards his elderly, crumbling tutor." Is there anyone here who has ever heard the professor's brain... felt the professor's brain, touched or smelt the professor's brain?" No one appears to have done so. The Muslim shakes his head sadly.
"It appears no-one here has had any sensory perception of the professor's brain whatsoever. Well, according to the rules of empirical, stable, demonstrable protocol, science, I DECLARE that this professor has no brain." The class is in chaos. The Muslim sits...
Because that is what a chair is for!!
Sunday, February 1, 2009
Blog Archive
-
►
2007
(34)
-
►
November
(18)
- The Emergency Times
- Most dangerous country of the World
- I was dead
- Emergency Times No. 6
- 20 Ex-Generals Ready to Join Fight for Democracy
- Iqbal Day --- anti-Martial Law protest
- The Emergency Times - Issue 5
- "Proud of you"
- Student risen in unversities across Pakistan
- Changes in Army Act are ridiculus
- Media flashing at LUMS anti-martial law drive
- LUMS stages biggest anti-martial law demostration ...
- LUMS protest noticed: CNN to local media
- Karachi Stock Exchange Suffers biggest Downfall in...
- Country-wide Anti marshal-law protets gear up
- Another Martial Law!! this guy is freak
- Imran Khan in LUMS on the eve of Martial Law
- Text of emergency proclamation (Source dawn.com)
-
►
November
(18)
About Me
My Associations
Volunteer Internet Environment Watch (VIEW)
(which is no more volunteer based)
Sahana - Disaster Management System
Sahana is my Google Summer of Code Project (2009)

