Friday, January 30, 2009

Cookies


Share/Bookmark

Thursday, January 29, 2009

Angle of Vectors by Dot Product in 3D space


Dot product of two vectors with the same number of components shows the angular relationship between two vectors.
A = Ax(i) + Ay(j) + Az(k)
B = Bx(i) + By(j) + Bz(k)

(i), (j), and (j) in above vectors represent unit vectors which are belong to x, y, and z coordinate direction and projection of vector A along the x, y, and z axis are presented by Ax, Ay, and Az.

The magnitude f a vector in 3D X-Y-Z coordinate system can be calculated as following:
|A| = Sqrt( Ax * Ax + Ay * Ay + Az * Az )

...
vecAlen = Math.Sqrt( Math.Pow(Ax, 2.0) + Math.Pow(Ay, 2.0) + Math.Pow(Az, 2.0) )
...

The dot product of vectors A and B is equal to vector A magnitude multiply by vector B magnitude multiply by cosine of angle between the two vectors (teta).
A.B = |A| * |B| * Cos(teta)

it results the following facts too:
(A.B = B.A) and also we know (A.A = |A| * |A|) because teta is 0 and Cos(0) is equal to 1.

In 3D X-Y-Z rectangular coordinate system the dot product can be evaluated from the relation:
A.B = Ax * Bx + Ay * By + Az * By

The proof of above relation comes from the facts that related to unit vectors in rectangular 3D X-Y-Z coordinate system which presented by 90 degree angle between Axis directions:
(i) . (j) = (i) . (k) = (j) . (k) = 0
(i) . (i) = (j) . (j) = (k) . (k) = 1

Now if we want to calculate angle between the A and B are unit vectors (vectors with magnitude of 1), then simply we have:
A.B = Cos(teta)
teta = arcCos( A . B )

The code can be something like this:
public struct vector
{
   public double Vx;
   public double Vy;
   public double Vz;
}
...
public double vecsAngle(vector A, vector B)
{
 double dotPrdct = A.Vx*B.Vx + A.Vy*B.Vy + A.Vz*B.Vz;
 return Math.Acos( dotPrdct ) * 180 / Math.PI;
}

Share/Bookmark

Tuesday, January 27, 2009

SQL - Recursive Queries by CTE

CTE (Common Table Expression) is very useful when we want to perform recursion by defining a self referencing query. In Northwind Database sample (downloadable from CodePlex web pages) Employees table has a column with title of ReportsTo which refers to EmployeeID of another Employee record in current Employee row, it's the manager. The exception is for the managers who their ReportsTo column is NULL (They are lucky people who don't need to report to any body, watch out, it shows you are responsible not them!). Then the managers are sitting in Level 1 and employees are in next levels. Then employees report to their manager who are in upper level. It shows the table has a reference to itself, it's a join back that is possible to implement by utilizing power of recursive connection.

To cover all the sub levels and show Employees and their managers, we need to UNION result set of multi levels all together and go deep inside till find all requested info. Each time that the query needs to go one level deeper, the Level column adds by 1 to show the correct level of employee in organization diagram.

WITH Emp (EmpID, EmpName, ManagerID,
ManagerName, [EmployeeLevel] )
AS
(
SELECT EmpTbl.EmployeeID,
EmpTbl.LastName,
EmpTbl.ReportsTo,
EmpTbl.FirstName+SPACE(1)+EmpTbl.LastName, 1
FROM [Northwind].[dbo].[Employees] as EmpTbl
WHERE ReportsTo IS NULL
UNION ALL
SELECT EmpTbl.EmployeeID,
EmpTbl.LastName,
EmpTbl.ReportsTo,
Mgr.FirstName+SPACE(1)+Mgr.LastName,
[EmployeeLevel] + 1
FROM [Northwind].[dbo].[Employees] as EmpTbl
JOIN Emp
ON Emp.EmpID = EmpTbl.ReportsTO
JOIN [Northwind].[dbo].[Employees] as Mgr
ON EmpTbl.ReportsTO = Mgr.EmployeeID
)
SELECT EmpID,
EmpName,
ManagerID,
ManagerName,
[EmployeeLevel]
FROM Emp

Output:

2 Fuller NULL Andrew Fuller 1
1 Davolio 2 Andrew Fuller 2
3 Leverling 2 Andrew Fuller 2
4 Peacock 2 Andrew Fuller 2
5 Buchanan 2 Andrew Fuller 2
8 Callahan 2 Andrew Fuller 2
6 Suyama 5 Steven Buchanan 3
7 King 5 Steven Buchanan 3
9 Dodsworth 5 Steven Buchanan 3

Share/Bookmark

Monday, January 26, 2009

Free - Taskbar Button Manager (Innovative Solutions)

If you are looking for a utility to make you able to arrange your buttons on windows taskbar in way which you want and just by drag n drop the buttons, then go to load this perfect utility:
Taskbar Button Manager

It's free and works on Windows XP, after 30 days it needs a registration code which comes also for free.

I was looking for it, found it, and now I enjoy having it on my system.
Share/Bookmark

Free Virus Scanners

Free Virus Scanners

http://free.avg.com/
http://www.kaspersky.com/virusscanner
http://security.symantec.com
http://us.mcafee.com/root/mfs/scan.asp?affid=56
http://www.bitdefender.com/scan8
http://onecare.live.com/site/en-us/default.htm
http://www.eset.com/onlinescan/
http://www.avast.com/eng/download-avast-home.html
http://ca.com/securityadvisor/virusinfo/scan.aspx
http://www.ewido.net/en/onlinescan
http://www.pandasecurity.com/homeusers/solutions/activescan
http://www.trendsecure.com/portal/en-US/tools/security_tools/housecall
http://www.clamwin.com/
http://www.clamav.net/
http://www.free-av.com/
http://www.radialpoint.net/home/
http://www.f-prot.com/ (Trial)
CyberDefender Early Detection Center - Trial Edition
Share/Bookmark

Sunday, January 25, 2009

The Internet browser Embedded Objects

Users can view non-HTML contents by embeded objects. For example to watch a flash animation, listen to a RealAudio audio, watch a QuickTime movie or many other non-HTML documents or media entities, a browser need to take advantage of embedded objects. It's possible to check client browser to see if required embedded object is installed or not.

Internet Explorer uses Microsoft ActiveX components to load other applications and support embedded objects and FireFox uses the Netscape Plugin Application Programming Interface (NPAPI) system. FireFox does not officially support ActiveX. (Mozilla and ActiveX)

Which properties keep the name of available embedded objects in the Internet browser?

The document.embeds[] array contains a list of all the objects embedded in a document which are applied by the <OBECT> tag for IE and the <EMBED> tag in Mozilla.

The document.applets[] works for <APPLET> tag in the web page codes and contains all the applets embedded in a document as Java Applet although <OBJECT> and <EMBED> are recommended instead of using <APPLET>.

The navigator.plugins[] array contains all the plug-ins that Mozilla supports like Adobe Acrobat.

The navigator.mimeTypes[] array contains all the MIME types supported by Mozilla. MIME is Multipurpose Internet Mail Extension, It related to the file types that Mozilla can understand and display. MIME is a component for communication protocols (HTTP) and also it defines methods for transferring binary data in ASCII text format as a message and more.

The navigator.plugins[] and navigator.mimeTypes[] arrays in IE are null cuz IE uses ActiveX to implement embedded objects instead of plug-ins, then in IE document.embeds[] array detects embedded contents.
Share/Bookmark

Saturday, January 24, 2009

How to find referrer page (JavaScript)

The referrer page is the page that user loaded before loading your web page. It's useful if you are interested to find visitors of you web page came from which URL to see your web pages.

Simply enough, the referrer property of the document object, identifies the referrer page URL.

If the value of document.referrer is blank ("") , then it shows user loaded up your page directly by typing its URL into the browser address field.

Just be notified that the value of document.referrer is blank if you test an HTML page locally in your machine.

if (document.referrer != "") {
   document.writeln("Ref page: " + document.referrer);
}
else
{
   document.writeln("Page loaded up from fresh.");
}

Share/Bookmark

Free - Download Windows 7 Beta CPP

If you are eager to try the Windows 7 Beta Customer Preview Program, go for the following URL (You can find a lot about it over there):
http://technet.microsoft.com/en-ca/windows/dd361745.aspx

Mark Russinovich: Inside Windows 7
http://channel9.msdn.com/shows/Going%20Deep/Mark-Russinovich-Inside-Windows-7/

One very important change in the Windows 7 kernel is the dismantling of the dispatcher spin lock and redesign and implementation of its functionality. The direct result of the reworking of the dispatcher spin lock is that Windows 7 can scale to 256 processors.
Share/Bookmark

How to determine the version of .NET framework in your system - Two

Internet Explorer DOM (Document Object Model) has a navigator object and there is a userAgent properties which shows browser application name and also version of .NET Framework which installed on your system. To query this property (userAgent) simply enter the following line in address bar, the alert method in javascript will show the result in a message window.

javascript:alert(navigator.userAgent)


Share/Bookmark

Friday, January 23, 2009

How to determine the version of .NET framework in your system - One

Locate the following folder (you can use Windows Explorer):
%systemroot%\Microsoft.NET\Framework

The following folders contain the released versions of the .NET Framework:
Folders with vN.N.NXXXX format, contain beta or pre-released versions.
* v3.5
* v3.0
* v2.0.50727
* v1.1.4322
* v1.0.3705

Find Mscorlib.dll inside each of the above mentioned folders, right click on it, click on Properties, click on [Details] tab and check [Product version]

To find all the version numbers, look at the following URL in [Microsoft Help and Support] web pages:
http://support.microsoft.com/default.aspx/kb/318785


Share/Bookmark

Thursday, January 22, 2009

C# - How to run a program in DOS command

The approach that comes in the following, could similarly be used to run command line tools, and DOS commands.

public bool runAcmd(string strCmd, string strCmdWorkDir)
{
// "strCmd" can contain command line arguments
bool returnVal = true;
Process prcs;
ProcessStartInfo psi = new ProcessStartInfo();

psi.FileName = "cmd";
psi.Arguments = " /c " + strCmd;
psi.WorkingDirectory = strCmdWorkDir;
psi.WindowStyle = ProcessWindowStyle.Hidden;

try
{
   prcs = Process.Start(psi);
   // wait value is in milliseconds
   if (!prcs.WaitForExit(10000))
      returnVal = false;
}
catch (Exception ex)
{
   returnVal = false;
}
finally
{
   // Some lines of code to execute in
   // case of error or not, if necessary
}
return returnVal;
}

Share/Bookmark

Wednesday, January 21, 2009

Free: Zoho (Work. Online)

Do you want to work online? It looks green too!
ZOHO http://www.zoho.com/

Zoho is a suite of online applications which are free for individuals and some have a subscription fee for organizations.

ZOHO Productivity applications:
Zoho Mail (Web-based Email Service)
Zoho Writer (Online Word Processor)
Zoho Sheet (Spreadsheets. Online)
Zoho Show (Online Presentation Tool)
Zoho Docs (Online Document Management)
Zoho Notebook (Online Note Taker)
Zoho Wiki (Easy to use, full-featured Wiki)
Zoho Share (Centralized Public Repository)
Zoho Planner (Online Organizer)
Zoho Chat (Make Group Decisions Faster)

ZOHO Business Apps:
Zoho CRM 3 Users Free (On-Demand CRM Solution)
Zoho Projects (Project Management Software)
Zoho Creator (5 Users Free) (Online Database Application)
Zoho Invoice 5 Invoices Free (Online Invoicing. Quick and Easy)
Zoho Meeting One on One Free (Web Conferencing, Remote Support)
Zoho DB & Reports (Online Reporting & BI Service)
Zoho People 10 Users Free (HRIS & Applicant Tracking System)
Zoho Business 10 Users Free (Online Business Solutions)
Zoho Marketplace (Apps for your Business needs)

Utilities by ZOHO:
Site 24x7 (Website Monitoring Service)
Zoho Polls (Online Polls in a snap)
Zoho Viewer (View and Share Documents Online)
Zoho Challenge (Easiest Way to Evaluate Candidates)
Share/Bookmark

Monday, January 19, 2009

How to pass command line arguments for debugging

To pass command line arguments for debugging purposes when you are developing your code with Visual Studio 2005, follow the following sequences:
- In Solution Explorer, right click on your project name
- In appeared context menu, click on "Properties"
- In "Properties" window, click on "Debug"
- In "Start Option" part of page, you can find "Command line arguments" text box


The following picture shows passing command line arguments in a C++ project in Visual Studio when you have opened "Properties" windows to access to debugging options:


Share/Bookmark

Sunday, January 18, 2009

SQL - CASE WHEN THEN ELSE END

T-SQL CASE check conditions and returns result expressions if it find the first
condition logical true value.

Two version of CASE is available:

1- Searched CASE expression:

CASE
WHEN Boolean_expression THEN result_expression [..n]
[ ELSE else_result_expression ]
END

- For each WHEN in CASE expression it evaluates the conditional expresiion in front of WHEN
- It return the first result_expression of the first TRUE conditional expression in order.
- If no conditional expression is TRUE, then it returns else_result_expression if an ELSE clause is specified.
- If no conditional expression is TRUE and there is no ELSE clause, it returns a NULL value.

Example:

use AdventureWorksLT
SELECT [name], [listprice],
CASE
WHEN [color] = 'Black' THEN [listprice] * 0.9
WHEN [color] = 'Red' THEN [listprice] * 0.45
WHEN [color] = 'White' THEN [listprice] * 0.6
ELSE
[listprice]
END as discountPrice
FROM [AdventureWorksLT].[SalesLT].[Product]

2- The simple CASE expression:
Operates by comparing the first expression to the expression in each WHEN clause.
If equal, the expression in the THEN clause will be returned.

CASE input_expression
WHEN when_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ]
END

- It evaluates input_expression, and in the order specified for each WHEN clause
- It checks to see if when_expression is equal to input_expression.
- It returns the result_expression of the first match as explained above.
- If no input_expression equals to when_expression, it returns the else_result_expression if an ELSE clause is exist.
- If no input_expression equals to when_expression and ELSE clause is not exist, it returns a NULL value.

Example:

SELECT [name], [listprice],
CASE [color]
WHEN 'Black' THEN 'In stock'
WHEN 'Red' THEN 'Sold out'
WHEN 'White' THEN 'On web'
WHEN 'Blue' THEN 'In order'
ELSE
'CALL'
END as availability
FROM [AdventureWorksLT].[SalesLT].[Product]

Note:
CASE in both formats support an optional ELSE argument.
CASE can be used in any statement or clause that allows a valid expression,
such as SELECT, UPDATE, DELETE and SET, and also in IN, WHERE, ORDER BY, and ...

enjoy using CASE !
Share/Bookmark

Friday, January 16, 2009

C# - How to activate another application?

There is not a managed library who offer this function for C#. The solution is using AppActivate method of Microsoft.VisualBasic .NET library in your code.

* First it's necessary to add Microsoft.VisualBasic.dll in References for your solution, If you try "Add Reference ..." you will find it in ".NET" page tab in new opening window.

* Next, you need to include Microsoft.VisualBasic namespace to your code

* Then you can activate another application by the application title or Its ProcessID as following:
...
using Microsoft.VisualBasic
...
Interaction.AppActivate("App Title or ProcessID");

Note: If your application is minimized, it will be activated but AppActivate does not restore the application window (it doesn't come up).
Share/Bookmark

Thursday, January 15, 2009

C# - Shutdown or Restart MS Windows

To Shutdown:
System.Diagnostics.Process.Start("ShutDown", "/s");

To restart:
System.Diagnostics.Process.Start("ShutDown", "/r");

List of all possible arguments are as following:

-r Shutdown and restart the computer
-s Shutdown the computer
-t xx Set timeout for shutdown to xx seconds
-a Abort a system shutdown
-f Forces all windows to close
-i Display GUI interface
-l Log off

Share/Bookmark

Sunday, January 11, 2009

150 million users for Facebook !

Facebook has almost 75 million daily users in 170 countries and on every continent.

http://www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9125421&source=rss_news
Share/Bookmark

Saturday, January 10, 2009

Like great art, great software doesn’t just happen

o a bit of planning first, and decide exactly what you want your application to do. When you have a clear idea in mind, take a few minutes to write your thoughts down on a piece of paper. This phase is known as the requirements phase (Notice that the requirements can be in your own words). Collect info, plan it, design and thenimplement, now you need to test your application. You can’t test something if you don’t know exactly how it’s supposed to work !
Share/Bookmark

Wednesday, January 7, 2009

Windows 7 upgrades for Windows Vista machines buyer as of July 1

If you have a plan to buy another Vista machine but you are afraid of losing your money when the Windows 7 show up, don't worry if you planed it to do after July 2009!

To find out more, look at the Mary Jo Foley post:
http://blogs.zdnet.com/microsoft/?p=1791
Share/Bookmark

Tuesday, January 6, 2009

BUG in Microsoft.JScript evaluator

I encountered with an interesting mis calculation (bug) on Microsoft.JScript expression evaluator.

It calculates the following expression:
"-180.188+38.1-19.05-(57.15)+142.088+19.05+57.15+76.2-19.05-(57.15)"

It returns "-7.105427357601E-15" instead of 0 (Zero)


To Evaluate an expression in a C# class, we need to add Microsoft.JScript and call Eval.JScriptEvaluate method:
using Microsoft.JScript;
...
public static string EvalJScript(string equation)
{
return Eval.JScriptEvaluate(equation, Vsa.VsaEngine.CreateEngine()).ToString();
}

Share/Bookmark