tag:blogger.com,1999:blog-14270640724008192582024-02-29T03:45:09.307+02:00Hosam Hammady's blogThis is my personal blog. I write both personal and technical blogs. I write about new ideas and technical stuff that interest me.Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-1427064072400819258.post-4124908278722655532015-07-06T16:30:00.001+02:002015-07-06T16:30:49.539+02:00Install GNU-screen binaries when you don't have root access<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://gnu.org/software/screen/" target="_blank">GNU-screen</a> is very useful when running long commands that survive across SSH sessions. <span class="fullpost"> </span>Sometimes you get access to servers that do not have it installed. <span class="fullpost">Here is how to do it without having root access, without having to install from source. Installing from source may require additional libraries, and you may end up installing many things from source.</span><br /><br />
<span class="fullpost">
<pre>
# download the package for yum-based linux distros (RedHat, Fedora, CentOS, …)
yumdownloader screen
# extract package contents
rpm2cpio screen-X.rpm | cpio -idv
# or for debian based (Debian, Ubuntu, …)
aptitude download screen
# extract package contents
dpkg -x screen-X.deb .
# prepare environment (append to .bashrc to be always available)
export SCREENDIR=$HOME/var/run/screen
export PATH=$HOME/usr/bin:$PATH
# launch screen
screen
</pre>
</span></div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com1tag:blogger.com,1999:blog-1427064072400819258.post-69943817534812485102015-01-21T10:55:00.002+02:002015-01-21T10:55:39.271+02:00The cheatsheet on writing scalable web apps<ol>
<li class="li4"><span class="s1"></span>Scale horizontally (<a href="http://en.wikipedia.org/wiki/Scalability">scale out</a>): Separate system tiers on different environments: database, Solr, memcached, push, web/app servers. Separation helps in scaling up/down tiers individually.</li>
<li class="li4">Use the cloud (<a href="http://en.wikipedia.org/wiki/Platform_as_a_service">Platform as a Service</a>) right away that facilitates scaling out/up/down (<a href="https://cloud.google.com/appengine">Google AppEngine</a>, <a href="https://www.heroku.com">Heroku</a>, <a href="http://aws.amazon.com/elasticbeanstalk/">AWS Beanstalk</a>, …</li>
<li class="li4">Monitor usage on each tier to scale up/down in the correct time (e.g. <a href="http://newrelic.com">NewRelic</a>)</li>
<li class="li4">Use push instead of server polling (<a href="http://pusher.com">Pusher</a>)</li>
<li class="li4">Don’t use filesystems for storage, unless it is a distributed filesystem (<a href="http://aws.amazon.com/s3/">AWS S3</a>)</li>
<li class="li4">Don’t involve your app server in long requests/responses. Slow clients may block your server and cause longer request queues (depends on implementation).<span class="Apple-converted-space"> </span></li>
<ul class="ul1">
<li class="li4">If you want to receive an upload <a href="https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails">get it through S3</a> with some work on the client side.<span class="Apple-converted-space"> </span></li>
<li class="li4">If you want to send a huge response, either stream it using a streaming capability of your app server, or generate it using a background job that stores it finally on S3 and sends the direct link when done through the app using push or through email.</li>
</ul>
<li class="li4">Defer long tasks to background jobs (<a href="https://github.com/resque/resque">Resque</a>, <a href="http://www.rabbitmq.com/tutorials/tutorial-two-python.html">RabbitMQ</a>, Ruby <a href="https://github.com/collectiveidea/delayed_job">delayed jobs</a>, …)</li>
<li class="li4">Don’t clutter your app server memory with language bindings, use <a href="https://thrift.apache.org">Apache Thrift</a> or <a href="https://developers.google.com/protocol-buffers/">Google Protocol Buffers</a> to communicate between different environments</li>
<li class="li4">Use <a href="http://lucene.apache.org/solr/">Apache Solr</a> (Lucene over HTTP) to query large data even if you don’t have full text search, it can be used for scoping and faceting as well (think SQL WHERE and GROUP BY)</li>
<li class="li4">Autoscale your web/app servers depending on traffic. Monitoring shows you traffic metrics and <a href="http://hirefire.io">HireFire</a> will autoscale your heroku dynos</li>
<li class="li4">Use clients-side rendering (<a href="http://www.creativebloq.com/web-design/templating-engines-9134396">Javascript templates</a>) to get rid of the rendering time on the server</li>
<li class="li4">Use caching in different layers (<a href="http://memcached.org">memcached</a>) to be nice on your servers</li>
<li class="li4">Asset hosting, static assets (javascripts, stylesheets, html templates, images, …) have nothing to do with your app servers so host them somewhere else (<a href="http://aws.amazon.com/cloudfront/">CloudFront</a>/S3)</li>
</ol>
Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com19tag:blogger.com,1999:blog-1427064072400819258.post-88899135029094828292014-12-08T12:33:00.000+02:002014-12-10T11:39:52.615+02:00Check your Postgres database catalog integrity effortlessly in seconds<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
Regular database backups is something no one can afford missing. If your database is inconsistent backups won't be produced successfully. A quick search on <a href="https://www.google.com/search?rls=en&q=pg_dump+cannot+schema+oid&ie=UTF-8&oe=UTF-8#rls=en&q=pg_dump+schema+with+oid+does+not+exist">pg_dump schema with oid does not exist</a> reveals a lot are suffering and cannot produce any backups.
<br />
<br /></div>
<div>
Going through the <a href="http://www.postgresql.org/message-id/438C7027.904@aeccom.com" target="_blank">search results</a>, people suggest manually scanning the system catalog tables to identify inconsistencies. This is a tedious process and requires a lot of knowledge about the catalog structure.<br />
<br />
Fortunately, there is an open-source tool called <a href="https://github.com/EnterpriseDB/pg_catcheck" target="_blank">pg_catcheck</a>, which can detect these inconsistencies. However, it requires you to install <a href="http://github.com/postgres/postgres" target="_blank">Postgres</a> from source and build the tool against its source tree, which may be <a href="https://groups.google.com/a/enterprisedb.com/forum/#!topic/pg-catcheck/ufIMq8XTpjs" target="_blank">tricky</a> on some systems. In this blog, I will introduce a cloud-based solution to effortlessly run pg_catcheck, without any compilation, at no extra cost.</div>
<span class="fullpost">
<a href="https://github.com/hammady/cloud_pg_catcheck" target="_blank">Cloud pg_catcheck</a> is a <a href="http://www.heroku.com/" target="_blank">heroku</a> customized fork of the original repo. There are 2 main advantages to use it over the local one:<br />
<br />
</span><br />
<ol style="text-align: left;"><span class="fullpost">
<li>No need to download, compile postgres or pg_catcheck from source.</li>
<li>For postgres servers running on heroku (or any AWS-based servers), super fast running time because it runs on the same infrastructure of the database server, reducing the time to do the check from minutes to several seconds.</li>
</span></ol>
<span class="fullpost">
Fortunately, heroku gives <a href="https://devcenter.heroku.com/articles/usage-and-billing" target="_blank">free 750 dyno hours</a> per month, so you will always do the checks for free, because there are no web dynos running.<br />
<br />
</span><br />
<h2 style="text-align: left;">
<span class="fullpost">
How to use:</span></h2>
<span class="fullpost">
To check your own database, just clone this repo, deploy it to heroku, set database url and finally run the check:<br />
<br />
<code># setup: do this only once</code><br />
<code>git clone https://github.com/hammady/pg_catcheck.git</code><br />
<code>cd pg_catcheck</code><br />
<code>heroku create --buildpack https://github.com/ddollar/heroku-buildpack-multi.git</code><br />
<code>git push heroku master</code><br />
<code><br /></code>
<code># set the database url and run the check</code><br />
<code>heroku config:set DATABASE_URL=postgres://username:password@host:port/databasename</code><br />
<code>heroku run ./check</code><br />
<br />
Before deploying, you need to create an account on heroku, if you don't already have one. </span></div>
Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-63074169762080934542013-05-21T08:59:00.000+02:002013-05-21T08:59:01.685+02:00Remove the stupid onscreen keyboard input from an example banking website<div dir="ltr" style="text-align: left;" trbidi="on">
The onscreen keyboard input is a security feature in many website, especially banking websites. It is only useful if you are accessing your account from a public machine (which is not a good practice anyway). On such computers, a spyware may be monitoring your keyboard strokes and will have access to your typed password. However, on your own computer, if you are vigilant enough, there is no such need for such keyboard.<span class="fullpost"></span><br />
<span class="fullpost">
</span>
<div>
<span class="readmore"><br /></span></div>
<span class="readmore">
<div>
Here are 2 userscripts that will enable the normal keyboard input for QIB banking website on the main and the transaction pages. You will need <a href="https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo" target="_blank">Tampermonkey</a> to get them working on Google Chrome, or <a href="https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/" target="_blank">Greasemonkey</a> for Firefox.</div>
<div>
<br /></div>
<div>
After installing the above browser extensions, just follow the following links and click on "Install" on the very top of the page. Once your browser shows the main and transaction pages, it will automatically enable the password fields so that you can freely type your passwords.</div>
<div>
<br /></div>
<div>
<ol style="text-align: left;">
<li><a href="http://userscripts.org/scripts/show/85137" target="_blank">Enable main page password field</a></li>
<li><a href="http://userscripts.org/scripts/show/168047" target="_blank">Enable transaction page password field</a></li>
</ol>
<div>
The script can be extended to work on any page by looking for read-only fields and enabling them, I will do this later inshaAllah :)</div>
</div>
<div>
<br /></div>
</span></div>
Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com1tag:blogger.com,1999:blog-1427064072400819258.post-74787301887164592382013-04-03T09:44:00.001+02:002015-03-04T13:02:24.497+02:00[Linux/Mac] Always leave your trash occupied, but not full<div dir="ltr" style="text-align: left;" trbidi="on">
Some people have a common "bad" practice of deleting items permanently as seeing the Trash (Recycle Bin for poor Windows users) non-empty provokes them! Rule of thumb: don't ever permanently delete your files, the trash is a great feature, so please use it! You never know when you will need those files again.<br />
<br />
However, by time your trash size will grow up and take a lot of space of your storage. No, I won't ask you to empty it every now and then. The best practice is to only delete files that are older than a specific date, lets say 30 days.<br />
<span class="fullpost"><br /></span>
<span class="fullpost">To be short, this is a little bash script that will calculate the total trash size then deletes those old items and print again the new size:
</span><br />
<span class="fullpost"><br /></span>
<pre><span class="fullpost">victim=~/.Trash
echo Calculating $victim size...
echo $victim size: `du -sh $victim | cut -f1`
echo -n "Emptying $victim items older than 30 days, please be patient..."
find $victim -mtime +30d -exec rm -fr {} \; &> /dev/null
echo Done
echo Current $victim size: `du -sh $victim | cut -f1`
</span></pre>
<span class="fullpost"><div>
<span class="fullpost"><br /></span></div>
You can change the victim to ~/Downloads or whatsoever, you can also change the number of days to weeks or months or whatsoever.
Use it at your own risk :)
For your convenience I have created 2 scripts, <a href="http://hammady.net/scripts/empty-trash-older-than-30d.sh">one for Trash</a>, the <a href="http://hammady.net/scripts/empty-downloads-older-than-30d.sh">other for Downloads</a>. Download them to your home and just
execute them whenever you run out of space.
<pre>
./empty-trash-older-than-30d.sh
./empty-downloads-older-than-30d.sh
</pre>
</span></div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com3tag:blogger.com,1999:blog-1427064072400819258.post-13899286650209564562011-06-02T07:30:00.007+02:002011-06-02T08:14:25.574+02:00الآن يمكنك الكتابة بالعربية على الأندرويد باستخدام لوحة مفاتيح آبل اللاسلكية<div style="text-align: right;direction: rtl; ">لقد كتبت <a href="http://blog.hammady.net/2011/05/android-adding-arabic-layout-for.html">تدوينة</a> الأسبوع الماضي تتحدث عن كيفية إضافة اللغة العربية كلغة ثانية على <a href="http://www.apple.com/keyboard/">لوحة مفاتيح آبل اللاسلكية</a> لاستخدامها على هاتف الأندرويد. ولكني قد كتبتها باللغة الإنجليزية. وبعد مرور أسبوع تقريبا جاءت مبادرة المجلس الأعلى للاتصالات وتكنولوجيا المعلومات بدولة قطر لدعم المحتوى العربي على شبكة المعلومات. بالطبع لم تكن هذه هي المبادرة الأولى فقد نظم المجلس الأعلى مؤتمر كتكوم الذي كانت إحدى محاوره الرئيسية دعم المحتوى العربي على شبكة المعلومات.</div><div style="text-align: right;">وبعد تشجيعهم لي على موقع تويتر فلم أجد بدا من أن هذه التدوينة هي أولى تدوينة لكتابتها باللغة العربية لأنها تخدم لغتي الحبيبة العربية شكلا ومضمونا، وإليكم التدوينة.</div><div style="text-align: right;"><br /></div><div style="text-align: right;">إذا كنت محظوظا بما فيه الكفاية بتملك لوحة مفاتيح لاسلكية - بلوتوث وخاصة لوحة مفاتيح آبل اللاسلكية، إذًا فإنه من الممتع استخدامها للكتابة على هاتف الأندرويد خاصتك لكونها مريحة جدا في الكتابة. ولحسن الحظ أيضا، فهناك عدة تطبيقات على سوق تطبيقات أندرويد تتيح لك ذلك، أذكر منها بالأخص اثنين: <a href="https://market.android.com/search?q=blueinput&so=1&c=apps">BlueInput</a> و <a href="https://market.android.com/details?id=elbrain.bluekeyboard.ime&feature=search_result">BlueKeyboard JP</a>.</div><div style="text-align: right;">هناك أيضا العديد من مقاطع الفيديو التي تشرح كيفية استخدام هذه البرامج منها على سبيل المثال هذا المقطع:</div><div style="text-align: right;"><br /></div><div style="text-align: right;"><div style="text-align: right;"><br /></div><div style="text-align: right;"><object style="height: 390px; width: 640px" width="640" height="390"><embed src="http://www.youtube.com/v/Tg4KJ33VwH8?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="390"></embed></object></div></div><span class="fullpost"><div style="text-align: right;"><br /></div><div style="text-align: right;">ربما لاحظت أن اللغات المدعومة في التطبيق السالف ذكره لا تشمل سوى الإنجليزية والألمانية واليابانية، أي أن العربية غير مدعومة. أما في التطبيق الثاني فالإنجليزية فقط هي المدعومة وحدها. وبما أني أكتب كثيرا على الهاتف بالعربية فكم تمنيت أن أكتب باستخدام لوحة المفاتيح لما وجدته من سهولة استخدامها وبالأخص في المؤتمرات والمحاضرات حين أريد كتابة ملاحظات أو إرسال تغريدات آنية. المهم فقد راسلت مطوري هذه التطبيقات وطلبت منهم إضافة العربية، ولكن أحدهم لم يرد مطلقا والآخر أخبرني أنهم بصدد طرح إصدار جديد من شأنه إضافة لغات جديدة حسب اختيار المستخدم. لم يسعني الانتظار وخصوصا أنهم لم يحددوا موعدا ثابتا.</div><div style="text-align: right;"><br /></div><div style="text-align: right;">بعد البحث في شكبة المعلومات والدراسة السريعة لتصميم وبناء نظام الأندرويد، فقد قررت أن أضف دعم العربية بنفسي. وبالفعل تم بحمد الله مرادي وأنشأت تحديث للأندرويد وهو ما يطلق عليه ROM Update</div><div style="text-align: right;">من شأنه إضافة اللغة العربية كلغة ثانية بحيث تعمل على أي تطبيق للوحة المفاتيح على كل تطبيقات الهاتف. وبما أن هذا التحديث يعدل في نظام التشغيل فيجب أن يكون جهازك مفتوح وهو ما يسمي بالروتنج أو Rooting.</div><div style="text-align: right;"><a href="http://twitter.com/#%21/hammady/status/28760736985522176">هذا</a> دليل جيد جدا للروتنج أنصح بالرجوع إليه إذا لم تكن قد فعلت بعد.</div><div style="text-align: right;"><br /></div><div style="text-align: right;">في الوقت الحالي هذا التحديث مصمم فقط لجهاز جوجل نكسس إس المحمل بنظام تشغيل معدل <a href="http://android.modaco.com/">موداكو</a> أو <a href="http://www.cyanogenmod.com/">سيانوجنمود</a>. ولكن لا يعني هذا أن بقية الأجهزة غير مدعومة وذلك لأني ليس عندي الوقت الكافي لحزم التحديث لجميع الأجهزة المتوفرة. إذا كنت مهتما، فقط اترك تعليق أدناه مع ذكر نوع جهازك ونظام تشغيله المعدل وسيسعدني عمل التحديث لجهازك.</div><div style="text-align: right;"><br /></div><div style="text-align: right;">للتحميل وكيفية التنصيب والاستخدام، راجع <a href="http://blog.hammady.net/2011/05/android-adding-arabic-layout-for.html">التدوينة السابقة</a>.</div><div style="text-align: right;">هذا كل ما أردت كتابته، في انتظار تعليقاتكم ويسعدني مساعدتكم.</div><div style="text-align: right;">والسلام عليكم</div><div style="text-align: right;">حسام</div><div style="text-align: right;"><br /></div></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com2tag:blogger.com,1999:blog-1427064072400819258.post-74694728519082866902011-05-26T21:22:00.016+02:002011-05-26T22:34:02.953+02:00[Android] Adding Arabic Layout for Bluetooth HID KeyboardsIf you are lucky enough to have a bluetooth <a href="http://en.wikipedia.org/wiki/Human_interface_device">HID</a> keyboard, like <a href="http://www.apple.com/keyboard/">Apple Wireless Keyboard</a>, then it would be ultimate fun to use it on your Android phone for convenient editing. Luckily as well, there are couple of Market apps that let you do this. The first is <a href="https://market.android.com/search?q=blueinput&so=1&c=apps">BlueInput</a> and the other is <a href="https://market.android.com/details?id=elbrain.bluekeyboard.ime&feature=search_result">BlueKeyboard JP</a>. There are many tutorials explaining how you use these apps, here is one of them:<br /><iframe src="http://www.youtube.com/embed/Tg4KJ33VwH8" allowfullscreen="" width="560" frameborder="0" height="349"></iframe><br /><span class="fullpost"><br />As you can see, only English, Dutch and Japanese layouts are supported. For the other app, only English is supported. As an Arabic speaker, I wished that I could use my keyboard to write in Arabic. I tried to contact the developer of BlueKeyboard JP but he never answered. He even didn't have much time to publish my comment on his website. I contacted <a href="http://www.teksoftco.com/index.php?section=blueinput">Teksoft</a>, the developers of BlueInput, but all what they have said is that they are gonna add more layouts soon.<br /><br />After some readings in the Android OS architecture, I have developed a ROM update that will add the Arabic layout to <span style="font-weight: bold; font-style: italic;">ANY</span> HID app you are using! Obviously, your device should be rooted.<br />A good guide for rooting Nexus S can be found <a href="http://twitter.com/#%21/hammady/status/28760736985522176">here</a>.<br /><br />As of the moment, the update is available only for Nexus S running either <a href="http://www.cyanogenmod.com/">Cyanogenmod7</a> or <a href="http://android.modaco.com/">MoDaCo</a>. Although, cooking an update for any device is darn easy, but I don't have much time to do this for all and every device on the market. If you are interested, please leave a comment below mentioning your device model and firmware, and I will cook the update for you.<br /><br /><span style="font-size:130%;"><span style="font-weight: bold;">Download (144 KB):</span></span><br /><ul><li><a href="http://hammady.net/arabichid-android/update-arabic-hid-NS-CM7-0.1-signed.zip">Nexus S, Cyanogenmod7</a></li><li><a href="http://hammady.net/arabichid-android/update-arabic-hid-NS-modaco-0.1-signed.zip">Nexus S, MoDaCo</a><br /></li></ul><span style="font-size:130%;"><span style="font-weight: bold;">How to install:<br /><br /></span></span>Because you have a rooted device, you should be already having <a href="http://twitter.com/#%21/clockworkmod">Clockworkmod </a>recovery installed as your recovery manager (or a similar). Flash my update the same as you flash any update.<br /><ol><li>Download the appropriate file from above and save it on your device sdcard.<br /></li><li>Reboot the device in the recovery mode (for Nexus S, hold the Power & Vol-up while switching on, and then select Recovery)</li><li>Choose 'install zip for sdcard'</li><li>Choose 'choose zip for sdcard'</li><li>Select the update file you have saved in step 1</li><li>Confirm install by selecting 'Yes - install blah blah...'</li><li>Wait a couple of seconds and make sure no errors are displayed</li><li>Now choose 'Go Back' and reboot your device normally<br /></li></ol><span style="font-weight: bold;font-size:130%;" >How to use:</span><br /><br /><ol><li>Assuming you have successfully connected your keyboard and can type in English, wherever you want to write in Arabic, just press the Alt key two times, that simple!</li><li>To type again in English, just press the Alt key two times, again!</li><li>When writing in Arabic, you can use the shift key to write alef hamza, Arabic comma, semicolon, diacritics (tashkeel) and everything you are used to write on your computer.<br /></li><li>You will also notice that digits are written in Hindi, so yes it is real Arabic keyboard :)</li></ol><span style="font-weight: bold;">Note: </span>in BlueKeyboard JP, there is a bug that will not let you switch to Arabic when the bottom ads are shown, to workaround this, just press 'Esc' on your keyboard for the ads to go away and then you can switch back and forth to/from Arabic.<br /><br /><span style="font-weight: bold;">Important: </span>Don't use this update for devices having physical keyboards. Obviously this will modify their layout.<br /><br />That's it for now, waiting to hear from you.<br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com10tag:blogger.com,1999:blog-1427064072400819258.post-8820770435844242232010-09-26T13:44:00.003+02:002010-09-26T14:00:54.340+02:00Securing apache Basic authenticationThe easiest way to <a href="http://httpd.apache.org/docs/1.3/howto/auth.html">secure your apache webserver</a> is using Basic authentication. Users wanting to access your webserver will be prompted to enter a username/password pair to do that. However, Basic authentication is not secure as it does not encrypt these credentials, nor the content itself. The solution comes in Digest authentication. This is how to migrate your server configuration from Basic to Digest authentication.<br /><span class="fullpost"><br />In Basic authentication, you create a passwords file (using htpasswd command) then configure apache as in the link above. To migrate to Digest authentication all you have to do is to:<br /><ol><li>Use the command htdigest instead of htpasswd to create users<br /><blockquote>htdigest -c /path/to/your/passwords/file "Authentication Realm" username</blockquote></li><li>Configure apache by adding the following:<br /><blockquote>AuthType Digest<br />AuthName "Authentication Realm"<br />AuthUserFile /path/to/your/passwords/file<br />Require valid-user</blockquote><br /></li><li>If you have SELinux running, enable httpd to access the passwords file:<br /><blockquote>setsebool -P httpd_enable_homedirs 1</blockquote></li><li>Restart apache:<br /><blockquote>service httpd restart</blockquote></li></ol><div>Note: the apache user (usually apache) needs to have read access to the passwords file, apparently!</div><div><br /></div><div>It is worth nothing that Digest authentication only encrypts your password, but not the content. Moreover, anyone sniffing on the packets, having the encrypted password, can use it directly to access your content. To overcome these issues, you have to put your content under SSL, but this is another story.</div><div><br /></div><div><br /></div></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com1tag:blogger.com,1999:blog-1427064072400819258.post-39459120052346378752010-08-19T09:37:00.005+02:002010-08-19T10:04:50.038+02:00Nokia Ovi Store distribution market and the axis-of-evil countriesToday I was reading some technical news and came across <a href="http://blogs.forum.nokia.com/blog/nokia-developer-news/2010/08/16/new-forum-nokia-page-shares-ovi-store-statistics">an article</a> from the Forum Nokia Blog. The article highlights the achievements and new features of the <a href="http://store.ovi.com/">Ovi Store</a>. What drew my attention in this page is the distribution market map of the store. It basically tells which countries have paid apps, which have free only apps, which are totally blocked!<div><br /><span class="fullpost"><br /><br /><img src="http://www.forum.nokia.com/pics/distribute-ovi-store-global-map.jpg" style="display:block; margin:0px auto 10px; text-align:center;width: 400px; height: 267px;" border="0" alt="" /><br />As you can see from the map, these are the axis-of-evil countries that are blocked from the Ovi Store:</span></div><div><ol><li>Iran</li><li>Syria</li><li>Sudan</li><li>Cuba</li><li>North Korea</li><li>Cote d'Ivoire</li><li>Congo</li><li>Zimbabwe</li><li><i>Did my eyes miss something?</i></li></ol></div><div><span class="fullpost">This reminds me of the <a href="http://arabcrunch.com/2010/01/following-clintons-internet-freedom-speech-us-based-sourceforge-blocked-syria-sudan-iran-korea-cuba-is-open-source-still-really-open.html">ban of some of these countries</a> from the SourceForge website post <a href="http://www.state.gov/secretary/rm/2010/01/135519.htm">Clinton's Internet Freedom Speech</a>. At least Nokia should make this block list under the control of the app publishers, exactly like <a href="http://news.northxsouth.com/2010/03/03/sourceforge-and-the-us-laws/">what SourceForge did</a>.</span></div><div><span class="fullpost"><br /></span></div><div><span class="fullpost">I don't like the political influence on the technical world. It does not align with the human rights of the people of these countries.</span></div><div><span class="fullpost"><br /></span></div><div><span class="fullpost">You too Nokia?</span></div><div><div><br /></div></div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com1tag:blogger.com,1999:blog-1427064072400819258.post-54278892415393516492010-06-07T13:12:00.002+02:002010-06-07T13:16:13.365+02:00Who is the true God, Jesus or Allah?Everything that is made should have a maker. The computer you are using right now did not come from nothing randomly. There should be a maker of it. The earth, sky, mountains, rivers, your body and everything should have a maker. This maker should be one and only one because if there is more than one, there would be much discrepancy throughout the creatures. This creator is the only God who is so powerful, so great and so merciful. This God is called for since Adam, Noah, Moses, Jesus and Mohammad, Peace be upon them all. They all call for the same creator, the same God, Allah. This is what Muslims believe.<br /><br /><span class="fullpost">As for Jesus, Peace be upon him, he was given birth without a father. Allah sent his angel Gabriel to Jesus mother, Mary with the blessing of a baby. She asked Gabriel, oh how can I have a baby without a father? He replied, for Allah, the most powerful, do you think it is difficult for him? Allah created Eve without a mother, and Adam without a mother, nor a father.<br /><br />Jews at that time condemned Mary of making illegal love, they did not believe Jesus is a blessed prophet sent from almighty Allah. They even tried killing him over the Cross when he was an adult. However, Allah, the most merciful, sent someone that resembles him to be prosecuted instead of him. Since then, Christians believe it was Jesus was really prosecuted for the humanity sake. They even believe that he is God himself, or the son of God. But how could a God stay in his mother's womb for 9 months? How could he eat and drink and then urinate and defecate? And how was the world managed while he was in his mother's womb?<br /><br />If you need more information about Allah and Islam, you can check these websites:<br /><a href="http://www.islam-qa.com/en/cat/12">http://www.islam-qa.com/en/cat/12</a><br /><a href="http://www.islamicity.com/education/understandingislamandmuslims/">http://www.islamicity.com/education/understandingislamandmuslims/</a><br /><br /></span><div><span class="fullpost">Peace be upon you.</span></div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-40589116428427502432010-06-03T11:54:00.004+02:002010-06-03T12:06:32.407+02:00The undocumented changes in Google Groups posting policiesI have been noticing that my email posts on one of the Google Groups I am subscribed to do not get replies from other members anymore. I was starting to get upset and thought my popularity has dropped and people are totally skipping my emails! I asked <a href="http://blog.gammal.org/">Mahmoud </a>what was the last email he got from me and he told me it was several days ago! I logged in to the group website and found that my recent posts do NOT get delivered at all, without a single notice from Google!<br /><span class="fullpost"><br />After several tests I came to the following:<br />When your subscription in Google Groups is on email A, you have to really send from this email account A. If you use an email account B with an alternate account A (that appears in the From field), this will not work (as of May 29th and at least for me!)<br />You will not even get a delivery error from Google in this case because they think you are forging this email.<br /><br />However, if you send from a totally different account C (and don't try to modify the sender), you will get a delivery error.<br /><br />Moreover, if you send from account A USING ANY ALTERNATIVE ACCOUNT B, C, D, ... The message will be delivered!<br /><br /><b>Bottom line, now they only look for the real sender, and if an alternative account is used, they don't reply back with any error.</b><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-27612805437503453422009-09-05T16:41:00.000+02:002009-09-05T15:53:06.395+02:00Getting your location using iPhone with no GPSOne of the main big features in iPhone 3G that was not shipped with its ancestor iPhone 2G is GPS support. You can determine your location using GPS satellites.<br />It is known that although very accurate, GPS has some drawbacks. It needs a lot of time to connect to the satellites, in the order of tens of seconds. It won't work indoors as well. Moreover, it is <a href="http://www.cellular-news.com/story/34085.php">banned</a> in Egypt, Syria and North Korea!<br />Update: It is <a href="http://rescommunis.wordpress.com/2009/04/20/egypt-lifts-gps-ban/">not banned</a> anymore in Egypt.<br /><br />So can one determine his location without the aid of GPS technology? The answer is Yes. This can be done by identifying nearby GSM cell towers and query a database that stores their location. So lets divide the rest of this post into 2 parts:<br /><span class="fullpost"><br /><br /><span style="font-size:130%;">Identifying nearby GSM cell towers</span><br /><br />Doing this on the iPhone was a bit tricky. Actually it was a challenge for us at <a href="http://www.espace.com.eg/">eSpace</a> to get such information. I will list here the challenges we met and how we managed to solve them:<br /><ol><li>There is no official SDK for iPhone OS 1.x. This was the easiest challenge to solve. Everybody uses <a href="http://code.google.com/p/iphone-dev/wiki/Building">iphone-dev</a> for building the iPhone toolchain. Most of the header files in the toolchain are generated by <a href="http://www.codethecode.com/projects/class-dump/">class-dump</a>! This is a tool that takes a binary framework (library) as an input and emits some Objective-C code in a header file that represents symbols in the library. Its idea is as simple as using <a href="http://linux.about.com/library/cmd/blcmdl1_nm.htm">nm</a> to query symbol names and some extra code to wrap this info in Objective-C syntax.<br /></li><li>Even in the non-official toolchain, there is not a word on how to deal with telephony features like calls and text messaging. Thanks to <a href="http://code.google.com/p/iphone-wireless/source/browse/#svn/trunk/CellStumbler">CellStumbler</a>, we used it to get cell information. It is a tool that exploits CoreTelephony framework functionality. CoreTelephony.h is also generated with class-dump.</li><li>CellStumbler is very fragile, if you do simple edits in it, it may crash! The guys say it is toolchain bugs! Just keep this in mind if you need to modify it. Be aware that server connection callback never get called, so keep on retrieving cell information until you get something useful.</li><li>Because CellStumbler is that fragile, we left the code untouched in its major parts, we just changed the part that outputs results. We then called the binary from a shell and parsed its output to get useful nearby cell information.<br /></li></ol><br /><span style="font-size:130%;">Querying a database for cell location</span><br /><br />Google used to have a secret API for this. It is called My Location. This is the API it uses in Maps. Unfortunately, at the time of our development, the API was secret, we had to sniff upon packets to/from Google Maps to know what happens under the hood and replays it. Now this API is <a href="http://googlemobile.blogspot.com/2008/06/google-enables-location-aware.html">open to developers</a>, thanks Google.<br /><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com4tag:blogger.com,1999:blog-1427064072400819258.post-77350867729381403222009-06-02T13:24:00.005+02:002009-06-02T13:36:37.587+02:00Fortunately, another reason why I use UbuntuSince I installed Ubuntu 9.04 on my work machine (and replaced Micro$oft Outlook with Evolution), I always wondered why my download speed became surprisingly a lot faster! My surprises approached a relief today when I came across a local speed test service. I tested the speed on Windows (with no firewalls or anything coming in the middle) and Ubuntu.<br /><br />The result was Ubuntu achieving <span style="font-weight: bold;">DOUBLE</span> speed than Windows! Yes you read it right, <span style="font-weight: bold;">DOUBLE</span> speed on the same machine!<br />I will leave you with the screenshots to witness it yourself.<br /><br /><span style="font-weight: bold;font-size:130%;" >Windows download speed:</span><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5SHNPd0xlB_vOo31MZe6lQgk1bLdo-2xVI33qJxxyPQaLHh5NekfYz1F4neMGeTPB899FfOnvDUwteLb4MMEENC2eIDS_DVCbeChvOuWR7bbFRe7LnjADYSlaCKRWeIAsxnC5GsQAuyx0/s1600-h/speedtest-windows.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 232px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5SHNPd0xlB_vOo31MZe6lQgk1bLdo-2xVI33qJxxyPQaLHh5NekfYz1F4neMGeTPB899FfOnvDUwteLb4MMEENC2eIDS_DVCbeChvOuWR7bbFRe7LnjADYSlaCKRWeIAsxnC5GsQAuyx0/s400/speedtest-windows.jpg" alt="" id="BLOGGER_PHOTO_ID_5342691555930515426" border="0" /></a><br /><span style="font-size:130%;"><span style="font-weight: bold;">Ubu download speed:</span></span><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfAZKo9ocCe86iv6IHXyssLnSC-UfdQpnDz2GzDAb3hk7QfEh7qmdSymM_YcFnx1S9t0Cb11f2hZqogCG7K3j4CXylwBzehC9qfzSB356Q5775Vl2qKfVCC7dOuBAwEAtEAyKEQ_TWTuRr/s1600-h/speedtest-ubuntu.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 231px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfAZKo9ocCe86iv6IHXyssLnSC-UfdQpnDz2GzDAb3hk7QfEh7qmdSymM_YcFnx1S9t0Cb11f2hZqogCG7K3j4CXylwBzehC9qfzSB356Q5775Vl2qKfVCC7dOuBAwEAtEAyKEQ_TWTuRr/s400/speedtest-ubuntu.jpg" alt="" id="BLOGGER_PHOTO_ID_5342691717853831410" border="0" /></a>The only explanation I can tell is that the TCP/IP stack default parameters on Windows are not optimally configured, while the defaults in Linux are!<br />Any other suggestions?<br /><br /><span class="fullpost"></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com7tag:blogger.com,1999:blog-1427064072400819258.post-44782285728002247562009-05-17T13:29:00.006+02:002009-07-01T13:44:10.055+02:00Dr Mohamed Slim Alouini farewell at TAMUQToday we gathered for the farewell of <a href="http://ecen.qatar.tamu.edu/425.aspx">Dr Alouini</a> at <a href="http://www.qatar.tamu.edu/">TAMUQ</a>. It has only been one week since I am here at TAMUQ, but Dr Alouini did have an effect on my career! Last October when I came here for an interview, Dr Slim (and <a href="http://ecen.qatar.tamu.edu/838.aspx">Dr Shehab Ahmed</a>) urged me to finish my Masters so that they can apply for my VISA.<br /><br />After I came back to Egypt, I took an unpaid vacation from my work at <a href="http://www.espace.com.eg/">eSpace</a> and started the campus of studying! Thanks to Allah, I got the Masters certificate last February. I was always remembering Dr Alouini's words about pushing my career onwards and finishing the Masters as quickly as possible.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfKSXv-a7JtA4M37WtS-QgTClOTbeMADZSBVN1yuENlS97Ml1lVD7jZVdYiNrThyphenhyphenOakWfKGXvjAbLkZozVv9bUwuZMgDZHg9_pm2v1VRc8uLnsZjK-LfRrU-tRbHexf2JN2XErcCaZwpXO/s1600-h/17052009147.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfKSXv-a7JtA4M37WtS-QgTClOTbeMADZSBVN1yuENlS97Ml1lVD7jZVdYiNrThyphenhyphenOakWfKGXvjAbLkZozVv9bUwuZMgDZHg9_pm2v1VRc8uLnsZjK-LfRrU-tRbHexf2JN2XErcCaZwpXO/s400/17052009147.jpg" alt="" id="BLOGGER_PHOTO_ID_5336755990803952562" border="0" /></a><br /><br />From right: Hossam Hammady (me), <a href="http://people.qatar.tamu.edu/wessam-mesbah/">Dr Wessam Mesbah</a>, Dr Alouini, Dr Ahmed Masoud, Majid Farouqi.<br /><br />So although we didn't meet much, but thanks Dr. Alouini for pushing me onwards.<br /><br /><span class="fullpost"></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com3tag:blogger.com,1999:blog-1427064072400819258.post-17794856831750265402009-05-14T09:32:00.005+02:002009-05-17T13:43:55.671+02:00My new job at Texas A&M University at QatarIt has been so long since I posted anything here. I am always lazy writing blogs :( Today I thought I should write something. From now on, my blogs should be short so that I don't get lazy writing them!<br /><br />So, I am writing this to let you know that I have joined <a href="http://www.qatar.tamu.edu">Texas A&M University at Qatar</a> as a Teaching Associate. The hiring process took too long since I had to finish my Masters first before I apply for the VISA. Thanks Allah, I finished my Masters last February, but this is another story, I will write about it soon insha2Allah :)<br /><br />I am now in Doha with my little family, my wife and my little 1-year-old kid, Abdullah. My job here includes both teaching tasks and support in IT-related issues for the faculty.<br /><br />A lot of paper work to do here to finish my residency permit and settle in my new house. I didn't take any task yet, just all about orientation and settlement. I hope work would be fun here as I have always enjoyed my job :)<br /><br /><span class="fullpost"></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com4tag:blogger.com,1999:blog-1427064072400819258.post-45730480651782658342008-11-06T10:24:00.011+02:002008-12-13T22:51:58.060+02:00MCabber: a command-line-only multi-protocol IM clientCommand-line geeks, its time to stay focused on your terminals and not switch to X back-and-forth when chatting with your buddies.<br /><blockquote><a href="http://mcabber.com/">mcabber</a> is a small Jabber console client.<br />mcabber includes features such as SSL support, MUC (Multi-User Chat) support, history logging, command completion, OpenPGP encryption, OTR (Off-the-Record Messaging) support and external action triggers.</blockquote><br />As you can see MCabber is just a Jabber client. So you can not use it to connect to your favorite IM servers like MSN, Yahoo!, GTalk,...<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mirror.mcabber.com/screenshots/mcabber20060403.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 599px; height: 316px;" src="http://mirror.mcabber.com/screenshots/mcabber20060403.png" alt="" border="0" /></a><br /><br />However, you can use it to connect to these networks with little effort. All you have to do is to install <a href="http://www.igniterealtime.org/projects/openfire/index.jsp">OpenFire</a> (or any Jabber server software) and enable the GatewayIM plugin. From its name, this plugin enables you to connect to other IM networks. Just create an account on your Jabber server through its nice web interface and configure it with other networks login information. Next, let MCabber connect to your server and do everything you love.<br /><br /><span class="fullpost"><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGlxq1Ekaa6ELqr4lqODpV0cjajncJi8Ztme3XKVwXtp4VyjP8EP3tm0EvX1bbZvhA8tF9N5jaFQfDkHxq0OyPFp_5HGjR19_0nU_SsrSd0eVducLUPE7TOR9DosJwza8_8Urcr3RTJP-7/s1600-h/Screenshot-Openfire+Admin+Console:+Gateway+Registrations+-+Mozilla+Firefox+3.1+Beta+1.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 304px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGlxq1Ekaa6ELqr4lqODpV0cjajncJi8Ztme3XKVwXtp4VyjP8EP3tm0EvX1bbZvhA8tF9N5jaFQfDkHxq0OyPFp_5HGjR19_0nU_SsrSd0eVducLUPE7TOR9DosJwza8_8Urcr3RTJP-7/s400/Screenshot-Openfire+Admin+Console:+Gateway+Registrations+-+Mozilla+Firefox+3.1+Beta+1.png" alt="" id="BLOGGER_PHOTO_ID_5265468224437396546" border="0" /></a><br /><br />To install MCabber on Debian/Ubuntu just type:<br /><code><br />sudo apt-get install mcabber<br /></code><br /><br />Before you connect with the server, you have to configure MCabber first. The only mandatory configuration is server address, port, username (jid format: username@servername, you can know the servername from OpenFire admin console) and password. You can start with the example configuration file by copying it to your home directory:<br /><code><br />cd $HOME<br />mkdir -p .mcabber/histo<br />zcat /usr/share/doc/mcabber/examples/mcabberrc.example.gz > .mcabber/mcabberrc<br /></code><br />So far, I have been talking about everything old! Anything cool here?<br /><br />A great functionality of MCabber is that you can write an external script in any language and let it handle IM events like message received, buddy logged in, ...<br />I have wrote a bash script which plays some nice sounds (got them from <a href="http://www.pidgin.im/">Pidgin</a>) on some events, so that you don't have to poll mcabber "window" to watch for new messages! You can download the script from <a href="http://downloads.hammady.net/mcabber/event-handler.sh">here</a>.<br /><br /><span style="color: rgb(255, 0, 0);">Update: The script now "says" the jid of the buddy logging in/out! However, you need to install <a href="http://en.wikipedia.org/wiki/Festival_Speech_Synthesis_System">festival</a> before you can use this feaute:</span><br /><br /><code><br />sudo apt-get install festival<br /></code><br /><br />Don't forget to turn on execution bit or it won't be able to run.<br /><code><br />chmod u+x $HOME/.mcabber/event-handler.sh<br /></code><br /><br />Don't also forget to edit mcabberrc to tell it to use that script for handling events<br /><code><br />set events_command = /your/home/directory/.mcabber/event-handler.sh<br /></code><br /><br /><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com5tag:blogger.com,1999:blog-1427064072400819258.post-71141862591959601932008-11-01T14:56:00.004+02:002008-11-01T16:13:26.959+02:00Building a no-X version of HTK on Linux<blockquote>The Hidden Markov Model Toolkit (HTK) is a portable toolkit for building and manipulating hidden Markov models. HTK is primarily used for speech recognition research although it has been used for numerous other applications including research into speech synthesis, character recognition and DNA sequencing. HTK is in use at hundreds of sites worldwide.</blockquote>Quoted from the <a href="http://htk.eng.cam.ac.uk/">HTK website</a>.<br /><br />HTK is a free/open-source piece of software. It builds on Linux, Solaris, IRIX, HPUX, Mac OS/X, Windows NT, 2000, XP and FreeBSD.<br /><br /><span style="font-weight: bold;font-size:130%;" >The problem:</span><br />If you tried to build HTK on a command-line-only Linux machine (no X installed), it will give build errors. You may face this situation if you need to run your experiments on a hosted solution that has no GUI to exploit its CPU/memory power. The problem happens because there is a single tool that requires graphical user interface: HSLab.<br /><br /><span class="fullpost"><br /><blockquote>HSLab is an interactive label editor for manipulating speech label files. An example of using HSLab would be to load a sampled waveform file, determine the boundaries of the speech units of interest and assign labels to them. HSLab is the only tool in the HTK package which makes use of the graphics library HGraf.<br /></blockquote>In most cases you will not need this tool in your regular experiments. So if this is your case, you can disable it so that the rest of HTK would build successfully.<br /><br /><span style="font-weight: bold;font-size:130%;" >The solution:</span><br />I assume you are using the latest version of HTK (3.4). Disabling HSLab comes in 2 steps:<br /><ol><li>Remove HSLab target from file HTKTools/Makefile in line 48.</li><li>Remove HGraph from object dependancy in file HTKLib/Makefile lines 49 and 78.</li></ol>If you have no idea how to make this, you can download my <a href="http://downloads.hammady.net/htk/">2 patches</a> and place them in HTK src directory. Run the following commands to patch the makefiles and make/install HTK:<br /><code><br /># change directory to htk src path, then:<br />./configure<br />patch HTKLib/Makefile HTKLib.Makefile.patch<br />patch HTKTools/Makefile HTKTools.Makefile.patch<br />make<br />sudo make install<br /></code><br />Now the whole HTK installs with no problems.<br />Enjoy :)<br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com2tag:blogger.com,1999:blog-1427064072400819258.post-48412529958395164982008-09-30T04:47:00.005+02:002008-10-04T16:38:54.552+02:00Writing Large-Scale iPhone Applications using JiggyDeveloping for the <a href="http://www.apple.com/iphone/">iPhone</a> is the hype nowadays. However, one big obstacle that faces anyone who wish to write iPhone applications is learning <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/chapter_1_section_1.html">Objective-C</a>. After all, it is a high-level Object Oriented language. However, in my point of view, and for many people as well, the C family of languages is not suitable for application development. It is perfectly suited for writing system libraries and frameworks. This is because one should always take care of memory management, types and low level system calls.<br /><br />Thats why we are here, quoted from the <a href="http://www.jiggyapp.com/">Jiggy</a> official website:<br /><br /><blockquote><br /><h3>What is Jiggy?</h3><br />Simply put, Jiggy is the easiest way to create applications for the iPhone (or iPod Touch). With just Jiggy and a browser, you'll be able to write an awesome iPhone application in a matter of minutes. JiggyApps run natively on the iPhone, so there is no messing around with HTML and the limitations of Mobile Safari. At the same time, you don't need a compiler or even a Mac, because JiggyApps are written in JavaScript.<br /></blockquote><br /><br /><p>When you start writing an application with Jiggy you will find it very simple. However, as your application grows it will be so hard to maintain. Thats why I am writing the following guidelines, which if followed, will help you write large-scale, neat and maintainable Jiggy applications:<br /></p><br /><br /><span class="fullpost"><br /><ol><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Don't use the Jiggy IDE, prepare your development environment around ssh.</span></span><br />If you already installed Jiggy on your iPhone, you will probably have noticed that there are 2 packages your are installing. First one is called Jiggy runtime. This is a set of dynamic-link libraries that encapsulate all native functionality. These are installed in the library path of the system (/usr/lib) and start with the prefix jiggy, as an example: jiggy.UIKit and jiggy.sqlite. The other package is called just Jiggy. This is the Jiggy IDE I am talking about. It is just an application server built on an HTTP server. You run it from SpringBoard, open a browser on your PC and point it to the iPhone IP to get the IDE working inside the browser. This is the simplest way to develop Jiggy applications. You only need a browser. Running into big applications, you will soon find that the browser is never meant to be a reliable IDE. It WILL crash more frequent than you expect. It will leak memory to the ground. It will freeze for seconds as you save and run the application. Moreover, to work on multiple files simultaneously, you have to open several tabs/windows. You can use this IDE as a fast boot but when you eventually develop seriously you need a more reliable environment. Install <a href="http://blog.psmxy.org/pkg-info/openssh/">OpenSSH</a> on the iPhone (but be careful if you need to <a href="http://blog.hammady.net/2008/06/only-idiots-change-their-iphone-root.html">change the root password</a>). Next, mount the iPhone filesystem using sshfs:<br /><code><br />sshfs root@IPHONE_IP /mount/point -o allow_other<br /></code><br />You can download sshfs from its <a href="http://fuse.sourceforge.net/sshfs.html">official site</a> or if you are using Debian/Ubuntu by:<br /><code><br />sudo apt-get install sshfs<br /></code><br />or if you are using Gnome use the menu Places/Connect to Server... and select server type as SSH. Write the iPhone IP and root as the username. A shortcut will be placed in Places and on the desktop. Either way, you can browse through /Applicatoins/ and point to your application folder then double click on any Javascript file to edit using your favorite editor. I personally use gedit or vim. Just a note, be sure the iPhone is mounted before editing the files or the editor may get confused and hangs.<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Distribute required runtime libraries along with your applications, don't assume Jiggy runtime.</span></span><br />These can be found in /usr/lib as discussed earlier. During the installation process, don't copy the libraries in the system /usr/lib in order not to conflict versions. It is safer to leave them in the application directory. By the way, I didn't try leaving them in the application directory yet :) On the contrary, you may prefer to distribute the libraries through Jiggy runtime. However, be very clear in the installation steps.<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">For a more stable and collaborative environment, use a code repository and deploy on device as needed. </span></span><br />When your code-base grows over time, you will discover that it is safer to use a code repostiory (<a href="http://subversion.tigris.org/">Subversion</a> of <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System">CVS</a>). This will also enable you to share the application with other developers. Now you don't have to mount the iPhone filesystem using ssh as you will not be editing files in-place. You will have a working copy on your PC which is linked against some repository. Each time you need to run the application you will have to copy files over the iPhone, you can write a small shell script to do the copy commands. Till the time of writing this line, Jiggy is only available for the iPhone OS 1.x which has no official SDK or emulator from <a href="http://www.apple.com/">Apple</a>. If Jiggy is ported to iPhone OS 2.x it would be easier to run applications on the emulator without the need of copying files on each run.</span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Avoid using off-the-shelf libraries (<a href="http://www.prototypejs.org/">prototype</a> for example), you don't need larger useless interpretation times.<br /></span></span>Usually you won't need fancy mechanisms or drag-and-drop and alike functionality. If you need to use AJAX, write your own prototype-alike around the XMLHttpRequest object. If you are too lazy to write it, see <a href="http://downloads.hammady.net/jsexamples/jiggy/ajax.js">mine</a>.<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Don't start the application from SpringBoard (if you don't have to). Start it from an ssh terminal instead</span></span>.<br />Some functionality won't work if you don't start the application from SpringBoard (like the accelerometer). If you don' have to, ssh to your iPhone and change to the applications directory then launch the jiggy binary:<br /><code><br />ssh root@IPHONE_IP<br />cd /Applications/MyApp.app<br />./jiggy<br /></code><br />This is a must if you need to see useful log messages from Jiggy native implementation. You can also write your own logs straight from Javascript using the global function log(). See my <a href="http://blog.hammady.net/2008/09/your-guide-to-writing-large-scale.html">other post</a> for a discussion on logging in Javascript platforms.<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Optionally generate a public/private ssh key-pair so that you don't have to enter ssh password every time you login to your iPhone.</span></span><br />See the <a href="http://blog.psmxy.org/pkg-info/openssh/">OpenSSH page</a> or this <a href="http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html">good tutorial</a>.</span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Keep your main.js as small as 10 lines or less. </span></span><br />This is always a rule-of-thumb for all programming paradigms. The general flow of the program should be readable by anybody. Throw away your implementations inside classes and throw these classes inside files other than your main.js. Even more, I do NOT write any flow in my main, its just a logic switch, or program selector:</span></li><span style="font-size:85%;"><br /><code><br />// main.js<br />try {<br />//include("test1.js")<br />//include("test2.js")<br />include("myprog1.js")<br />}<br />catch(e) {<br />log(e)<br />terminate()<br />}<br /></code><br />Whenever I need to test any code or run any sample code, I just throw it in a file and switch to it in my main. When I am finished I uncomment back the original program.<br />The try/catch is there to bust silly alerts that appears on-screen which if not dismissed normally by user, will freeze the SpringBoard.<br /><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Create a test-harness because you will need to try various things first.<br /></span></span>You may create a new application for the sole purpose of testing code. Create any testing code in new files and switch between them in main.js. This way you don't need new applications each time you try any code. See the code of main.js in previous point as an example.<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Make your files self-contained, don't assume any implicit dependency.</span></span><br />In Jiggy, there are 2 types of code dependency. First is Plugin dependency where you depend on a native plugin (<a href="http://www.jiggyapp.com/jigglins">Jigglin</a>). Second type is Javascript dependency where you depend on other Javascript files. As an example for the first type, if you use the package <span style="font-style: italic;">Images</span> don't assume that the <span style="font-style: italic;">UIKit</span> plugin is loaded. In the beginning of the file check if it is not loaded and load it accordingly:<br /><code><br />if (typeof Images == 'undefined')<br />Plugins.load('UIKit')<br /></code><br />Current Jiggy implementation does not check for loading same plugins more than once, and hence the check above.<br />As an example for the second dependency type consider this:<br /><code><br />include('another.js')<br /></code><br />And in another.js put the inclusion guard which I borrow from C/C++!<br /><code><br />if (typeof __ANOTHER_JS == 'undefined') {<br />__ANOTHER_JS = 0<br />// write all your Javascript code here<br />...<br />}<br /></code><br /></span></li><span style="font-size:85%;">This inclusion guard is recommended although not mandatory because re-interpretation of code may cause undesired logical errors.<br /><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Use a central include path because you are going to make/use reusable components. </span></span><br />Sticking to the Object Oriented design will render many parts of your code reusable. The straightforward way to reuse the components is to copy them over through different applications. However, you will be changing them frequently and you need a central place for them. You may place them in a separate directory and create symbolic links inside your application folder. I wish I could have time to patch Jiggy source so that it looks in a central include path if it does not find the file in the application directory. Did I hear someone offering help?<br /></span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Always remember the restricted memory resources, cache on disk if necessary.</span></span><br />Don't write code that aggressively allocates memory. Don't let your arrays grow indefinitely. If you need large data-structures let them write their data on disk if they exceeded some limit, using sqlite if needed. If it is all about memory cache, let older values drop altogether.</span></li><span style="font-size:85%;"><br /></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">Don't forget your friend, the garbage collector (GC), you may know when to call it better than the engine does.</span></span><br />Let the code be smart and invoke it in places where you are sure many objects have been released. Each time you release an object, or return from a function, increment released objects count and invoke the GC if it reached some limit. The <a href="http://downloads.hammady.net/jsexamples/jiggy/">AutoReleaseCache and ImageLoader</a> are perfect examples for restricted memory management and garbage collection. There should be a global GC function when using them. Here it is:<br /><code><br />var GC_TRIGGER = 40<br />var releasedObjectsCount = 0<br />GC = function(force)<br />{<br />if (force || releasedObjectsCount++ > GC_TRIGGER) {<br />releasedObjectsCount = 0<br />log("-----------------------------------------------")<br />log("running gc")<br />log("-----------------------------------------------")<br />gc(1)<br />}<br />}<br /></code><br /></span></li></ol><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-5752773942023900362008-09-30T02:33:00.007+02:002008-10-04T16:55:24.912+02:00Your Guide to Writing Large-Scale Javascript Applications<span style="font-size:85%;">What is peculiar in Javascript is that it is designed for many types of applications. Noobs can learn it in minutes. They can just go write little validation code insided web pages. Advanced web applications also rely heavily on Javascript. It is even taken beyond the web paradigm. Now you can find Javascript running on servers, inside desktop applications, and even on hand-held devices.<br /><br />This explains the ongoing war between Javascript interpreters, <a href="http://code.google.com/p/v8/">V8</a>, <a href="http://webkit.org/blog/189/announcing-squirrelfish/">SquirrelFish</a> (and <a href="http://webkit.org/blog/214/introducing-squirrelfish-extreme/">SquirrelFish Extreme</a>) and <a href="https://wiki.mozilla.org/JavaScript:TraceMonkey">TraceMonkey</a>. Each engine fights to dominate the market. Actually this is so important as web applications are becoming a lot more complex and old-style Javascript engines are dying out of performance. Embedded devices also need performant Javascript engines due to their limited resources.<br /><br />When your Javascript application grows in size, you will find it very difficult to maintain because the language is designed to be written in a simple way, no enforcements or conventions of any type. Actually, you will most probably end up with a very bad code. To avoid this and to write neat, maintainble and scalable Javascript applications, I have brainstormed with myself and wrote down the following guidelines. Some of them are general and can be applied to any programming language, not necessarily Javascript. I will be constantly adding to these guidelines as I forumalate them.<br /><br /></span><br /><span class="fullpost"><br /><ol><li><span style="font-size:85%;"><span style="font-weight: bold;font-size:130%;" >Use classes instead of separate global functions. </span><br />One may simply write an old C-style program around functions. The good, although old, news is that Javascript can be written in an object-oriented (OO) style. Although there are no explicit class definitions or inheritance, you still can work around this and define your own classes with both public and private access to data members and member functions. As implied by the OO design, your application will neatly grow as it goes. I will not discuss how to write classes but you can see the <a href="http://downloads.hammady.net/jsexamples/jiggy/">these examples</a> and see these useful links (<a href="http://www.xml.com/pub/a/2006/06/07/object-oriented-javascript.html">1</a> and <a href="http://www.developertutorials.com/tutorials/javascript/writing-classes-in-javascript-050404/page1.html">2</a> or google it).</span></li><li><span style="font-size:85%;"><span style="font-weight: bold;font-size:130%;" >Don't pollute the global context, always use namespaces/singletons.</span><br />If you strictly followed the previous point of the OO design, you will end up with a lot of class names. These class names are nothing but global variables, we approach the start point again. You can create namespaces to hold class definitions inside. For example:<br /></span></li><span style="font-size:85%;"><code>var MyPackage = {<br />MyClassA: function() {...},<br />MyClassB: function() {...}<br />}<br /></code><br />This way, we have just hidden MyClassA and MyClassB inside MyPackage namespace. To instanciate objects we write:<br /><code><br />x = new MyPackage.MyClassA().<br /></code><br />Note also that similarly we can write a singleton class:<br /><code><br />var MySingleton = {<br />method1: function() {...},<br />method2: function() {...},<br />variable1: 10,<br />variable2: "hello"<br />}<br /></code><br />You access singleton members as:<br /><code><br />MySingleton.method1()<br />MySingleton.variable1<br /></code><br />and so on.<br /></span><li style="font-weight: bold;"><span style="font-size:130%;">Make your functions anonymous and give them variable names.</span></li><span style="font-size:85%;">Functions in Javascript may be anonymous as well as named. For example you can define a function like this:<br /><code><br />function myfunc() {...}<br /></code><br />You can also write:<br /><code><br />function() {...}<br /></code><br />The latter form can be used as a closure or as an inline function. See <a href="http://www.jibbering.com/faq/faq_notes/closures.html#clClose">this</a>, <a href="http://blog.morrisjohns.com/javascript_closures_for_dummies">this</a> and <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Closures">that</a> for more information about closures.<br />Being an inline function you can set it to a variable:<br /><code><br />var myfunc = function() {...}<br /></code><br />This form may seem equivalent to the named form example above. However, they are not always equivalent. It is interpreter-specific. In IE JScript (I think it was IE6), named functions are always given their name regardless of their scope. This has the side effect of defining the function name as a global variable name. Take this example for more clarification:<br /><code><br />if (a > 1)<br />function foo() {...}<br /></code><br />In bad interpreters (Micro$oft JScript for example) foo is always a global variable of type function. It can be called in all cases not only if a > 1!<br />Need a dangerous scenario? Take this example:<br /><code><br />if (typeof foo == 'undefined')<br />function foo() {...}<br /></code><br />Suppose you need to check whether a function is defined or not, and if not define it your own way. This could happen inside a large application where you test if some sources are included and act accordingly. This will not work as expected due to the missbehavior of such interpreter. I faced this problem when writing some code that checks if <a href="http://www.prototypejs.org/">prototype</a> was included or not. So I wrote:<br /><code><br />if (typeof $ == 'undefined')<br />function $(element) {return document.getElementById(element)}<br /></code><br />The result was my $ always overriding prototype's $!<br />The solution is easy, just use:<br /><code><br />if (typeof $ == 'undefined')<br />var $ = function (element) {return document.getElementById(element)}<br /></code><br />This way, $ will not be defined unless it is already defined before.<br /><br /></span><li style="font-weight: bold;"><span style="font-size:130%;">Keep your files small, don't worry about number of files.</span></li><span style="font-size:85%;">As a general practice, don't place more than 1 class definition in a file. Consider Java public classes where you cannot define more than 1 public class in a file and file name should be the same as that public class. If this has changed in current specification, please tell me as I am not an active Java developer. This will add to modularity and will make your classes more liable to reusability.<br /><br /></span><li style="font-weight: bold;"><span style="font-size:130%;">Never use alerts for debugging.</span></li><span style="font-size:85%;">Debugging Javascript code using alerts always proves to be not practical. It pauses execution until the user dismisses the alert. You cannot just put 10 alerts and have them displayed each run waiting for you to dismiss them! Sometimes it is invalid to log through alerts. Suppose you need to simulate real time performance while you are having multiple threads, for AJAX requests as an example. Alerts will ruin the synchronization of threads because they pause their owning threads. Its worth noting that text inside alerts are limited to the display area.<br /><br /></span><li style="font-weight: bold;"><span style="font-size:130%;">Always use log messages for debugging.</span></li><span style="font-size:85%;">A better solution for debugging, still not the best, is using log messages rather than alerts. Logging debug information has many benifits of not blocking the running thread, playing the 10 messages with no code interruption and simulating the real time performance of threads. If you are inside a web page, you can log to some text area by modifying its value property. In <a href="http://www.jiggyapp.com/">Jiggy</a>, you can use the global function log() to throw away any message to the console. It is important to note that logging is not only for debugging. You have to log your application activity for inspection afterwards. This may help you enhance its performance or monitor user activity.<br /><br /></span><li style="font-weight: bold;"><span style="font-size:130%;">Consider using dynamic log-levels when your logs become bloated.</span></li><span style="font-size:85%;">Following the logging paradigm will render your log stream unreadable. When you add a new log line it will not be noticed among tens and hundreds of other log lines. Thinking of disabling older log lines is not the best solution, you may need to come back and debug something old. By enabling/disabling log lines you will be uncommenting/commenting some code. As a general practice code inside comments is highly discouraged. Actually you will need to debug several aspects continuously, like requests sent/received on network. Thats why log levels are for. However, I don't mean here the basic 4 levels that are widely used: Error, Warning, Info and Debug. These levels are placed according to severity of log. What I mean here is dynamically creating log levels according to different aspects of your application logic. For example, you may have aspects called "Network", "Database", "Rendering", "Flow" and such. Lets call them log aspects as opposed to log levels. When you log any message you define its aspect from these aspects. You may also combine an aspect with one of the 4 basic log levels mentioned above. When you wish to debug warnings from the network aspects you enable Warning level and Network aspect from a central configuration file. Such file may turn on and off all aspects and levels for your application. For example:<br /><code><br />var ENABLE_LOGS = true<br />var DEBUG_ASPECT_NETWORK = true<br />var DEBUG_ASPECT_DATABASE = false<br />...<br />var DEBUG_LEVEL_ERROR = false<br />var DEBUG_LEVEL_WARN = true<br />...<br /></code><br />and in your log lines:<br /><code><br />LOG("message here", DEBUG_ASPECT_NETWORK && DEBUG_LEVEL_WARN)<br /></code><br />where LOG is simply defined as:<br /><code><br />var LOG = function(message, enabled)<br />{<br />if (ENABLE_LOGS && enabled) log(message)<br />}<br /></code><br />You can add debug aspects and levels dynamically as your application grows. You can enable/disable aspects and levels as required without commenting/uncommenting your code.<br /><span style="font-size:130%;"><br /></span></span><li><span style="font-size:85%;"><span style="font-size:130%;"><span style="font-weight: bold;">If you are working inside a web browser, consider a Javascript debugger.</span></span> For Firefox there is <a href="http://www.mozilla.org/projects/venkman/">Venkman</a> and <a href="http://getfirebug.com/">Firebug.</a></span><span style="font-size:85%;"> If your log mechanism didn't help you, you may consider a real debugger which steps you into your code and helps you inspecting variables.<br /></span></li></ol><span style="font-size:85%;">Thats all for now, stay tuned for a more focused post about writing large-scale Jiggy applications!<br /><br /></span><br /><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com1tag:blogger.com,1999:blog-1427064072400819258.post-77127676894512520012008-07-25T23:12:00.002+02:002008-10-04T16:56:57.018+02:00Building your first Javascript-powered Symbian application using Webkit<p>The 10-years old <a href="http://www.symbian.com/" class="external text" title="http://www.symbian.com/">Symbian OS</a> is the open mobile operating system, that powers millions of smartphone worldwide, especially <a href="http://www.nokia.com/" class="external text" title="http://www.nokia.com/">Nokia</a> mobile phones.<br />Symbian itself is the OS engine that is customized by device manufacturers to produce real operating systems. Symbian has 3 platforms, the S60 which runs mostly on Nokia phones, the UIQ which runs mostly on <a href="http://www.sonyericsson.com/" class="external text" title="http://www.sonyericsson.com/">Sony Ericsson</a> and <a href="http://www.motorola.com/" class="external text" title="http://www.motorola.com/">Motorola</a>, and the MOAP (new).<br /></p><p>Developing for Symbian is an inevitable task for developers targeting mobile platforms. Depending on the target platform, a developer should select a Symbian SDK to use. The S60 platform itself contains a lot of versions with a corresponding SDK for each version. 1st, 2nd and 3rd editions exist, each one having as many as 3 to 4 feature packs. This results in about 9 versions. 1st edition represents Symbian OS v6.1 and the latest is v9.5. <a href="http://developer.symbian.com/main/index.jsp" class="external text" title="http://developer.symbian.com/main/index.jsp">The Symbian Developer Network (SDN)</a> and <a href="http://www.forum.nokia.com/" class="external text" title="http://www.forum.nokia.com/">Forum Nokia</a> has been always Sybmian developers heaven.<br /></p><p>Symbian applications are written in C++ (native) or Java (requires J2ME). The Internet browsing on Symbian started with <a href="http://www.opera.com/" class="external text" title="http://www.opera.com/">Opera</a> in its first releases. However, after releasing <a href="http://webkit.org/" class="external text" title="http://webkit.org/">Webkit</a> as an open-source project, it has been adopted by Symbian starting from 3rd edition as its default browser engine.<br /></p><p>The good news is that you can develop your own Symbian application that links with the Webkit and exploits its capabilities in Javascript interpretation and DOM manipulation. The bad news is that there is no guide, up to my knowledge, that demonstrates this!<br /></p><p>So here are simple steps for creating your first Javascript-enabled S60 application:<br /></p><br /><span class="fullpost"><br /><ul><li> First of all, download and build S60Webkit using <a href="http://wiki.forum.nokia.com/index.php/Building_S60Webkit#Configure_Your_Computer" class="external text" title="http://wiki.forum.nokia.com/index.php/Building_S60Webkit#Configure_Your_Computer">this guide</a>. Don't panic for build errors, you will find all solutions in this guide. This should work for Carbide.c++ the latest release v1.3. You will need also <a href="http://symbiangeek.blogspot.com/2008/02/change-details-compiling-s60webkit-with.html" class="external text" title="http://symbiangeek.blogspot.com/2008/02/change-details-compiling-s60webkit-with.html">this guide</a> because Carbide v1.0 is obsolete. Remember 3 simple rules:<br /><ul><li> to build for the emulator use "build -w"<br /></li><li> to build for the device use "build -g"<br /></li><li> to build a special target use "build -? targetname"<br /></li></ul><br /></li><li> There is a bug in the Perl script that scans build output to show number of errors/warnings. Find the file in: C:\Symbian\9.1\S60_3rd\Epoc32\tools\scanlog.pm, or change path to your SDK installation path. To fix it, find the condition following the comment:<br /></li></ul><code></code># make: *** [SAVESPACECONVTOOL] Error 2<br /><br /><p>with<br /></p><p><code>if ($line =~ /make(\[\d+\])?:\s*\*\*\*.*(E|e)rror/)<br /></code><br /></p>Start a new project in Carbide.c++ IDE using File->New->Symbian OS C++ project and select 3rd-Future ed. GUI application. Follow on-screen steps and you now have a simple HelloWorld application.<br /><ul><li> Now its time to link with the Webkit. You will have to edit some header and configuration files to get it working:<br /><ul><li> modify S60/JavaScriptCore/kjs/list.h and add<br /></li></ul><br /></li></ul><pre>#if NOKIA_CHANGES<br />#include <oom.h><br />#endif<br /></pre><p>somewhere in the beginning of the file<br /></p><ul><li> Edit the project mmp file (<projectname>.mmp) using Carbide IDE visual editor:<br /><ul><li> In the libraries tab at the bottom click on Add to add 2 libraries: JavaScriptCore_sdk.lib and MemMan_sdk.lib. If you did not find either then the building of S60Webkit was incomplete.<br /></li><li> In the options tab add 4 entries in the Compiler Settings area:<br /><ul><li> User includes: /Symbian/9.1/S60_3rd/s60/JavaScriptCore/kjs<br /></li><li> System includes: /Symbian/9.1/S60_3rd/s60/MemoryManager/Inc and /epoc32/include/libc<br /></li><li> Macros: NOKIA_CHANGES<br /></li></ul><br /></li></ul><br /></li><li> Edit the file where you want to write webkit-specific code, for example: xxxxAppUI.cpp:<br /><ul><li> Include the interpreter header file:<br /></li></ul><br /></li></ul>#include "interpreter.h"<br /><br /><ul><li><ul><li> write some code for Javascript interpretation, for example in the handler for first menu action:<br /></li></ul><br /></li></ul><p><code> using namespace KJS;<br /></code></p><p> InterpreterLock lock;<br /></p><p><br /><br /> Object globalObj(new ObjectImp);<br /></p><p> Interpreter *interp = new Interpreter(globalObj);<br /></p><p> UString code = KJS::UString("10 * 5");<br /></p><p> Completion result = interp->evaluate(code);<br /></p><p> ComplType resultType = result.complType();<br /></p><p> if (resultType == Normal) {<br /></p><p> // OK<br /></p><p> textResource = StringLoader::LoadLC(R_MESSAGE_OK);<br /></p><p> // textResource loaded with StringLoader.<br /></p><p> informationNote->ExecuteLD( *textResource);<br /></p><p> // Pop HBuf from CleanUpStack and Destroy it.<br /> CleanupStack::PopAndDestroy(textResource); <br /></p><p> }<br /></p><p> else {<br /></p><p> // failure<br /></p><p> textResource = StringLoader::LoadLC(R_MESSAGE_FAILURE);<br /></p><p> // textResource loaded with StringLoader.<br /></p><p> informationNote->ExecuteLD( *textResource);<br /></p><p> // Pop HBuf from CleanUpStack and Destroy it.<br /> CleanupStack::PopAndDestroy(textResource); <br /></p><p> }<br /><br />You may replace the variable "code" with any valid Javascript code.<br /></p><br /><ul><li><ul><li> add some string resources for the previous code to compile. In file data/<projectname>.rls add these 2 lines:<br /></li></ul><br /></li></ul><br /><br /><pre>#define qtn_message_ok "OK"<br />#define qtn_message_failure "Failure"<br /></pre><br /><ul><li><ul><li> In file data/<projectname>.rss add:<br /></li></ul><br /></li></ul><p><code><br />RESOURCE TBUF r_message_ok { buf=qtn_message_ok; }<br /></code></p><p>RESOURCE TBUF r_message_failure { buf=qtn_message_failure; }<br /><br /></p><br /><ul><li> Build your project for the emulator<br /></li><li> Open the emulator from Start menu and browse to Installed-><projectname><br /></li></ul><br /><p>Your application sould open, press the left menu button to show the menu, then select Message and get your previous Javascript evaluated by seeing 'OK'!<br /></p><p>I hope I have covered all dark parts, in case something was missing, please comment here to augment any missing part.<br /></p><div class="fivestar-static-form-item"><div class="form-item"><br /><br /></div></div><br /></span>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-66876084589361371782008-07-25T23:08:00.000+02:002008-07-25T23:09:03.115+02:00Which programming language I am<a href="http://www.bbspot.com/News/2006/08/language_quiz.php"><img src="http://www.bbspot.com/Images/News_Features/2006/08/language/java.jpg" alt="You are Java. You are very strong and sturdy, but this makes you a bit sluggish." height="90" width="300" border="0" /><br />Which Programming Language are You?</a>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-83127814696302171922008-06-22T14:59:00.000+02:002008-06-22T15:01:01.076+02:00Only idiots change their iPhone root password!<p>If you are a happy <a href="http://www.apple.com/iphone/" class="external text" title="http://www.apple.com/iphone/">iPhone</a> owner and you are an <a href="http://en.wikipedia.org/wiki/Secure_Shell" class="external text" title="http://en.wikipedia.org/wiki/Secure_Shell">ssh</a> geek, then the first thing you will install on your iPhone is <a href="http://blog.psmxy.org/pkg-info/openssh/" class="external text" title="http://blog.psmxy.org/pkg-info/openssh/">OpenSSH</a>.<br /></p><p>You will be happy with the installation, but you will find no GUI on your device, so it is supposedly accepting your ssh connections. Great, now find your iPhone IP and go ssh it with root login. Of course it is not passwordless, after googling this you will find it is 'dottie' prior to firmware 1.1.1 and 'alpine' later on. In the same site (<a href="http://blog.psmxy.org/pkg-info/openssh/" class="external text" title="http://blog.psmxy.org/pkg-info/openssh/">OpenSSH</a>) you are advised to change your root password, so intuitive: "You should change your password, after you install OpenSSH. Everyone knows the default password".<br /></p><p>Now login, fire passwd command and change it. Congratulations, you have put your iPhone in a wreck! After restarting it you will get a notice "Edit home screen" and the springboard crashes and restarts infinitely! If you try to connect it to your Mac or PC to reset it, or even <a href="http://www.ziphone.org/" class="external text" title="http://www.ziphone.org/">jailbreak</a> it, you will find your Mac/PC clueless and can't even discover the device.<br /></p><p>Being trapped in such frustration for more than an hour, I finally found <a href="http://blog.matsimitsu.nl/english/183/howto-fix-the-edit-home-screen-loop-for-iphone" class="external text" title="http://blog.matsimitsu.nl/english/183/howto-fix-the-edit-home-screen-loop-for-iphone">someone</a> talking about this problem and saying that changing the root password causes this and one should restore the old password files. The hard point is that I changed the password and did a lot of things then restarted the device so I never related the problem to its real cause.<br /></p><p>So, the passwd binary is not working for the iPhone. Either don't change your password or hash it manually using the <a href="http://blog.matsimitsu.nl/english/183/howto-fix-the-edit-home-screen-loop-for-iphone" class="external text" title="http://blog.matsimitsu.nl/english/183/howto-fix-the-edit-home-screen-loop-for-iphone">guide above</a>.<br /></p><p>phew, restarting your iPhone now solves the problem. Play wisely, even conservatively, with your little cute iPhone.<br /></p><div class="fivestar-static-form-item"><div class="form-item"><br /> <div class="fivestar-widget-static fivestar-widget-static-5 clear-block"><div class="star star-1 star-odd star-first"><span class="off">0</span></div><div class="star star-2 star-even"><span class="off"></span></div><div class="star star-3 star-odd"><span class="off"></span></div><div class="star star-4 star-even"><span class="off"></span></div><div class="star star-5 star-odd star-last"><span class="off"></span></div></div><br /> <div class="description"><div class="fivestar-summary fivestar-summary-"></div></div><br /></div><br /></div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-45550912446891545662008-05-28T13:50:00.003+02:002008-05-28T19:56:20.957+02:00Firefox bug: deceiving select onchange eventI have been experiencing a silly bug in Firefox for 2 years now. It happens on my Ubuntu (Gnome) and formerly on Debian (Gnome too). I tried it on a Windows machine but it didn't work.<br />As usual, I am lazy to try it on all available platforms, so please help me in your comments!<br /><h4>Bug description:</h4><br />If a select element has no option selected (selectedIndex == -1), an outside-select click behavior deceives the browser to fire the onchange event for the select.<br /><h4>How to reproduce bug:</h4><br /><ol><br /><li>Click to open a select element</li><br /><li>Move your mouse over any option (make sure the option is highlighted, but don't click on anything)</li><br /><li>Click outside the select twice</li><br /><li>As a result of the bug, the onchange event is fired with the option under mouse as the select value</li><br /></ol><br /><br />To see an example, the bug is illustrated <a href="http://downloads.hammady.net/select-gnome-bug.html">here</a><br /><br />I tried it on Ubuntu (Gnome and KDE) and it happens too.<br />I tried also on Firefox for Windows (through <a href="http://www.winehq.org/">wine</a>) and it happens too!<br /><br />Now what?Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0tag:blogger.com,1999:blog-1427064072400819258.post-53480543618483164362008-05-28T11:09:00.003+02:002008-05-28T12:03:57.546+02:00SELECT threads FROM GMail ORDER BY sender, subject, thread_activityGMail is a very good mail service, it has a lot of useful features, mainly searching. However, it misses a very important feature: sorting. Someone may argue, why sort while you can find any message using fast search? I say, sometimes you want to view your threads sorted alphabetically when you don't know the exact phrases to search with.<br /><br />I wrote a Javascript <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a> (GMail Sorter) to add sort controls in your GMail Inbox view. Once you enable the bookmarklet, you can see the following above your threads:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQDzfb_wcMlmujJuKikJu32wb6b3XZdw1WXoFq20dN27zmtgXUmZ4ozUJOWIOXF_tDqcbmDgPI04jmrlxAQGzO8dRfdWsnv8KhK-upRueNZbbf-b5_lHVOggXC5uZTUa8nPw7hsgVIWWpa/s1600-h/gmail-sorter.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQDzfb_wcMlmujJuKikJu32wb6b3XZdw1WXoFq20dN27zmtgXUmZ4ozUJOWIOXF_tDqcbmDgPI04jmrlxAQGzO8dRfdWsnv8KhK-upRueNZbbf-b5_lHVOggXC5uZTUa8nPw7hsgVIWWpa/s400/gmail-sorter.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5205353659286411954" /></a><br /><br />Clicking on the links asc/desc sorts visible threads by sender, subject or thread activity. Actually I wrote this bookmarklet mainly for the thread activity feature. Sometimes I don't have time to check community messages, until I come back after several days to see a lot of unread messages there. I wished there could be a way to sort them by their activity: threads that more people have replied on seems more interesting, I need to read them first.<br /><br />The bookmarklet is heavily based on <a href="https://www.squarefree.com/bookmarklets/pagedata.html#sort_table">another bookmarklet</a> which adds sort controls to all tables in page. Actually what I did was customizing that bookmarklet to work on GMail Inbox and adding different sort criteria. The sorting code is taken almost as is.<br /><br />If you just need to use the bookmarklet and don't care about some implementation details, you can skip to section "How to install" below.<br /><br /><h3>How GMail Sorter is different</h3><br /><br />Let me refer to that bookmarklet as B and mine as M. In B, all tables are tampered. In M only the Inbox table is tampered. It was a challenge finding the Inbox. Guys at Google seem to obfuscate ids and class names for all DOM elements. For example, they are something like 1d3f, 3xua,...<br />I attacked this issue by finding the "widest table". The Inbox table happens to be the 2nd widest table, where the notification area that appears on top of the table is the 1st widest one. However, the Inbox table does have an id and the notification area does not. So I find it by getting the widest table having an id:<br /><br /><code><br />function getWidestTable(tables) {<br /> var maxTable = undefined;<br /> var maxWidth = -1;<br /> for (var i = 0; i < tables.length; i++) {<br /> var table = tables[i];<br /> if (table.clientWidth >= maxWidth && table.id != '') {<br /> maxWidth = table.clientWidth;<br /> maxTable = table;<br /> }<br /> }<br /> return maxTable;<br />}<br /></code><br /><br />Applying B on GMail will give you an alert: "This page does not contain any tables". Wow, all these tables and B can't find it! The problem is that B searches for table tags in current document. In M, I had to iterate through all iframes and search in tables in their documents. Shortly I discovered that the Inbox table exists in an iframed named "canvas_iframe", so the code became a little simpler:<br /><br /><code><br />function getAllTables() {<br /> g_tables = toArray(document.getElementsByTagName('table'));<br /> var iframe = document.getElementById('canvas_frame');<br /> if (!iframe) return null;<br /> var iframedoc = iframe.contentDocument.document || iframe.contentWindow.document;<br /> iframetables = toArray(iframedoc.getElementsByTagName('table'));<br /> if (iframetables.length)<br /> g_tables = g_tables.concat(iframetables);<br /> if (!g_tables.length)<br /> return null;<br /> return g_tables;<br />}<br /></code><br /><br /><h3>How to install:</h3><br />In Firefox, Just create a new bookmark and paste the following code in the URL:<br /><br /><code><br />javascript:function toArray (c) {var a, k;a = new Array;for (k=0; k < c.length; ++k)a[k] = c[k];return a;}function insAtTop(par,child) {if (par.childNodes.length)par.insertBefore(child, par.childNodes[0]);else par.appendChild(child);}function countCols(tab) {var nCols, i;nCols = 0;for(i = 0; i<tab.rows.length; ++i)if (tab.rows[i].cells.length > nCols)nCols = tab.rows[i].cells.length;return nCols;}function makeHeaderLink(colNo, ord, regex, numeric) {var link;link = document.createElement('a');link.href = '#';link.onclick = function() {var __st = window == top ? window : top;__st.sortTable(colNo, ord, regex, numeric);return false;};link.appendChild(document.createTextNode((ord>0)? 'asc':'desc'));return link;}function makeSortControl(header, col, title, regex, numeric) {header.appendChild(document.createTextNode(title + ' ['));header.appendChild(makeHeaderLink(col, 1, regex, numeric));header.appendChild(document.createTextNode('/'));header.appendChild(makeHeaderLink(col, -1, regex, numeric));header.appendChild(document.createTextNode(']'));}function makeHeader(nCols) {var header, headerCell, i;header = document.createElement('span');/*put links in columns 2 and 4 only (sender, subject)*/makeSortControl(header, 2, 'Sender(s)');header.appendChild(document.createTextNode(' | '));makeSortControl(header, 4, 'Subject');header.appendChild(document.createTextNode(' | '));makeSortControl(header, 2, 'Thread Activity', /\(\d*\)$/, true);return header;}function getWidestTable(tables) {var maxTable = undefined;var maxWidth = -1;for (var i = 0; i<tables.length; i++) {var table = tables[i];if (table.clientWidth >= maxWidth && table.id != '') {maxWidth = table.clientWidth;maxTable = table;}}return maxTable;}function getAllTables() {g_tables = toArray(document.getElementsByTagName('table'));var iframe = document.getElementById('canvas_frame');if (!iframe)return null;var iframedoc = iframe.contentDocument.document || iframe.contentWindow.document;iframetables = toArray(iframedoc.getElementsByTagName('table'));if (iframetables.length)g_tables = g_tables.concat(iframetables);if (!g_tables.length)return null;return g_tables;}(function () {/* ---- main() ---- ENTRY POINT HERE ------------------------- */g_tables = getAllTables();if (!g_tables) {alert("It seems that this script is not compatible with your gmail version (no tables), giving up!");return;}inboxtable = getWidestTable(g_tables);if (inboxtable.id.length<4) {alert("It seems that this script is not compatible with your gmail version (no inbox), giving up!");return;}var control = makeHeader(countCols(inboxtable));var tableparent = inboxtable.parentNode.parentNode;while(tableparent.previousSibling.style.display == 'none')tableparent = tableparent.previousSibling;tableparent.previousSibling.appendChild(control);/*tableparent.parentNode.insertBefore(control, tableparent);*/}) ();function compareRows(a,b) {if (a.sortKey == b.sortKey)return 0;return (a.sortKey < b.sortKey) ? g_order : -g_order;}function compareRowsNumeric(a,b) {if (a.sortKey == b.sortKey)return 0;return ((a.sortKey + '').match(/\d+/) - (b.sortKey + '').match(/\d+/)) * g_order;}function sortTable(colNo, ord, regex, numeric) {var table, rows, nR, bs, i, j, temp;g_order = ord;g_colNo = colNo;g_tables = getAllTables();table = getWidestTable(g_tables);rows = new Array();nR = 0;bs = table.tBodies;for (i = 0; i < bs.length; ++i)for(j=0; j < bs[i].rows.length; ++j) {rows[nR] = bs[i].rows[j];temp = rows[nR].cells[g_colNo];if (!temp)rows[nR].sortKey = '';else if (!regex)rows[nR].sortKey = temp.textContent.toLowerCase();else {var val = temp.textContent.toLowerCase().match(regex);rows[nR].sortKey = val ? val : '';}++nR;}if (numeric)rows.sort(compareRowsNumeric);else rows.sort(compareRows);for (i = 0; i < rows.length; ++i)insAtTop(table.tBodies[0], rows[i]);}<br /></code><br /><br />Put it in the Bookmarks Toolbar folder so that it is always visible. Anytime you need to enable the bookmarklet, open your Inbox view (or any messages view) and click on the bookmark you have just created. You will see a sort control added on top of the table. Play and enjoy!<br /><br /><h3>How to modify:</h3><br />If you are a Javascript geek and need to play with the code, <a href="http://downloads.hammady.net/sorttables.js">here</a> is a clear source where you can play with. After playing you will have to remove all new lines and prepend "javascript:" to form a valid URL that will fit in a bookmark. Don't worry, here is a one-liner to do this task:<br /><code><br />(echo "javascript:" ; cat sorttables.js) | tr -d "\n\t" > sorttables_bookmarklet.js<br /></code><br />This will read in the file sorttables.js that contains your code and outputs a file sorttables_bookmarklet.js where you can grasp its contents and paste it in your bookmark URL.Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com2tag:blogger.com,1999:blog-1427064072400819258.post-80287076980443011972008-05-08T13:42:00.001+02:002008-05-08T13:44:56.836+02:00Upgrading unupgradable Firefox extensions<div class="content"><br /> <p>To their bad fortune, many of you may have already upgraded to Firefox 3 beta. Ouch!<br />You may have also tried to upgrade your extensions and found most of them failed to do :(<br />Now you have either of 2 solutions:<br /></p><br /><ol><li> downgrade back to Firefox 2<br /></li><li> force upgrade of your extensions<br /></li></ol><br /><p>"2" seems nice, huh?<br />OK, lets go straight, now follow me on these:<br /></p><br /><ol><li> Any extension is an .xpi file (pronounced as zippy), download the .xpi. If you click on a .xpi link in Firefox it will be installed instead, so you can get it with any other browser, or right-click and Save as... You can also type the following in a shell: <code>wget XPI_URL</code><br /></li><li> Extract the .xpi with any archive manager (it is actually a ZIP file renamed)<br /></li><li> Open install.rdf with any text editor<br /></li><li> Locate the line: <em:maxVersion>...</em:maxVersion> and replace this value to something like 3.0b5. This will make your extension <i>pretend</i> to work on up to FF3 beta5!<br /></li><li> Now zip back your files and drag on any Firefox open window and it will automatically install.<br /></li><li> Enjoy!<br /></li></ol><br /><p><b>IMPORTANT</b>:<br /></p><br /><ul><li> The new archive you created in step 5 MUST have the extension .xpi<br /></li><li> Files in the archive should be directly on the root not inside an internal directory<br /></li><li> The extension will claim to work on your browser, but it may not function as you expect, simply because the extension maker did not test it on your version. So forcing it to work is solely on your responsibility with NO WARRANTY!<br /></li></ul><br /> </div>Anonymoushttp://www.blogger.com/profile/17387936164476486881noreply@blogger.com0