Friday, January 30, 2009
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;
}
Angle of Vectors by Dot Product in 3D space
Tuesday, January 27, 2009
SQL - Recursive Queries by CTE
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
SQL - Recursive Queries by CTE
Monday, January 26, 2009
Free - Taskbar Button Manager (Innovative Solutions)
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.
Free - Taskbar Button Manager (Innovative Solutions)
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
Free Virus Scanners
Sunday, January 25, 2009
The Internet browser Embedded Objects
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.
The Internet browser Embedded Objects
Saturday, January 24, 2009
How to find referrer page (JavaScript)
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.");
}
How to find referrer page (JavaScript)
Free - Download Windows 7 Beta CPP
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.
Free - Download Windows 7 Beta CPP
How to determine the version of .NET framework in your system - Two
javascript:alert(navigator.userAgent)
How to determine the version of .NET framework in your system - Two
Friday, January 23, 2009
How to determine the version of .NET framework in your system - One
%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
How to determine the version of .NET framework in your system - One
Thursday, January 22, 2009
C# - How to run a program in DOS command
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;
}
C# - How to run a program in DOS command
Wednesday, January 21, 2009
Free: Zoho (Work. Online)
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)
Free: Zoho (Work. Online)
Monday, January 19, 2009
How to pass command line arguments for debugging
- 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:
How to pass command line arguments for debugging
Sunday, January 18, 2009
SQL - CASE WHEN THEN ELSE END
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 !
SQL - CASE WHEN THEN ELSE END
Friday, January 16, 2009
C# - How to activate another application?
* 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).
C# - How to activate another application?
Thursday, January 15, 2009
C# - Shutdown or Restart MS Windows
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
C# - Shutdown or Restart MS Windows
Sunday, January 11, 2009
150 million users for Facebook !
http://www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9125421&source=rss_news
150 million users for Facebook !
Saturday, January 10, 2009
Like great art, great software doesn’t just happen
Like great art, great software doesn’t just happen
Wednesday, January 7, 2009
Windows 7 upgrades for Windows Vista machines buyer as of July 1
To find out more, look at the Mary Jo Foley post:
http://blogs.zdnet.com/microsoft/?p=1791
Windows 7 upgrades for Windows Vista machines buyer as of July 1
Tuesday, January 6, 2009
BUG in Microsoft.JScript 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();
}
BUG in Microsoft.JScript evaluator