Monday, September 7, 2009

eSpace makes it into Rails Magazine

aking their biggest steps since they started in 2000, eSpace is taking steady steps into the community of Rails, proving its leadership in Ruby on rails solutions in Egypt. Check out the full article on Rails Magazine



Here is a couple of pictures from the event, the first one shows eSpace's CTO, Mohamad Ali with Matz. The second picture of Ali giving a presentation about Neverblock, a ruby solution for concurrent operations, developed by eSpace. eSpace is using it currently in many production servers, such as Alsaha


Sunday, July 26, 2009

Recovering MySQL root password

Have you ever dealt with different Mysql Installations on different machines?
Have you ever mixed up root passwords of different installations?

I recently had that happened to me, I decided to look further into it and find a good way to do a password reset for my root account.

Here is what we will do:

  1. Stop the mysql daemon.

  2. Start mysql with "--skip-grant-table" option.

  3. login with your root account with no password.

  4. update the mysql.users table with your new password.

  5. restart the mysql default daemon.


Step1: stop the running mysql daemon
/etc/init.d/mysql stop

Output:
* Stopping MySQL database server mysqld  [ OK ]

Note: Make sure it is stopped with the following command
ps aux | grep mysql

You should see only one entry for the grep command you just typed.

Step2: we start mysql with "--skip-grant-table" option.
mysqld_safe --skip-grant-table

You should find output similar when you hit
ps aux | grep mysql7090 pts/1    S      0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-table7129 pts/1    Sl     0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock --skip-grant-table7131 pts/1    S      0:00 logger -p daemon.err -t mysqld_safe -i -t mysqld7246 pts/2    S+     0:00 grep --color=auto mysql

You should login successfully without any password.
mysql -uroot

Step4: change your root password
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit

/etc/init.d/mysql stop/etc/init.d/mysql start

You should be able to login normally with your new password.
Monday, April 20, 2009

Changing your home directory to a new Drive on Ubuntu

I recently was trying to install Windows with my Ubuntu on my machine. I ended up moving my /home partition to another extended one :).

Windows Vista can't be installed on an extended partition (or at least that is what it told me), so i had to make a new primary partition for it. Since I'm using 3 primary partitions for my linux (boot, root and home) plus the extended partition area. The total primary partition (and maximum you can have) is 4 primary partitions. I had to relocate one of my Linux partitions to an extended one. Either i move my boot partition, or the home partition. home was my choice so i did the following.

First you have to make a new extended partition for your home. I choose to try the reiserfs as i read it has some performance advantage over ext3. let's call it /dev/sda5.

Next, you should mount it and copy all your /home data to your new partition.

sudo mkdir /media/home_new
sudo mount -t ext3 /dev/sda6 /media/home_new

replace "sda6" with your correct drive file

Next copy your files:
Since your "/home" directory will have soft links, hard links and nested directories, normal copy "cp" will not do the job. We can use a command similar to the one in the Debian archiving directory

find . -depth -print0 | cpio --null --sparse -pvd /media/home_new

After copying the data you have to edit "/etc/fstab" to make sure your "/home" is pointing to your new partition. You may find some "UUID"s instead of "/dev/..." just replace your UUID with your new drive path "/dev/sda6" or whatever it is.
/dev/sda6  /home reiserfs relatime  0 2

I just replaced the drive file and the file system as i changed both of them. It is best to keep the rest on their default settings.

Now Restart your machine and everything should work fine.You can even create a new primary partition for your windows installation now.
Thursday, September 25, 2008

Calling javascript from ActiveX component.

Recently I was trying to call javascript functions in a web page from an embeded activex component i'm working on (The same way a flex developer do using ExternalInterface).

Problems facing this kind of action:


The problem in MFC is that life is not easy like Flex in this specific point. You have to deal with alot of COM interfaces to get what you want. So my problem was as follows.

  1. I should get a reference to the window that the ActiveX control is embeded in (in my case, it will be an IE tab).

  2. Try to get an interface from this window to an html container to be able to access html and javascript.

  3. find the javascript function you want to call.

  4. formulate the parameters in the way that suits the Interface.

    1. Starting a normal ActiveX control application using the app wizzard, leaving all the default settings.

    2. in the ActiveXCtrl class added a CComPtr which i will be using to access the javascript functions inside the web page.

    3. Added a new method I called it FindMainWindow() and called it in the OnDraw()method.

    4. the code of FindMainWindow()Is as follows.
      void FindMainWindow()
      {
      LPOLECLIENTSITE lpClientSite = NULL;
      lpClientSite = GetClientSite();
      CComPtr<IServiceProvider> serviceProvider(0);
      CComPtr<IWebBrowserApp> webBrowserApp(0);
      CComPtr<IWebBrowser2> webBrowser(0);
      CComPtr<IDispatch> dispatch(0);
      if(SUCCEEDED(lpClientSite->QueryInterface(IID_IServiceProvider,(void**)&serviceProvider))) {
      }
      if(SUCCEEDED(serviceProvider->QueryService(IID_IWebBrowserApp,IID_IWebBrowserApp,(void**)&webBrowserApp)))
      { }
      if(SUCCEEDED(webBrowserApp->QueryInterface(IID_IWebBrowser2,(void**)&webBrowser)))
      {
      webBrowser->get_Document(&dispatch);
      }
      if(SUCCEEDED(dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&htmlDoc)))
      {
      LOG(_T("Found Html Document:"));
      }
      }

      As you can see here, I needed to get first an IServiceProvider interface from theIOLEClientSite i got by calling GetClientSite().
      The following link in the msdn documentation says in the remarks section that The IWebBrowser2 interface derives from IDispatch indirectly. IWebBrowser2 derives from IWebBrowserApp, which in turn derives from IWebBrowser, which finally derives from IDispatch. So i had to get an IWebBrowserApp interface then IWebBrowser2. Finally getting an IDispatch interface to get the IHTMLDocumtne2 from it.

    5. Here we start to call a javascript methods within the IHTMLDocument2 interface we have got earlier. we call get_script(IDispatch*) to get the script object. The following code demonstrate how to get the id of a given javascript function name, formulating the parameters and invoking the function.
      CComPtr spScript;
      if(!GetJScript(spScript))
      {
      return false;
      }
      CComBSTR bstrMember(function);
      DISPID dispid = NULL;
      HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,LOCALE_SYSTEM_DEFAULT,&dispid);

      if(FAILED(hr))
      {
      return false;
      }

      CStringArray paramArray;
      const int arraySize = paramArray.GetSize();
      DISPPARAMS dispparams;
      memset(&dispparams, 0, sizeof dispparams);
      dispparams.cArgs = arraySize;
      dispparams.rgvarg = new VARIANT[dispparams.cArgs];

      for( int i = 0; i < arraySize; i++)
      {
      CComBSTR bstr = paramArray.GetAt(arraySize - 1 - i); // back reading
      bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
      dispparams.rgvarg[i].vt = VT_BSTR;
      }
      dispparams.cNamedArgs = 0;
      EXCEPINFO excepInfo;
      memset(&excepInfo, 0, sizeof excepInfo);
      CComVariant vaResult;
      UINT nArgErr = (UINT)-1; // initialize to invalid arg

      hr = spScript->Invoke(dispid,IID_NULL,0,DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);
      if(FAILED(hr))
      {
      return false;
      }
      *pVarResult = vaResult;
      return true;




  5. Finally call the javascript and cross fingers!

    Solution:


    Here is what i succeeded in after 5 hours of searching and reading and debugging code.

    I have simplified this example as it was a testing to show that javascript is called successfully.
    The detailed example on calling javascript from IHTMLDocument2 can be found in this link
Wednesday, June 4, 2008

Introducing Goosh (Google Shell)

Have you ever wondered, when can i search the web using command line?
Are you a command line geek?
Would you like to get the power of command line and the essence of web.

I felt all that when i opened goosh.org.
When you open the site, you will find a simple white screen with some welcome message like what you see if you have been using a Nix shell before.

just type help and press enter to see what you can do with this shell.

One of the amazing things i have tried is the translate command.
Here is a screenshot of the result for translating "I'm amr and i like to talk" from english to arabic


Totally amazing? Just watch out for the other abilities as well. and share your feedbacks about it and if there is any other amazing commands you did on it.

I will try to read the javascript of the page and share hints.

Happy command line searching
Friday, May 30, 2008

Firefox 3 to score a Guinness World Record

An amazing idea is to aim at scoring a world record for the most downloaded software in 24 hours. Firefox team is spreading its popularity by this announcement as most of Firefox users will talk about it, more users will be interested in trying Firefox if they were not using it and Firefox will gain more popularity.

I have tried Firefox beta 1 and it was very inspiring. But as a developer, I needed more variety of add ons and i couldn't find some addons support for it like firebug and web developer. So i switched to Firefox 2 and waiting for the release of the amazing Firefox 3.

I hope they break the record
Saturday, May 24, 2008

A word about eventmachine gem for Rails

I was working recently in a project that required special purpose server to be implemented from scratch. so i got down to business and started coding. But instead of reinventing the wheel, I started the implementation using the event machine gem for Ruby On Rails . After finishing the coding and basic testing, I got an unexpected problem. The server Always crash!!

First I tried to look back into my code, may be the problem is there. I have tried to repeat a certain request several times and log the server results. Some requests are served and some are not, then the server just stop responding. When I shut it down, It seems to be buffering the rest of the requests. So what happens is that it sends the rest of the requests and then terminate.

The solution to my problem was very simple, Switch OS!!!!!! What I did was installing the Rails environment and deploying my project on Ubuntu machine, then testing with the same sequence. It didn't crash. I even made my stress testing even more aggressive by initiating a request loop for around 10,000,000 requests from two different machines each and the server still RESPONDS!

I think you already have guessed what platform i was using for development. It was WINDOWS of course.

Viva Microsoft !!!
Tuesday, April 29, 2008

A talk about Gamunity

I've been away a little bit in the past few months as i joined the military. Military service is nice, but there is much time wasted in vain.

Anyway. I'm here to talk about something else. Something I hope it will be a great revolution in web based applications. It's called Gamunity.

Gamunity is our next product that will be introduced in the upcoming months. It will have alot of support from many platforms.

Watch my blog for more information about Gamunity and an introduction about it soon.
Tuesday, July 24, 2007

Getting into business

Finally, I've decided to blog!. After graduation, I have much time now to do other activities other than work. Blogging is very difficult at first, but once you get used to it, you won't stop. Simply because blogging change the way a person express his ideas and Improve his writing style.

I'm starting my own business these days with two other enthusiastic friends and colleges. We are calling our company (LogN). Why? As a symbol of efficiency. Mainly our work will be focused firstly on developing web 2.0 products. We're working right now on a prototype of our new product. If the prototype was good (As i hope), we will get funded from a local company here. I won't mention its name now. but maybe later i will.

We hope to finish the product before March 2008. That's before we start our military service after college.

I hope our product come to the light soon, and with the quality i hope.