This blog is subject the DISCLAIMER below.

Sunday, December 11, 2011

FCIH Initiative family call for new members

FCIH initiative is group of FCIH graduates who are interested in passing their experience & knowledge to FCIH students. The kick off was on 7 November 2009; during these two years, we managed to hold number of sessions and  Java training.


We think of the initiative as our role towards the society and as a chance to help others find their way in life. Currently, we are hoping to add new members to FCIH  initiative family. Kindly, if you are interested, take a few minutes to fill  this form, if you are already a member please fill the form as well.


Please, feel free to spread the word to other FCIH graduates who might be interested.

.. more.

Wednesday, November 16, 2011

Currying


In this post we will talk about currying, why you may need it, how to implement it with different paradigms (OOP, meta-programming, and functional).

Let's first talk about motivation. Consider the simple scenario where you have a list of integers, and you want to filter it to extract only the integers you want. For instance this list could be a list of user IDs, and you want to extract only the users who are late in their payments to send them an email. 

It is pretty much straight forward to do it in a loop; but we want a clearer way that focuses on semantics. For example consider something like 

send_email_to(select_from(all_users, payment_due))

I've colored payment_due in red to make it clear its a function, not a variable. The function select_from could contain the loop structure (and maybe some database processing), where in each loop they apply the function payment_due to some user like this:

select_from(list, test)
{
  selected = {};
  for(i=0; i < list.length; i++)
    if(test(list[i]) == true)
      append(selected,list[i])
  return selected;
}

Notice that the function payment_due must be a function that takes only one parameter, because that is how it will be called from inside select_from. In most languages which have first-class functions there is a built-in function which acts like select_from, exactly for this kind of purpose. This includes C++ and all functional programming languages. In C++11 it is called copy_if (it was dropped from C++ by accident).

Consider another «test» function that takes as argument a user ID, and returns true if the user’s monthly salary is more than 3000. That could be written as:

salary_greater_than_3000(user)
{
   return user.salary > 3000;
}

send_email_to(select_from(all_users, salary_greater_than_3000))

Maybe we have something like this:

salary_greater_than_x(user,x)
{
   return user.salary > x;
}

salary_greater_than_3000(user)
{
   return salary_greater_than_x(user,3000);
}

send_email_to(select_from(all_users, salary_greater_than_3000))

C++ macros won’t do the same thing as above, but C++ STL bind2nd (which is also compile-time meta-programming) can do the same thing.

If we don’t know the value 3000 at compile time and instead we only have it in run-time, we can’t do this call select_from(all_users, salary_greater_than_x). This wouldn’t work because select_from expects a function taking one parameter only.

In C++ this could be fixed by using a functor, which is a class which overrides operator(), and hence could be used as a function. For example (this example is valid C++, not just pseudo code as the previous examples):

class salary_greater_than_x
{
   const int x;
   public: salary_greater_than_x(int x): x(x){}
   bool operator()(User user) { return user.salary() > x; }
}

send_email_to(select_from(all_users, salary_greater_than_x(3000)))

Lambda expressions does the same thing exactly, without the need to write a class for it. In C++11 (which supports lambda epxressions) that would be like:

send_email_to(select_from(all_users, [](User user){salary_greater_than_x(user,3000)}))

The lambda expression, just like the functor, stores the value 3000, which is a sort of a closure.

Lambda expressions is too powerful; you can define arbitrary functions. We don’t need all that power, we only need to fix one argument of another function. This is what currying does. For instance, we know that salary_greater_than_x takes two arguments. If the language we are using supports implicit currying (like Haskell) if we omitted the second parameter we end up with a function whose first parameter is fixed. Concretely speaking we can do this (notice I switched the first and second parameters in the definition of salary_greater_than_x) :

salary_greater_than_x(x, user)
{
   return user.salary > x;
}

salary_greater_than_3000 = salary_greater_than_x(3000)

send_email_to(select_from(all_users, salary_greater_than_3000))

or simply just :

send_email_to(select_from(all_users, salary_greater_than_x(3000)))



.. more.

Tuesday, July 12, 2011

Announcement: FCIH Initiative


FCIH Initiative….FCIH Revolution

If you love your country and want to take effective steps to raise Egypt
If you're seeking development, freedom, knowledge and science

So, you're a proactive Egyptian and FCIan and should join our FCIH Revolution
A revolution of knowledge, learning, working and a revolution of dreams

We're all together; FCIH Graduates and Students
We're all here to help each others; we're all here to develop our skills
Together, we'll have a better world, we'll have a better tom, and we'll have a better Egypt

We'll attend Technical & Business sessions to know
We'll be trained to learn
We'll do projects…and then we'll be ready to achieve

Let's join and train ourselves
Let's join and know the business world from experts from each field
Let's join and start building our future and career from now

Our program will be divided into three phases:
1-      Sessions Phase:
These sessions will open us a window to the business world, discuss technical topics and tell us about the world outside FCIH
2-      Training phase:
we'll have more than one training track, each track will be delivered and leaded by a group of experts in this track, we'll learn how to learn and how to apply what we've learned
3-      Projects phase:
After all this knowledge, it'll be our chance to do and achieve. We'll develop projects simulating business cases and deliver it according to modern software engineering methodologies used in real business by leading companies.


FCIH Initiative,
Don't wait the chance, create it

Contacts:


.. more.

Thursday, March 03, 2011

"Note in (Google) Reader" issue Fix

Probably you're familiar with the sharing button (at least on Firefox and Chrome) offered by Google reader to help you share stuff that don't have feeds. Today, for some reason I realized that mine wasn't working!

GReader

 

After tweeting about it, thanks to Flavio Gomes and @mtobis, I realized what went wrong. Seems like the JavaScript file used by the button was updated, without updating the button script accordingly.

 

To solve this, all you have to do is set _IS_MULTILOGIN_ENABLED a variable that's not defined (but used) in the script file in the button script. So add something like:

_IS_MULTILOGIN_ENABLED=true;


// or


_IS_MULTILOGIN_ENABLED=false;


// or better


_IS_MULTILOGIN_ENABLED=((typeof(_IS_MULTILOGIN_ENABLED)=="undefined")?false:_IS_MULTILOGIN_ENABLED);




 



at the beginning of the button script, just to set _IS_MULTILOGIN_ENABLED before it's accessed as "undefined" in the script.

.. more.

Monday, January 17, 2011

How to solve "Silverlight.CSharp.targets was not found" problem


Friend of mine asked that she can't build any Silverlight project inside VS 2010 from http://gallery.expression.microsoft.com.
The error was similar to : 
C:\OverlappingTabs.csproj : error  : Unable to read the project file 'OverlappingTabs.csproj'.
C:\OverlappingTabs.csproj(108,3): The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

This problem runs because VS2010 came up with support for Silverlight 3 but not Silverlight 4 as Silverlight 4 had released after VS2010.

What you need is just setup "Microsoft Silverlight 4 Tools for Visual Studio 2010" about 35 MB without restarting your OS.



.. more.

Sunday, January 09, 2011

How to force undo checkout? #TFS

Sometimes you'd pop into cases where you find yourself in a situation where you have to force undo pending code changes of someone else (say a colleague who is no more around, or even temporarily) or your own pending changes if say your machine (along with your workspace on it).

Well, there a Visual Studio tool for that.. That's tf command-line utility, which you can look for in your VS directory under Common7\IDE..

Using tf has lots and lots of uses, here's a really LONG list of them. Note: there's 3 sub-lists for VS2005, 2008, 2010. But for our tiny problem here, we mainly have to options, I'm using here the most straight forward ones:

Undoing pending changes for a specific file:

That will need mainly main parameters to start with: The name/path of the file checkout, User name (of the user who did the checkout), and the Workspace in which the checkout was done (usually your machine name if you didn't create an new workspace).

You could have an issue with the third one (workspace name), so you might have to check the Workspaces command for more details, but generally a small command like the one below will do just ok in most cases:

tf workspaces /owner:UserName

Knowing the above you can easily undo the pending changes as below, note: parameters are in squiggly braces like {these}:

tf undo {file path} /workspace:{workspace};{username} /server:{TFS name/IP}

Of course the "/server" part can be removed if you're on the same server running TFS. An example with some data will look like:

tf undo $/myProject/myFile.cs /workspace:mySpace;FCIH\shady /server:FCIH_TFS

Deleting the whole workspace:

The other option is to delete the whole workspace, which in turn delete any related checkouts. A simple command for that could be:

tf workspace /delete {workspace};{username} /server:{TFS name/IP}

which with some example parameters might look like:

tf workspace /delete Shady-PC;FCIH\shady /server:10.0.0.2

UPDATE:

After a comment by Meligy, I think I needed to add this: Most of the above needs you to be logged in as an account with TFS admin privileges, check the exact required permissions for Undo, Workspace and Workspaces commands.

If you're not logged in as the appropriate account, you can append {/login:username, [password]} to provide the authorized username and password.

Meligy, also, mentioned another tool called TFS Sidekicks that can do similar stuff.

.. more.

Thursday, January 06, 2011

Silverlight: Image Carousel(3d Album)

Here is my "HelloWorld" Sliverlight application as in below picture for carousel by Sliverlight with source code as GNU GENERAL PUBLIC LICENSE.


The original code is here by Shine Draw then modified and enhanced by me.
The following are new features which I have added:
  1. Added Slider bar to view all items by scrolling.
  2. Linked the (Slider) with mouse wheel.
  3. Added a subject label related to every selected Item. 
  4. Added the ablilty to move next by selecting an arbitrary item (mouse click to the corresponding item only).
  5. Added a projection effect to every non-selected items.
  6. Added control panel to setup metadata on running time. 
     
Here is the source code with comments.
All what you need is Visual Studio 2008 or 2010 and Silverlight 3 or more (click here to get Sliverlight).
Note: 
No need to setup Microsoft Expression Blend, all effects are mathematics behind.

.. more.

Wednesday, December 29, 2010

Finding & Resolving Mysql Connection Leaks

As the title imply; we need to know why Mysql runs out of connections even if it may be configured to handle much more connections. First, most leaks come from the code, check for unclosed connections before anything. If you are using JPA/Hibernate - which is my case - you use a data source either managed by the container as a JNDI resource or a simple component used by the application.

In my application I had a lot of time debugging why mysql runs out of connections and finally I did the following to know the cause:

1- Limit the running features of your app: for example; I ran only the scheduled jobs of the system to maintain a clear log and also monitor the DBMS health slowly. Let your app run for a while till the problem happen or a suitable time has passed.
2- Mysql Admin: see the health of the DBMS from the "mysql admin" tool, if you find the connection usage rising up then we have a connection leak problem for sure.
3- show processlist: in the mysql command line tool, type "show processlist;". Notice the "Command" column of the results in front of you if you find a lot of connections marked as "Sleep" then we are on the right track for the disaster as sooner or later the connection pool will run out of connections.
4- wait_timeout: The "wait_timeout" variable tells Mysql when to consider an unused connection available for termination. for me, that was the problem, a default setting for the DB server not suitable for production or heavily loaded environments. Open the system variables tab and find the "wait_timeout" variable and check its value - default is 28880 seconds -, change this to a much lower value say 15 for example.

What caused the sleeping connections?
A data source may not close the connection after communicating with the DBMS for future use purposes, so, it puts the connection in a sleeping mode and it is the responsibility of the DBMS to terminate it as needed. What we have done in the last step is making sure the DBMS does its part in the play.

.. more.

Monday, September 20, 2010

Book Review: JasperReports 3.6.0 Development Cookbook


Two years ago I wrote a series of quick start articles here that introduce java reports development through one of the most popular open source library JasperReports. Back then the main motivation for writing such articles was the lack of good learning materials whether blogposts, books or tutorials. I remember struggling with the documentation and digging the web looking for the best practices and avoiding the unknown limitations, it formed a drawback for using the well-known open source library for technical architects who need an assisting quick reference for decision making either to choose JasperReports or another provider according to their instant needs and also it have been a real pain for frontline developers to consider more time and effort navigating the entire web looking for a good learning reference and a professional best practices guide.

Fortunately, that is a past. Recently Bilal Siddiqui has published a new book on the topic JasperReports 3.6.0 Development Cookbook which I’ve been reviewing through the last week and found it could be useful to share my impressions.

The book consists of 9 chapters; could be divided into two parts, the first one contains three chapters covers the basics of report designing using iReport v 3.6.0 through a step-by-step guiding and a dedicated chapter for enhancing the look and feel. The second part addresses the best practices for report developing e.g. using multiple data sources, Crosstabs and graphs; and finally a chapter for wrappers and consuming external swing applications as data source.

Generally, the book is useful for the beginners either designers or developers, it provides the kick start and minimize the learning time and effort to the minimum by guiding you throughout the report designing, development, testing and integrating phases and addressing the most common problems and their solutions. However, the weak points of the book are the same reasons of its strength that it scratches the surface for a better beginner look but lacks of more advanced topics, e.g. row JRXML manipulation for more flexibility, performance best practice specially working with huge datasets and caching sub-reports, also integrating reports in web application could be useful.


.. more.

Wednesday, September 15, 2010

SQLServer : How to know the last modified table in your DB

Here is simple T-SQL tip but great to be known. It was part of my task today :). It was making auditing tables for tables created after specific date.

Select * from sys.objects where type_desc= 'USER_TABLE' ORDER BY modify_date desc

type_desc : is object type in SQL and here we wrote 'USER_TABLE' as we need tables created by user.

.. more.

Monday, September 13, 2010

Do people in non-English-speaking countries code in English?

I was reading a question with the same name on Stack-Exchange Beta site for Non-programmer-related questions (aka Programmers) when I came across this answer posted by a (probably Ukrainian) developer named Igor.

Accompanied by an earlier attempt by a colleague at work to write an enum in Arabic, I tried to write this piece of code:

Strangely enough it compiled and even ran showing the expected output (10)!! Note, the order above of the 2nd & 3rd line is mingled due to RTL issues in Gist. Visual Studio will show it in the right order (or at least, a more readable order for me, copy it & past it in your IDE to know how it looks).

Off course, I’m pretty convinced that this isn’t the best practice you should follow, (check my answer to the same question). Yet, I find this really hilarious! As a matter of fact, I took the claim that it’s bad practice too much for granted to the extent that I’ve never even tired to write such a strange piece of code :D

.. more.

Wednesday, September 08, 2010

Does Google Instant really ruin SEO?

I was just reading an article I found on twitter about how Google Instant (the new Google search enhancement to be rolled out to all users soon) will ruin Search Engine Optimization (SEO) which I find kinda wrong.

First: SEO is a way to aid (content providers to provide ways to) internet users to find their way to their content. ie, it’s a mean to an end, not an end! So if Google (or Bing, etc) added new features to enhance the user experience (UX) and personalize search results that might break SEO, SEO should find a way to adapt. Killing innovation is not an option :)

SEO is not about deceiving people to direct them to your content, whether it’s relevant or not!!

Second: & that’s the main point here: As far as I can see, Google Instant is not ruining SEO as Steve claims. Search results are still gonna be shown as the good old days, the only main difference is that you won’t have to click ENTER after typing your search words. You can get instant feedback about where your search results meet your expectations or not. So if content-providers did their SEO job right, their content will show up according to the relevance of their content to the typed keywords.

So, what do you think? correct me if you can see it in any other way..

Update:

I find this tweet by @Bashmohandes more valid though:

Google Instant is cool, but I worry about advertisers, as some of their impression budgets are used while the user didn't show enough intent

.. more.

Wednesday, July 21, 2010

FCIH Initiative launch

Finally we are glad to announce the launch of
FCIH Initiative Program
On Next Sunday 25/7/2010 at FCI-Helwan
Join our great event; Join a group of carefully selected sessions highly needed in your practical life.
Event Schedule:
Day 1 [Sunday: 25-7-2010]: Let's get started
10:00
10:30
Orientation
10:30
12:30
Object Oriented Blocks
12:30
01:00
Break
01:00
02:30
Good Code
02:30
03:00
Break
03:00
04:00
English for Business
Day 2 [Monday: 26-7-2010]: Develop your path
10:00
11:30
Web Development A – Z
11:30
12:00
Break
12:00
02:00
Software Quality Engineering
02:00
02:30
Break
02:30
04:00
CV Writing and interviewing skills
Day 3 [Wednesday: 28-7-2010]: IT, World of Endless Choices
10:00
11:00
GIS: Geographic information system
11:00
12:00
CMS: Content Management System
12:00
12:30
Break
02:00
02:30
BI: Business Intelligence
02:30
03:30
RIA: Rich Internet Application
Day 4 [Thursday: 29-7-2010]: Into the business world
10:00
01:00
Agile Software Development
01:00
01:30
Break
01:30
3:00
Understanding Business Analysis
03:00
04:30
Global / Local IT Market
04:30
05:00
Closing
Don't miss the chance…..and don't forget our date "25/7/2010" at FCI-Helwan.
Waiting you there :)
Yours,
FCIH Initiative Team

.. more.