Friday, December 11, 2015

The beauty of UI dev in Winform

Writing an app with beautiful UI in Winform is not an easy task, especially if you don't get the amount to buy component from big companies.

However with litle time an effort you can achieve nearly perfection in UI design with Winform. Throughout the last couple days, I have been playing around UI design in order to make one of our app stand-out. WPF is great, but we do not have time and money to spend WPF tools and coordinated workflow. We do not have an in-house designer either.

This is what I have been able to achieve on our Pharma Express  which is based on our business app framework  Baboon.




Pretty neat hein? along the way I have put together an image Library usable throughout many other applications; You can use the resource browser to copy the name of the icon and use it in code. 

The ImageLibrary contains iconsets from famfam, Fugu, eclipse IDE, VS 2010, V2012 and VS2013. To use it in your application, just add the Baboon.ImageLibrary.dll to your project as a reference. 




Button btn=new Button();
btn.Image=global::ImageLibrary.Fugu.fugu_scissors__plus_16;

Download Link: https://drive.google.com/file/d/0B0rIFKEc-5PYT0NHSUxmVnU5VXc/view?usp=sharing

Friday, December 27, 2013

Namespace in Javascript

Structuring javascript code by using namespace is a great way to organise source code. However because javascript does not have namespace built-in feature ; it becomes verbous to create and use namespaces. one of the javscript library that makes use of namespace heavily is Qooxdoo . In this framework you create an instance of button like this:
 var button = new qx.ui.form.Button("Button");

First of all, lets create namespace in javascript.
//create an empty object that is the root of the namespace 
var com={}; 
//any other sub-namespace should be explicitly or implicity delcared as object
com.evansofts={};


com.evansofts.lib={
	hello: function(){
		console.log('Hello from com.evansofts.lib');
	}
}

com.evansofts.main={
	hello: function(){
		console.log('Hello from com.evansofts.main');
	}
}


	hello();//this won't work as hello is undefined on the global namesapce
As a side note, the global namespace is the window object. In order to call our functions we need to fully qualify their name like this :
	com.evansofts.lib.hello()
	com.evansofts.main.hello();
As you can see we need to type the namespace all the way down to our function com.evansofts.lib.*in order to access it. Wouldn't be great to uses statement like inport or using as in java and C# respectively. well we can implements such utility function. Since javascript namespaces in the way it's defined are just objects, the idea is to attache these objects to the global namespace window. that way we can access all the properties of those objects from the global namespace. A simple solution will be to create a utility function like this :
	function using(object,as){
		window[as]=object;
	}
Assuming you call the function like this using(com.evansofts.lib, 'library') , you can now do library.hello() in your code without any worries. You will notice that we have successfully bound the namespace. Now I would like to add that syntactic sugar to our utility function; I would like us to use it in this way using(com.evansofts.lib).as('library'). This syntaxe clearly explain the purpose of this function. So we will redefine our function like this:
	function using(object){
		this.as=function(alias){
			window[alias]=object;
		}
		return this;
	}
This litle change will allow us to use the function like so:
	using(com.evansofts.lib).as('library');
	library.hello();
	com.evansofts.main.hello(); //notice the namespaces are still consistent
Some people will say well we still have to type library.* in order to access object of the namespace. Can we pull everything to global namespace? Yes is the answer. You will just have to loop through the namespace and add all its objects and properties to the global namespace wich is the window. However, if you plan doing that, then there is no point to create namespaces in you code as you will be removing the organisation you brought in your code by introducing namespaces.

Friday, December 16, 2011

The fibonacci series using memoization

Another algorithm today...
This is the Fibonacci series implemented with memoization .

int fibonacci(int n){
 int prev=0;
 int next=1;
 int val=0;
 for(int i=2;i<=n;i++){
  val=next+prev;
  prev=next;
  next=val;
 }
 return val;
}

Typically, If you are designing a maths library, you would implement a caching mechanism to avoid reprocessing again. A better  way in term of performance would be :

int fibonacci(int n){
 static vector<int> cache(0);
 //check if we have already processed
 if(n<cache.size()){
  cout<<"from cache: ";
  return cache.at(n);
 }
 
 //initial values 
 if(cache.size()==0){
  cache.push_back(0);
  cache.push_back(1);
 }
 
 //we calculate the fibonacci from where the cache end to the number requested
 for(int i=cache.size()-1;i<=n;i++){
  cache.push_back( cache.at(i) + cache.at(i-1) );
 }
 cout<<"Calculated : ";
 return cache.at(n);
}

the cout is embedded for simple debugging.

Wednesday, December 14, 2011

Matching parenthesis in arithmetic expressions with c++

This is a simplinstic way of testing if an expression is correctly grouped using stack based method.
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main (int argc, char *argv[]){
	vector<char> expr_validator;
	string expression="2[(a-9)/(2-b)]/(x-2)-[(4*(x-8)+4)/(5x+17)]";
	for(int i=0;i<expression.length() ;i++){
		switch(expression[i]){
			case '(':
					expr_validator.push_back(expression[i]);
				break;		
			case ')':
					if('('==expr_validator.back())
						expr_validator.pop_back();
					else
						expr_validator.push_back(expression[i]);
				break;
			case '[':
					expr_validator.push_back(expression[i]);
				break;
			case ']':
					if('['==expr_validator.back())
						expr_validator.pop_back();
					else
					expr_validator.push_back(expression[i]);
				break;					
		}
	}	
	
	if(expr_validator.empty()){
		cout << "Good Expression" << endl;	
	}else {
		cout << "Bad Expression" << endl;
		cout<<	expr_validator.size() ;
	}
	return 0;	
}

Thursday, December 1, 2011

About this blog

Just another blog about c/c++  , Qt , STL,  C# Winform ,WPF,  PHP Zend framework, CI , Yalamo , and javascrip ...