{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
Using OpenID SSO mechanism to retrieve your visitor's details
Recently I got interested in allowing people to add feedback, but from previous experience I noticed that such feedback mechanisms will allow spammers to compromise the site contents.
And to mitigate the situation, I had until recently two solutions:
  • using Captcha mechanisms;
  • using external APIs  to validate if the comment is a spam or not.
Now I decided to implement an OpenID mechanism, allowing people to log in with their already-existing credentials from Google, Yahoo, and other providers.
For this I found on the internet the http://gitorious.org/lightopenid API which will help me authenticate the consumers with their OpenID account. So, inside the LightOpenID class I defined few blocks.
This statement is executed every time the page is loaded, and it simply will set in my session the contact name and email, according to the authentication protocol.
But getting the name and email are not trivial task, for which I defined a getContactDetails() method inside that class.
This function, getContactDetails will return an array containing the email and the name (friendly, full name, or email, whichever is available, preferably the first).
How can be seen in the fist statement, I used a function getAllProviders that will return me all the identity providers recognized by my site. The code for this function is getAllProviders.
Finally, all this functionality is used in the PHP page, as in Usage.php.
The code is functioning for the moment only on http://my.sorescu.eu.
Have fun coding!
4 files attached: LightOpenID.php getContactDetails.php getAllProviders.php Usage.php
LightOpenID.php getContactDetails.php getAllProviders.php Usage.php
<?if(@$_SESSION['contact']){?>
	<a class='dms-button' href='#' onclick='$(this).siblings().toggle()'>
		<%icon:loggedin%><?&@$_SESSION['contact']['email']?>
	</a>
	<a style='display:none' class='dms-button' href='?OpenIDAuthenticationProvider='><%icon:logout%>Logout</a>
<?}else{?>
	<a class='dms-button' href='#' onclick='$(this).siblings().toggle()'><%icon:login%>Login</a>
	<?foreach(LightOpenID::getAllProviders() as $providerName => $provider){?>
		<a style='display:none' class='dms-button' href='?OpenIDAuthenticationProvider=<?=$providerName?>'><img src='<?=$provider['icon']?>'/><?=$provider['label']?></a>
	<?}?>
<?}?>
How to write a simple Light SMTP Server in C#
Sample of a small C# SMTP server with the following features:
  • 17KB source code;
  • five files of code only;
  • able to receive mails;
  • relay (forward) mails to external servers;
  • able to resolve the MX machine IPs for external mails;
  • mails to external recipients (external elaying) requires authentication.
The components of the code are:
  1. "Listener" daemon that takes the incoming SMTP requests;
  2. "MXDiscovery" module able to identify the IP of the external recipient servers;
  3. "Sender" component that is responsible for forwarding the message to external recipients;
  4. "SMTP" library with useful functions;
  5. "SMTPServer" the main application that starts the listener.

I hope this information might be useful for others, too.
5 files attached: SMTPServer.cs Listener.cs MXDiscovery.cs Sender.cs SMTP.cs
SMTPServer.cs Listener.cs MXDiscovery.cs Sender.cs SMTP.cs
Email obfuscator
When I decided to publish my CV on a web page (http://dragos-matei.sorescu.eu) I wanted to publish also my email, but without letting the bots read it.
So, I came with the following solution:
  1. encode the email in some kind;
  2. let the browser decode it after the page gets loaded.
For this I used the following encoded text:
	
		<%icon:email%>[b36]831898108[b36][b36]1348423876[b36]@[b36]27913917[b36].[b36]16438[b36]
	
The JavaScript to decode it is attached.
A small demonstration of the algorithm is put also below:
SourceEncodingDecoding
 
 
1 files attached: Decode.js
Decode.js
Search functionality enabled on www.sorescu.eu
Now the site http://www.sorescu.eu/ offers a search functionality in the left bar.
The code is relatively simple, with two components, client-side and server-side.
Notes:
  • the PSP is a wrapper syntax on top of PHP;
  • after loading data, the client is responsible with formatting with JQuery the result;
  • in case of fast typing it is possible that multiple distinct requests to come in a different order (I shall fix it by adding a counter logic in few minutes).
2 files attached: ClientSide.html ServerSide.php
ClientSide.html ServerSide.php
Small Java Image Resizing Utility
Another small challenge; one guy came to me with 550 photographs in around 110 folders (they represent a tree structure of content images to be delivered and browsed by a front-end web application).

The challenge was to compress and resize all the images to improve the browsing performance.

Below is the code I wrote to perform this task.
My inspiration was http://www.mkyong.com/java/how-to-resize-an-image-in-java/ with the following small and compact code:
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
.
1 files attached: ImageResize.java
ImageResize.java
Screen Capture Update
My wife, the user of the Screen Capture application as described in  http://www.sorescu.eu/article/120220221500/Free-Screen-Capture-application explained me that she needs to run it also while in Full Screen mode.


For this I had to hook to the Windows Hot Key events, after I registered with the desired shortcut.

The chosen shortcut is <CTRL>+<ALT>+<PRINT_SCREEN>, and the code update is as in file below. Main call as following:
Thread t=new Thread(new ThreadStart(ProcessHotKey));
            t.IsBackground=true;
            t.Start();
Worthy mentioning are the following:
  • I used
    GetMessage(ref msg,IntPtr.Zero,0,0)
    for avoiding message queues to any form, but to the current thread;
  • It was required
    int hashCode=("hash-"+modifiers+"-"+key).GetHashCode();
    to ensure that the Hot Key is unique in Windows;
  • The Hot Key handler had to be ran in a separate thread, using
    new Thread(new ThreadStart(ProcessHotKey))
1 files attached: RegisterHotKey.cs
RegisterHotKey.cs
A small Java program to generate transparent images (for dynamic background colours)
Somebody requested me to generate a web page with a wall background that should change the wall colour based on the user's desire.
I thought a transparency-enabled background will suffice, with a dynamic background of the image.
Steps:
  1. Take the background image from my customer;
  2. Generate a mask image as a copy of the background image, and remove the area (set it to black) where I want to have transparency;
  3. Run the Java program that is written below;
  4. Use the final result image and put it in a web page.
You can check the result (while the web page is still there) at: http://dev-alexandru-doors.sorescu.eu/products-en_GB where you may click any image from gallery and the background image will appear.
1 files attached: ImageTansparency.java
ImageTansparency.java
Sending dynamic client-side parameters in URL fragments and manipulating them
Seldom I was in need to perform client filtering on tables and other data, and eventually save the filter. One solution was sending the filter to the server and generate the filtered page.
The functions below (I am using them few years already in Internet Explorer) are used to store and get the properties from fragments.
Some useful clues:
  • When the page is loaded, check all the fragment parameters and update the controls and perform filtering, etc.;
  • Whenever you update a filter in a text field, etc., you can save it in the fragment;
  • You can send the link with fragment to anybody else, and if the first bullet (filter executed on page loading) is accomplished, the URL receiver will see the same page as you.
1 files attached: getFragmentValues.js
getFragmentValues.js
Scripted C# - or how to run dynamic C# code, without compilation
As I started to develop small applications in C#, I thought why shouldn't I use the same paradigms that I used in Java... dynamic code execution, execution without compile/build/deploy process, hot-swap, etc.

I am far away from acomplishing the same functionality, but I started with writing a small program (81 lines) mentioned below.

When executing, it is able to compile and execute C# code that is written in text files, on the spot.

The mechanism is quite simple: it expects in the command line the name of an XML file (mentioned below this script) that describes:
  • the list of CS files that should be compiled;
  • the list of external binaries, if required;
  • the title of the application;
  • the entry point (the class name that contains the Main function).
An example (SMTPServer.csscriptof the input XML looks like attached.
Useful information:
  • the class mentioned in the CSScript/EntryClass node must have a Main(string[]args) method;
  • the Main method must be public and static!
  • additional parameters to be sent to the Main method are added to the executed command line!
Example of using the script attached.
In my development (that I started yesterday evening) I used some information from the following links:
The application code is straight forward, and I don't think any comment is required. If you need any comment, then either you should learn programming, or study a bit some C-like languages.

If you wonder why I don't also give the EXE file, please feel free to open the Visual Studio, create an empty project, add a class and paste this code.
3 files attached: RunCS.cs SMTPServer.csscript start.cmd
RunCS.cs SMTPServer.csscript start.cmd
Translating the DOCX file in machine-readable contents
One of my last tasks is to build clear requirements based on customer WinWord documents; I also do have a strong feeling that the documentation will change in time, and it will be a dirty work to trace it.
As a consequence, I wrote a small utility to render to the browser the contents (not rendition) of a diven DOCX file. And the transformation (in incipient phase) is below.
2 files attached: RenderWindWord.dsp Transform.xsl
RenderWindWord.dsp Transform.xsl