Archive for the ‘Uncategorized’ Category
Using yield while generating the sum of first 1000 prime numbers
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
شهر رمضان..
٣سنين ..
٣ سنين عدت .. يا ترى إتنسيت ..!!
طيب لو إتنسيت .. هوا ممكن أنا أنسى .. ؟؟
Singleton mySQL database connection using PHP
السلام عليكم و رحمة الله و بركاته
فيما يلي مثال على الـ Singleton Design Pattern
و هو ما يعطيك الإمكانية في الحصول علي فقط نسخة واحدة من أي مورد تريد إستخدامه .. في هذة الحالة مثلا الإتصال بقاعدة البيانات و ذلك بأن تستخدم الدالة getConnection بدلا من عمل نسخة جديدة من connection كل مرة هتحاول فيها الإتصال بقاعدة البيانات..
فيما يلي مثال على الـ 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();
و نسألكم الدعاء بظهر الغيب بالله عليكم 
في رعاية الله و أمنه
في رعاية الله و أمنه
testing syntax highlighting
testing ..
echo "hello, highlighting .. ";
Shutting my babies down ..
Shutting my babies down .. and now ..
They started ..