/log

life.log()

Archive for the ‘software’ Category

Chm server

without comments

It’s not so fancy but I love it.

For Mac OSX Install chmlib:

sudo ports install chmlib

Now you’ll find the chm_http available and you are ready to serve the documentation.

chm_http –port=8080 –bind=127.0.0.1 file.chm

aaand now browse  http://127.0.0.1:8080 and you should find the file de-compiled and served for you :)

Enjoy.

Written by me

December 30th, 2011 at 7:06 pm

Posted in I code,software

Tagged with , , , ,

Using yield while generating the sum of first 1000 prime numbers

with 2 comments

I like using yield here and I was happy when I knew that scala has yield

def oddNumbers(xlist):
	for item in xlist:
		item += 2
		xlist.append(item)
		yield item

oddNumbers 		= oddNumbers([7])
primeNumbers	= [2, 3, 5, 7]
count			= 3
summation		= 17

for item in oddNumbers:
	isPrime = True
	for otherItem in primeNumbers:
		if item % otherItem == 0 and item != otherItem:
			isPrime = False
	if isPrime:
		primeNumbers.append(item)
		count += 1
		summation += item
	if count == 999:
		break

print summation

Written by me

September 10th, 2011 at 11:20 pm

biggest prime palindrome under 1000.

with 4 comments

I had that problem in CodeEval:

Write a program to determine the biggest prime palindrome under 1000.

And my solution passed i don’t know if they have other levels than pass but it passed anyway..

Here you are:

oddNumbers 		= [2] + range(3, 1000, 2)
primeNumbers	= []
ppNumbers 		=[]
for item in oddNumbers:
	isPrime = True
	for otherItem in oddNumbers:
		if item % otherItem == 0 and item != otherItem:
			isPrime = False
	if isPrime:
		primeNumbers.append(item)

for prime in primeNumbers:
	if prime > 100 and str(prime)[0] == str(prime)[2]:
		ppNumbers.append(prime)

print ppNumbers[-1]

I first created script to get prime numbers then i search to know what exactly a palindrome number is and i tweaked the script to solve it:)

The personal part of the post:
I -lately- figured out that family support is not only important .. it’s incomparable to any other support..

ربنا يخليك ليا يا بابا
سلام

Written by me

August 16th, 2011 at 2:14 pm

Posted in I code,me.status()

Tagged with , , ,

Singleton mySQL database connection using PHP

with 9 comments

السلام عليكم و رحمة الله و بركاته
فيما يلي مثال على الـ Singleton Design Pattern
و هو ما يعطيك الإمكانية في الحصول علي فقط نسخة واحدة من أي مورد تريد إستخدامه .. في هذة الحالة مثلا الإتصال بقاعدة البيانات و ذلك بأن تستخدم الدالة getConnection بدلا من عمل نسخة جديدة من connection كل مرة هتحاول فيها الإتصال بقاعدة البيانات..

Following is a brief example for the singleton design patterns which will enable you from having only one instance of the resource you are controlling .. in this example it’s the mySQL database connection.
Else you will have multiple instances of the same class “connection” each time you want to connect.

define('DB_NAME', "test");
define('DB_USER', "root");
define('DB_PASS', "rootpass");
define('DB_HOST', "localhost");

class Connection{
	private static $connection_;

	private function __construct(){
		$con = mysql_connect(DB_HOST, DB_USER, DB_PASS);
		mysql_select_db(DB_NAME, $con);
		Connection::$connection_ =  $con;
	}

	public static function getConnection(){
		if( !Connection::$connection_ )
			new Connection;
		return Connection::$connection_;
	}

}

$con = Connection::getConnection();
و نسألكم الدعاء بظهر الغيب بالله عليكم :)
في رعاية الله و أمنه

Written by me

June 29th, 2010 at 11:57 am

yield statement .. by example

with 2 comments

السلام عليكم و رحمة الله وبركاته

ده تمرين بسيط علىyield statement

def simpleGenerator( anyList ):
	for item in anyList:
		yield item

myList = ['Ahmed', 'AlSayed', 'AbdulHameed', 'Osama', 'Gamal']

nameGenerator =  simpleGenerator( myList )

for name in myItemsList:
	print name

print myItemsList.next()
print myItemsList.next()
print myItemsList.next()
وده بس عشان البلوج كان عشش فيه العنكبوت ..

Written by me

June 27th, 2010 at 9:45 pm

Posted in I code,software

Tagged with ,

Survival..

without comments

السلام عليكم و رحمة الله وبركاته

Last 2 weeks

I was working last 2 weeks -between Cairo and Mansoura- for tadabborIT, for tadabbor website next release, also I’ve attended the JDC2010 conference and through that week I should have read about 4 reading tasks and should have solved tasks by Design patterns course by my dear mentor Ahmed Soliman, while planning to join GSoC.

Not to mention the courses and websites I’m delaying and canceling ..

And here I’m defining a new busyness level ..

One note before i go: If i survived that stage, I think I’ll be much more stronger than what I used to be, I also believe that It should be a milestone.

Anyway, I believe I can try :)

Written by me

March 13th, 2010 at 3:57 pm

Get Adobe Flash playerPlugin by wpburn.com wordpress themes