Friday, February 5, 2016

Egyptian durgs index

A searchable, smart phone compatible index for drugs and pharmaceutical products in Egypt.

http://egyptiandrugs.ml



Tuesday, December 28, 2010

Arduino + SD/MMC, the easiest way

Interfacing SD/MMC cards to arduino is a must, if you didn't need it soon, you will do later. Myself being new in arduino's world i had to google for an implementation. i came across this post where i got a simple schematic to interface the SD/MMC cards and few codes reading 12 pages of furstrated people who got no luck , i used "sd_raw", ufat and another one more code i found in arduino playground and none of them worked for me, I used the schematic on arduino forum with same resistors ratios but not the values, the schematic is composed voltage deviders to supply the SD card with no more than 3.3v out of the 5 volts the arduino is using.

For few days i didn't got further away from the other flocks (in the forum), till i came across SDfatlib from which worked just fine from the first trial on my curcuit.
The great thing about it is that it supports FAT16 & FATE32 and supports read/write in raw format. the liberary is also stocked with a large number of sketches which contains pretty much everything you want to do with SD card.


Schematic was taken from here.

Thursday, April 2, 2009

Monty Hall problem, a logic seems against the common sense

Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?

I have encountered this question in IQ test at facebook and I answered as "it doesn't make a difference to switch or not as i would have a 50% probability to win". I was surprised when i was told that i'm wrong, then i discovered that is a big argument for a problem presented by the game show "Let's make a deal"

i have read explanations about it but without much concentration, i was not convinced anyway, so i wrote a simple quick and dirty simulation in php which results around 66% probability to win, then i had to take a deep breath and said "Well, let's really think"

This is my sim code written in php

<?
function prove_montyhall_or_break_it(){
srand((float) microtime() * 10000000);
$doors = array(1=>"G", 2=>"G", 3=>"G");
$num = array(1,2,3);
$x = array_rand($num)+1;
//setting car's door
$doors[$x]='C';

//Think of one door
$y = array_rand($num)+1;
$original_choice=$doors[$y];
unset ($doors[$y]);

//find the goat door and remove it so the remaining door will be the one that you will to switch to if u want

$goatdoorkey = array_search('G', $doors);
unset ($doors[$goatdoorkey]);


if (in_array("C", $doors)) {
return true;
}else{
return false;
}
}
$trials= 1000000;
$wins=0;
$losses=0;

for ($i = 0; $i < $trials; ++$i) { if (prove_montyhall_or_break_it()){ ++$wins; }else{ ++$losses; } } echo "out of $trials trial: <br > wins are $wins <br > losses are $losses"; ?>


After a while of thinking i found it simple. It is the same thing like selecting two doors from three, and the host will open the door which has the goat behind out of these two. Selecting two will give probability of 2/3 to win , removing the non winner door out of the selected two will not affect your probability to win. So switching in the original game equals to choosing two doors.

C for car and G for Goat

Door A > G
Door B > G
Door C > C

Selecting "door A" will enforce the host to open "B" > switching wins
Selecting "door B" will enforce the host to open "A" > switching wins
Selecting "door C" will make the host to open either "A" or "B" > switching fails

Switching will give you 2 chances to win out of 3. this happens only if the host knows where is the car. If the host doesn't know, your probability to win will be 1/2. So you will always have to switch unless you want to win a goat.

Thursday, September 11, 2008

Arabic subtitle, how to make it work under Ubuntu.

I had been using dual boot of Microsoft windows and linux for a long time as I couldn't completely migrate to Linux because of immature Arabic support. booting to windows to watch subtitled movies was not uncommon thing I was doing.
Now with complete linux arabic subtitle support , I rarely boot to windows only to play MS flight simulator.
Most of arabic subtitles files are written in windows-1256 character set encoding and very scarse of them are written UTF-8 encoding.

Totem:

Ubuntu comes with Totem media player that already support arabic subtitles out of the box
just select Edit > Preferences > General > Encoding > Arabic (WINDOWS-1256)
and make sure to select a font that support arabic, mine is set to "Nimbus sans L". Also make sure that the .sub or .srt file has the same file name as the media files without extensionp; ie. foo.srt for foo.avi .

Mplayer:

Mplayer and VLC require fribidi liberary to support arabic, but the stable version is not mature enough to support arabic joining, that why you will get unjoined arabic charcters on subtitles, so you have to install version 2 of fribidi from CVS repository and compile it yourself or if you are using ubuntu or debian , you can download and install a .deb package from here or zshare mirror here.
Then edit $HOME/.mplayer/gui.conf with your favourite text editor and append the following line at the end of the file

sub_cp = "cp1256"

Now subtitles should properly work, just make sure the video file foo.avi has foo.sub, or foo.srt subtitle file in the same directory.

VLC

For VLC you have to install fribidi version 2 as mentioned before and edit $HOME/.vlc/vlcrc with your favourite text editor, and find the following line and comment it

subsdec-autodetect-utf8=1

and change the line that begins with "subsdec-encoding" to

subsdec-encoding=windows-1256

save your file and fireup your vlc opening a subtitled media now you should have a working subtitle with arabic joining.
I have VLC 0.8.6e Janus (wxWidgets interface) installed from ubuntu hardy repository and it looks that it suffer from a bug preventing it from loading subtitles having charcters other than letters and numbers in its location and its filename, for example a file location includes something like this "Chaos.Theory[2007]DvDrip[cut].AC3-aXXo" will not work, just rename the video and subtitles filenames and directory names if needed.

P.S.

A good thing about fridbidi version 2 is that it will fix arabic shaping/joining problems for other applications that use it like amsn.

Install the arabic fonts package ttf-arabeyes from repository by

sudo apt-get install ttf-arabeyes

Friday, August 1, 2008

arptables, and ARP poisoning(Netcut, Switchspoofer, ..)

Netcut , WinARPspoofer, Switchsniffer,WinARPattacker , and other ARP poisoners are becoming popular now with the growing number of the free wifi hotspots and shared broadband connections, and are being used either for taking advatage of the whole network internet speed , or sniffing sensitive informations, emails, chat conversations, .. etc
i tried many ways to stop attacks on my linux like what mentioned here but i failed to stop the attacks
after several trials and forensics, I found that arptables is the solution
i installed arptables package

$sudo apt-get install arptables


the i have added these lines to my firewall script
provided that "192.168.1.1" is the gateway IP and "00:1D:0F:A9:F0:45" is the mac address of the gateway

#arptables -P INPUT DROP
#arptables -P OUTPUT DROP
#arptables -A INPUT -s 192.168.1.1 --source-mac 00:1D:0F:A9:F0:45 -j ACCEPT
#arptables -A OUTPUT -d 192.168.1.1 --destination-mac 00:1D:0F:A9:F0:45 -j ACCEPT

#arp -s
192.168.1.1 00:1D:0F:A9:F0:45


First line to set the policy of INPUT chain to DROP.
Second line to set the policy of OUTPUT chain to DROP.
Third line to only ACCEPT connections from trusted gateway.
Forth line to send replies only to the trusted hosts.
Fifth line to add static entry into the ARP table to link your trusted host to its own MAC.
What i liked in this this solution that your box will only be visible to the trusted hosts in your network, even when the attacker try to scan the network by anykind of software. A good combination between arptables and iptables makes you safe in untrusted switched networks.

Saturday, July 26, 2008

Voice chat under linux

I have been searching for a voice chat solution under Linux to contact my family while I'm abroad , cause i am doing almost all my work under Linux and i hate to boot xp for only chatting, here is my experience

Msn:
- ofcourse voice chat will not work under linux

Yahoo messenger:
- i couldn't make it work with wine

Google talk
- it is my favorite voice chat client as it have good audio quality but unfortunately didn't work at all with wine or even crossover
- I couldn't setup Landell, and i didn't hear any success stories about installing it
- i could install Empathy successfully and it worked with me , voice chat worked too , tested the voice quality once, it was inferior to the original software, but it was usable

Skype
i had installed skype before on ubuntu dapper and ubuntu edgy but it didn't work properly , i could only make one call per session, and i had to restart the application for it to work again, there was a fix for that But i have installed skype 2.0.0.8 under ubuntu 8.04 (Hardy)


VOIP (SIP)
It worked from the beginning, used xten-xlite as a client on both sides, worked fine with the SIP gizmo service (sipphone), good audio quality, rare disconnections, minimal delay


Conclusion
if you are a Linux fan try to avoid properiatory solutions tailored mainly for windows, try to use a standard protocol like SIP you will find it well supported by not only Linux community but also other platforms and hardware manufacturers.

Changing hostname in linux

to change the hostname:
Method 1:

from terminal run this command

$sudo echo "your_new_hostname" > /etc/hostname


Method 2"

System > Administration > Network > General (tab)

and change "Host name" value to whatever you want

p.s.
a good tip is to add your new hostname to /etc/hosts

$sudo echo "127.0.0.1 your_new_hostname" >> /etc/hosts


p.s. tested on Ubuntu Hardy 8.04 LTS