Wednesday, December 23, 2009
Quantum Computing's potential: impossible to ignore
What's the minimum number of steps you need to solve a N-by-N system of linear equations ? at least N steps.
What's the minimum time you need to factor an integer of N bits ? 2^N steps. Cryptographic security relies on this fact.
However all these answers are wrong in quantum computing !
In quantum computing to find an item in an unsorted list of 1,000,000 items you need only Sqrt(1,000,000) = 1000 steps! [1,4]
In quantum computing to solve a system of N linear equations you need Log(N) steps ! [2]
In quantum computing to factor a N-bits integer you need only N steps (logarithmic to the number) ! So if a quantum computer with enough bits (called qubits in quantum computers) all today's encryptions are totally useless !! Your bank account can be stolen in one day. [3,5,6]
Several quantum computes of 5 and 7 qubits have been made to prove it is possible[7]. However not yet practical because they don't have enough qubits yet.
Some quantum cryptography networks have been deployed [8]. Ordinary cryptographic systems promises you that your encrypted text will not be decrypted in less than 1 million years for example. However these quantum cryptography methods are totally unbreakable no matter how much time given (personal opinion of the author, that can be wrong).
Even google is considering using quantum search algorithms and have already bought a quantum computer[1].
They are becoming less and less ignorable nowadays. One day we will wake up to find a complete revolution in computing. They are exponentially faster than ordinary computers in general.
To find a good and easy (and more complete) starting point refer to [9]. However I am going to write a small introduction here.
A quantum bit is the building block of quantum computers as much as the ordinary bit is the basic block of ordinary computers. Although it can not deliver or carry more than 1 bit of data in normal cases[11] (1), but in the intermediate calculation steps it can carry zero and one at the same time.
Basically what that means is that using an array of n qubits, you can deliver or carry any number between 0 and 2^(n-1) just like ordinary computers, but also means that in intermediate steps ur quantum register can carry ALL these numbers at the same time, and you can do calculations on ALL of them simultaneously. That's the concepts used in all quantum algorithms.
For more details I redirect the interested reader to the references mentioned below.
--------FOTENOTES------
(1) Other cases like superdense coding as in [10] uses more advanced techniques and tricks.
-------REFERENCES------
[1] http://www.popsci.com/technology/article/2009-12/google-algorithm-uses-quantum-computing-sort-images-faster-ever
[2] Davide Castelvecchi, _Warp-Speed Algebra_, Scientific American January 2010 Issue, Pages 22-23.
[3] http://spectrum.ieee.org/computing/networks/mother-of-all-quantum-networks-unveiled-in-vienna
[4] http://en.wikipedia.org/wiki/Grover's_algorithm
[5] http://en.wikipedia.org/wiki/Shor's_algorithm
[6] http://alumni.imsa.edu/~matth/quant/299/paper/node19.html
[7] http://en.wikipedia.org/wiki/Timeline_of_quantum_computing
[8] http://spectrum.ieee.org/computing/networks/mother-of-all-quantum-networks-unveiled-in-vienna
[9] http://alumni.imsa.edu/~matth/quant/299/paper/paper.html
[10] http://en.wikipedia.org/wiki/Superdense_coding
[11] http://en.wikipedia.org/wiki/Quantum_information_theory; last modified on 13 November 2009 at 06:53; Quote: "However, despite this, the amount of information that can be retrieved in a single qubit is equal to one bit. It is in the processing of information (quantum computation) that a difference occurs"
Monday, December 14, 2009
WSCF.blue v1.0
WSCF.blue is a Visual Studio .NET 2008 add-in that provides the following features:
· A WSDL Wizard that allows the developer to step through the creation of a WSDL from one or more XSDs.
· A Data Contract Generator (similar to XSD.exe, XSDObjectGen.exe and SvcUtil.exe) that generates the .NET equivalent classes of the XSD types.
· A Service/Endpoint Stub (support for self-hosted and web-hosted) Generator and
· A Client Proxy Generator.
· A Generate Data Contract Code feature that supports the selection of multiple XSD/WSDL source files.
· A Paste XML as Schema option that generates a schema for a block of XML in the clipboard.
· Support for C# and VB.NET code generation.
· You can choose if operation methods on your service class will throw a NotImplementedException, call an implementation method in a partial class, or will be defined as abstract methods.
· Force the SOAP actions (Action and ReplyAction) applied to each operation contract follow the standard WCF format
· Errors found while processing the WSDL are reported in a WSCF.blue pane in the Visual Studio Output window.
Monday, December 07, 2009
How to Get User Friends\Followers on Twitter
Developers are users but on Twitter and Facebook they are not regular users, Twitter for example gives you some APIs to develop you own application and extend Twitter with features, it's time for everybody to extend without waiting for creators to do.
I was developing Twitter application two days ago, and I faced a problem to get all user's friends\followers, I used some APIs but unfortunately, they got first 100 friends\followers!! I knew that you can browse user friends\followers for user called "RamyMahrous" like that http://twitter.com/statuses/friends/ramymahrous.xml?
http://twitter.com/statuses/followers/ramymahrous.xml?
But it gets just first 100 friends\followers I browsed some sites but no information, unless I went to Twitter API Wiki and I knew about XML cursor they use every cursor has limited 100 friends\followes means... if "RamyMahrous" has 204 friends so it will be iterated through 3 cursors.
Let's code...
string FriendsXMLFileURL = "http://twitter.com/statuses/friends/{0}.xml?cursor={1}";
string FollowersXMLFileURL = "http://twitter.com/statuses/followers/{0}.xml?cursor={1}";
List < users_list > listUserList = new List < users_list > ();
int index=0;
XmlSerializer Serializer = new XmlSerializer(typeof(users_list));
List < users_list > listUserList = new List < users_list > ();
List < users_listusersuser > users = new List < users_listusersuser > ();
users_list usersList = new users_list();
int index = 0;
string nextCursor = "-1";
while (nextCursor != "0")
{
usersList = (users_list)Serializer.Deserialize(
XmlReader.Create(string.Format(FollowersXMLFileURL, "RamyMahrous", nextCursor)));
listUserList.Add(usersList);
nextCursor = usersList.next_cursor;
}
//user_list class generated based on the xml structure you can save the xml file and generate it
//using XSD please take alook on this post by Shady http://fci-h.blogspot.com/2009/12/how-to-create-c-class-from-xml-file-via.html
foreach (users_list userlist in listUserList)
{
users.InsertRange(index, userlist.users[0].user);
index += 100;
}
//so now you've list of users you can iterate and do anything with them!
//take a look this brings user friends\followers without providing user password!
Your comments are welcome :)
Saturday, December 05, 2009
How to create a C# Class from XML file (via xsd.exe)
A friend asked me a couple of times about how to I created the class I used in “twitter common friends” to handle xml as objects (includes reading & writing back). Actually the tool (xsd.exe) is pretty simple & takes no more than a couple of commands to create the class for me.
It’s just that I usually forget the keywords/parameters & their order (you can create a dataset or class that can be C# or VB, & there’s a couple of other option I never used before). I usually refer to its MSDN page when asked..
So I thought a post would be easier to remember. First you should create the xsd file out of the xml, using the VS command prompt:
xsd myFile.xml
That will create “myFile.xsd”, now to create “myFile.cs”, write the below line:
xsd myFile.xsd /c
Now you can add the cs file to your project & use it as illustrated in my previous post.
Saturday, November 28, 2009
Generating DAL using CodeSmith and .Nettiers (step by step)
For whom don't know what is Codesmith :
CodeSmith is a software development tool to help you get your job done faster. Technically speaking it is a template driven source code generator that automates the creation of common application source code for any language (C#, Java, VB, PHP, ASP.NET, SQL, etc.).(http://www.codesmithtools.com/)
And .Nettiers :
.netTiers utilizes the power of the best code generation tool available today, CodeSmith. .netTiers generated architecture is custom to your domain, uses familiar patterns, and follows the guidance of Microsoft's recommended patterns and practices. In fact, the .netTiers base architecture is built upon the Microsoft Enterprise Library Application Blocks.(http://nettiers.com/)
Note : these steps captured with CodeSmith 3.2 and .NetTiers but almost versions are the same.
Opening CodeSmith 3.2:
1. After setup the CodeSmith 3.2, open it from the start menu.
2. If you haven’t license, you can continue with the trial version by pressing “Try” button.
3. From the File menu of CodeSmith press “Open” and select the Nettiers.cst inside NetTiers 2.2.0 folder.
8. Build the whole solution.
• your RootNameSpace.Data.dll
• your RootNameSpace.Data.SqlClient.dll
• your RootNameSpace.Entities.dll
Happy Coding :)
Wednesday, October 21, 2009
Wondering about Project Managers
- Should PMs know/ask much about technical decisions?
- IMHO, I thing the answer is NO!! PMs should be asking for less fine details like what's the estimations for doing that option or so.. But they shouldn't be asking why we are using X, or Y technology/approach to tackle a problem.
- In an agile process, where should PMs stand? What exactly is their Role? Should there be PMs in agile in the first place? Or Should they be replaced by a PO (Product Owner), or -may be- a Scrum Master?
- That's a question that really confuses me a lot.. I can't give a definite answer.. Should they replace POs.. Hmm. I guess not.. On one hand, a PO should be the one directing the project, knowing what the customer want.. But still, a PO -probably- should have some technical background.. So according to my answer to the previous question, PMs can't replace POs..
- On the other hand, Replacing a Scrum Master, is a bit too far for PMs, Scrum Master are supposed to be in favor of the development team, ie a facilitator & protector for the dev team; & PMs are notorious of failing to do so.. :D
- Another option -that just came to me right now- is PMs replacing customer in environments where it's difficult to involve the customer.
I might be adding other questions but for now that's what is on my mind..
Sunday, October 18, 2009
Deploying Reports in Reporting Services Programmatically
First it's a tool I developed to automate the deployment of BI solution (Creating Data warehouse, installing SSIS packages, creating Jobs, create Cubes and installing reports on Reporting Services Server).
If you don't have time to read and just need to download the tool, here you're
Source Code: http://cid-3e2288e7a8e55f56.skydrive.live.com/self.aspx/Public%20folder/Deploying%20Reports%20in%20Reporting%20Services%20Programmatically.zip
Herein, I'll talk about the last thing which is deploying reports.
P.S: It's my way in designing such task (Installing reports on Reporting Services Server) and it's not standard or anything else just (follow your heart :))
Let's begin, I assume you, me, or anybody else has these 3 XML files one for folders, one for data sources and one for reports.
[caption id="attachment_772" align="aligncenter" width="450" caption="Folders' XML Scheme"]
[/caption]Name: Folder name to be created on Reporting Services.
ParentFolder: '/' means on the top == no parent folder.
[caption id="attachment_773" align="aligncenter" width="450" caption="Data Sources' XML Scheme"]
[/caption]Name: Data Source name to be created on Reporting Services.
Folder: The folder in which Data Source should be in, if we use '/' means on the top == no parent folder.
Description: Data Source Description.
HideInListView: True to hide it in the Reporting Services, otherwise False.
Enabled: True to be enabled, otherwise not enabled.
ConnectionString: Data Source connection string.
Extension: Configured according to the provider for more details see below table...
| Provider | Extension |
| Microsoft SQL Server | SQL |
| OLE DB | OLEDB |
| Microsoft SQL Server Analysis Services | OLEDB-MD |
| Oracle | ORACLE |
| ODBC | ODBC |
| XML | XML |
| SAP NetWeaver BI | SAPBW |
| Hyperion Essbase | ESSBASE |
CredentialRetrieval: How Data Source will retrieve the credential.
WindowsCredentials: True to use Windows credential otherwise it'd use the credential provided in this XML (Username, and Password).
ImpersonateUser: Indicates whether the report server attempts to impersonate a user by using stored credentials after a data processing extension has established an authenticated connection to a data source.
ImpersonateUserSpecified: Gets or sets a value that indicates whether the ImpersonateUser property is specified.
Prompt: Gets or sets the prompt that the report server displays to the user when prompting for credentials.
UserName: Gets or sets the user name that the report server uses to connect to a data source.
Password: Sets the password that the report server uses to connect to a data source. Write-only.
EnabledSpecified: Gets or sets a value that indicates whether the Enabled property is specified.
More details on these properties http://msdn.microsoft.com/en-us/library/reportservice2005.datasourcedefinition_properties.aspx
[caption id="attachment_774" align="aligncenter" width="450" caption="Reports' XML Scheme"]
[/caption]Name: Report Name.
Path: .RDL file path.
Folder: The folder in which Report should be in, if we use '/' means on the top == no parent folder.
DataSource: Report's Data Source name of Reporting Services.
And these configuration keys
[caption id="attachment_777" align="aligncenter" width="450" caption="Configuration keys"]
ReportsXMLFilePath: Reports' XML File Path
DataSourcesXMLFilePath: Data Sources' XML File Path
FoldersXMLFilePath: Folders' XML File Path
ReportingServerURL: URL of Reporting Services
Open visual studio and create a C# console application (we don't need any interaction with user everything configured in the application configuration file)
From the project main menu Add Web Reference or Add Service Reference then Advanced then Add Web Reference...
[caption id="attachment_778" align="aligncenter" width="450" caption="Add Web Reference"]
[/caption][caption id="attachment_779" align="aligncenter" width="450" caption="Add Reporting Services Reference"]
[/caption]URL: http://{Server-Name}/reportserver/ReportService.asmx
Web reference name: Give it meaningful name..
What we did is adding web service by which we can talk to Reporting Services to ask it to do something like (create report, create data source, etc...).
Let's write some very simple C# code
We have method called DeployReports this method calls 3 other methods in order (CreateFolders, CreateDataSources, and CreateReports)
Sunday, October 11, 2009
Table-Value and Temp Tables
Table-value parameters offer more flexibility and better performance than temporary tables to pass a list of parameters. Table-value parameters do not acquire locks for the initial population of data from a client and do not cause a statement to recompile.
Table-value parameters offer the following benefits:
·Provide a simple programming model.
·Enable inclusion of complex business logic in a single routine.
·Reduce round trips to the server.
·Include a table structure of different cardinality.
·Enable strongly typed and set-oriented queries.
·Enable the client to specify sort order and unique keys.
Table-value parameters have the following restrictions:
·Statistics are not maintained on columns of table-value parameters.
·Table-value parameters must be passed as input READONLY parameters to Transact-SQL routines.
·DML operations such as UPDATE, DELETE, or INSERT cannot be performed on a table-value parameter in the body of a routine.
·Table-value parameters cannot be used as the target of a SELECT INTO or INSERT EXEC statement. Table-value parameters can be in the FROM clause of SELECT INTO, or in the INSERT EXEC string or stored procedure.
Source: http://bit.ly/3rmMLK
Saturday, September 12, 2009
Reading POP3 (secure) SSL like Gmail via C#
After a hard search in alot of pages I got two good result :
1- it is a good project (from this blog) have good description that implements the standard POP3 commands like authenticating, receiving stats, retrieving and deleting messages .
2-There are open source project called OpenPOP in sourefourge but have bugs and fixed (here) in this blog by Kiran banda,unfortantualy it have build errors but i fix it (here) but it needs some work to go live.
Related post :
Reading Atom feed of Gmail inbox via C#
Friday, September 11, 2009
Reading Atom feed of Gmail inbox via C#

Today I am coming with Gmail feature that may be useful although many people don't know and how to access it via simple C# code.
Gmail Atom feed is xml format file to know the unread messages .
http://mail.google.com/mail/feed/atom/ shows the most recent unread items from your inbox. Gmail also offers feeds for your labels:http://mail.google.com/mail/feed/atom/labelname/ .
To know the feature in detials go to this link @ (the unofficial news and tips about Google).
As a developer you can download the C# example here.
All what you need is create instance a simple class called GmailHandler and drop this lines in your project.
//just 2 steps to get your Gmail Atom
//1- Create the object from GmailHandler class
GmailHandler gmailFeed = new GmailHandler("WriteHereYourGmailUserName(ex: fci-h)", "WriteHereYourGmailPassword(ex: XXX)");
//2-get the feed :) ,Congratulations
XmlDocument myXml = gmailFeed.GetGmailAtom();
Just happy code :)
Thursday, September 10, 2009
Backup and Restore SQl Server DB by c#
lets get into the code.
First thing, you have to reference the following two references
- Microsoft.SqlServer.ConnectionInfo
- Microsoft.SqlServer.Smo
1) Create a connection to the SQL Server
private static Server CreateServerConnection(string ServerIP, string SQLInstanceName, string userName, string password)
{
try
{
// Create a new connection to the selected server name
ServerConnection srvConn = new ServerConnection(ServerIP+ @"\" + SQLInstanceName);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Give the login username
srvConn.Login = userName;
// Give the login password
srvConn.Password = password;
// Create a new SQL Server object using the connection we created
return new Server(srvConn);
}
catch (Exception ex)
{
// Handle Exceptions
}
}
--------------------------------------------------------
2) Perform DB Backup
/// The name of the .bak file
/// SQL Server instance name
/// The name of the Db we want to backup
/// serverIP">IP of the server where the SQL server installed
/// for sql Authentication, example sa
/// Password of the DB user
public static void BackUpDB(string backUpFileName, string SQLInstanceName, string DBName, string serverIP, string userName, string password)
{
try
{
Backup bDatabase = new Backup();
// Set the backup type to a database backup
bDatabase.Action = BackupActionType.Database;
// Set the database that we want to perform a backup on
bDatabase.Database = DBName;
// Set the backup device to a file
BackupDeviceItem bkDevice = new BackupDeviceItem(backUpFileName, DeviceType.File);
// Add the backup device
bDatabase.Devices.Add(bkDevice);
//Check if the file exists
if (File.Exists(backUpFileName))
File.Delete(backUpFileName);
// Perform the backup
bDatabase.SqlBackup(CreateServerConnection(serverIP, SQLInstanceName, UserName, password));
}
catch (Exception ex)
{
// Handle Exceptions
}
}
-------------------------------------------------------------------
3) Perform DB Restore
/// the .bak file
///
///
///
///
///
public static void RestoreDB(string restoreFileName, string SQLInstanceName, string DBName, string serverIP, string userName, string password)
{
try
{
Restore rDatabase = new Restore();
// Set the restore type to a database restore
rDatabase.Action = RestoreActionType.Database;
// Assign a db to restore operation
rDatabase.Database = DBName;
// Set the backup device to restore from file
BackupDeviceItem bkDevice = new BackupDeviceItem(restoreFileName, DeviceType.File);
// Add the backup device to the restore type
rDatabase.Devices.Add(bkDevice);
// Replace the Db if already exists
rDatabase.ReplaceDatabase = true;
if (File.Exists(restoreFileName))
// restore
rDatabase.SqlRestore(CreateServerConnection(serverIP, SQLInstanceName, userName, password));
}
catch (Exception ex)
{
// Handle Exceptions
}
}
---------------------------------------------------
That's it
Wednesday, September 09, 2009
Want to learn SQL Server Data Services (SDS)?
This 1-hour online clinic provides SQL Server developers who are experienced in implementing database solutions with an overview of SQL Server Data Services (SSDS).
The topics covered in the clinic include:
- Introduction to SSDS
- SSDS Object Model
- Working with SSDS
More on: http://learning.microsoft.com/Manager/ResourceDetails.aspx?resourceId=cbe836be-394e-4a23-9f87-5d12127cccd5&clang=en-US&brand=Learning
Developing an Application for Microsoft SQL Server Data Services
This 1-hour online clinic provides SQL Server developers who are experienced in implementing database solutions with an explanation of the knowledge and skills required to develop an application in SQL Server Data Services (SSDS).
Topics covered in the clinic include:
- Building an SSDS Application
- Enhancing an SSDS Application
More on: http://learning.microsoft.com/Manager/ResourceDetails.aspx?resourceId=9b2d7204-9f2e-4657-a4c7-0952b32ae081&clang=en-US&brand=Learning
More on SQL Azure Database: http://www.microsoft.com/azure/data.mspx
Wednesday, August 19, 2009
Disabling the mouse right click : JavaScript
The code is JavaScript ,the code is readable and can be used to handle other mouse events.
just call DisableRightclick() once in your page.
[script language="javascript" ]
var IE;
var NN;
function right(click)
{
if(IE && (event.button==2 || event.button==3))
{
alert("The right click has been disabled here.");
return false;
}
if(NN && (click.which==2 || click.which==3))
{
alert("The right click has been disabled here.");
return false;
}
return false;
}
function DisableRightclick()
{
if(navigator.appName=="Microsoft Internet Explorer")
{
IE=true;
}
if(navigator.appName=="Netscape")
{
NN=true;
}
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
document.onmousedown=right;
document.onmouseup=right;
window.document.layers=right;
}
[/script]
Check Acrobat Reader (PDF) installed : JavaScript with IE
Function returns : true for OK else false .
function CheckPDF()
{
var isInstalled = false;
var version = null;
if (window.ActiveXObject)
{
var control = null;
try {
// version 7
control = new ActiveXObject('AcroPDF.PDF');
}
catch (e)
{
// Do nothing
}
if (!control)
{
try {
//version 6
control = new ActiveXObject('PDF.PdfCtrl');
}
catch (e)
{
return false ;
}
}
if (control)
{
return true ;
}
else
{
return false ;
}
}
}