{{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.
How to safely migrate data between databases in MySQL with PHP
I saw many people using lots of complex methods in attempt to move data between databases and file systems.

One of the most frequent methods is storing sequential data records in CSV, TSV, XML, or other formats. Obviously, each syntax requires specific escaping algorithms, a fact that most of times is omitted or forgotten by developer.

The last time I had to move data between two different instances of MySQL from two different sites I followed the approach:
  1. Select the database records and put them in an object (array);
  2. serialize the array;
  3. encode the array in base64 to ensure the text needs no escaping algorithm;
  4. copy the text on a support (file, ftp, mail, etc.);
  5. decode the array from base64 to native format;
  6. deserialize the array;
  7. take each record and save it to the database.
Some of the advantages are:
  1. you don't transfer database records, but business objects;
  2. if you have complex relations or fields, they just get wrapped, irrelevant on the database representation.
A code example is in sample.php.

And the result will be similar to sample.txt.
2 files attached: sample.php sample.txt
sample.php sample.txt
Right click functionality on some buttons - how to, and demo
To use at best the screen estate it is indicated sometimes to implement right-click handlers that trigger menus or other activities.

Recently I thought implementing such functionality on http://my.sorescu.eu/. The functionality implemented was triggering a dialogue box; the complete functionality is still under development, but the right-click handler has been implemented.

First, I looked for a library, and I found one that looked nice and simple (implemented using jQuery): http://www.abeautifulsite.net/blog/2008/05/jquery-right-click-plugin/#demo.

I am using Google Chrome right now to test it, and I saw the following misbehaviour: if I right-click on the "MY Place" button after right-dragging, I get the event triggered multiple times.

I patched the code by inserting a line after line 53:
$(this).mousedown( function(e) {
					var evt = e;
					$(this).unbind('mouseup');//added by dragos-matei@sorescu.eu to avoid double right click events, or ghost right clicks for right dragging events starting from this button
					$(this).mouseup( function() {
						$(this).unbind('mouseup');
						if( evt.button == 2 ) {
							handler.call( $(this), evt );
							return false;
						} else {
							return true;
						}
					});
				});
The issue seems to be in the original code that every time the  rightMouseDown   occurs, a new  rightMouseUp handler is added. 
What I did was to remove the rightMouseUp event also when rightMouseDown event.

Thanks to http://www.abeautifulsite.net and I hope it was useful for you.

N.B.: No guarantee that the script in discussion and the modification I did is useful, safe, good, or whatever else - just take it without any warranty, of any kind, under any circumstances.
Java 6 BrainBench certification results for Dragos-Matei Sorescu
I am happy to anounce that I passed another certification test, this time in Java. The overall results are:
Name: Java 6
Score: 4.53Date: 2012-07-10

View detailed topic results

Scored higher than 99% of all previous test takers.

Demonstrates understanding of most advanced concepts within the subject area. Appears capable of mentoring others on the most complex projects.
Strengths
 Core Libraries 
 Practical Software Engineering 
 Integration Libraries 
 Class Definition 
 Support Libraries 
Weak Areas
    None Noted
Results per section are as below:
Dragos-Matei Sorescu
Test:Java 6
Date:10-Jul-2012
Score:4.53
Correct/Total:(34/40)
Topics/SubtopicsCorrect/Total
Tools(2/3)
Compiler(0/1)
Annotation Processing(1/1)
Deployment(1/1)
Practical Software Engineering(6/7)
Object Design(1/1)
Best Practices(4/4)
Refactoring(0/1)
Patterns(1/1)
Integration Libraries(5/5)
Web Services(2/2)
Scripting(1/1)
JNDI(1/1)
JDBC(1/1)
Class Definition(4/6)
Methods and Fields(2/3)
Inheritance(0/1)
Access Modifiers(1/1)
Generics(1/1)
Support Libraries(4/6)
Networking(0/1)
XML(2/2)
Internationalization(0/1)
Security(2/2)
Core Libraries(6/6)
I/O(4/4)
Math(1/1)
Language and Utilities(1/1)
Visual Libraries(2/2)
OS Integration(1/1)
Components(1/1)
Syntax(3/3)
Data Types(1/1)
Flow of Control(1/1)
Expressions(1/1)
Virtual Machine(2/2)
Thread Management(1/1)
VM Internals(1/1)
Comments option available on Sorescu Knowledge Base
Now, based on the OpenID authentication, the KB.Sorescu.EU site accepts reader's comments. Please feel free to add your contribution to the value of the site.
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