<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>the Fictionalrealm / Coding</title>
	<atom:link href="http://fictionalrealm.com/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://fictionalrealm.com/coding</link>
	<description>Some wicked thoughts and ideas</description>
	<lastBuildDate>Fri, 23 Dec 2011 11:35:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Oracle/Hibernate UUID generation</title>
		<link>http://fictionalrealm.com/coding/2011/12/15/oraclehibernate-uuid-generation/</link>
		<comments>http://fictionalrealm.com/coding/2011/12/15/oraclehibernate-uuid-generation/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 11:05:49 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/coding/?p=366</guid>
		<description><![CDATA[We have several datacenters some of which may be located pretty far away from each other. In all of them there are several tables which are going to be populated on the leaf DBs and then the resulting rows will have to be moved to a central database. This means that we need here some kind of [...]]]></description>
			<content:encoded><![CDATA[<p>We have several datacenters some of which may be located pretty far away from each other. In all of them there are several tables which are going to be populated on the leaf DBs and then the resulting rows will have to be moved to a central database. This means that we need here some kind of globally unique id generation mechanism between distant applications. Another problem is that there&#8217;s also the requirement that some of the rows in those synchronized tables may be inserted from other locations outside of my Java app&#8217;s scope. These rows would not be able to use Hibernate&#8217;s UUID generation strategy, instead IDs for these rows should be generated inside the database.</p>
<p>If you&#8217;re using Oracle database with java that usually means that you&#8217;re also using Hibernate as an ORM. If you do, then it&#8217;s always a good idea to generate your IDs in java and specify them when inserting new rows. You can do this in hibernate quite easily by specifying the ID generation strategy. Hibernate needs to know the ID of the inserted row for it&#8217;s internals to work correctly, that&#8217;s why if you use the inside-Orace ID generation then for each row there&#8217;s going to be a round trip for hibernate to actually find out what ID was assigned to the newly inserted row. This is definitely the case when you have UUID ( or GUID  in Oracle terminology) as your PK (this is probably not the case if you&#8217;re using sequences cause the sequence allows hibernate to allocate large chunks of IDs and use them for the inserts).  Hibernate offers <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#d0e5294">2 UUID generation strategies</a>(uuid and uuid2) so a natural question arose, which one to choose?</p>
<p><span id="more-366"></span></p>
<p>As Hibernates documentation points out about provided &#8220;uuid&#8221; generation strategy :</p>
<blockquote><p><a id="mapping-declaration-id-hilodescription">Note specifically that this is different than the IETF RFC4122 representation of 8-4-4-4-12. If you need RFC4122 compliant UUIDs, consider using &#8220;uuid2&#8243; generator discussed below.</a></p></blockquote>
<p>The Java built-in UUID generator turns out also uses the <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC4122</a> standard. What a single UUID generation algorithm does is guaranteeing that there is not going to be any collision of it&#8217;s generated values. Even if the values are generated on different machines at the same time. The problem is that any RFC4122 compatible algorithm is not required to generate values which do not collide with results provided by other RFC incompatible algorithms such as Oracle&#8217;s SYS_GUID. So this means that we&#8217;re unable to use SYS_GUID and Hibernate&#8217;s uuid2 on the same column cause there&#8217;s a slim chance of collision.</p>
<p>We ended up with using Java procedure in Oracle to generate Hibernate compatible UUIDs. The source code is available <a href="http://www.oracle-base.com/articles/9i/UUID9i.php">here</a>. <strong>DO NOT</strong> use the PL/SQL written procedure in this article. It&#8217;s not actually working when the invocations happen very rapidly. Oracle call the procedure once then caches it&#8217;s result and reuses it for the next several invocations thus making the PL/SQL approach total crap. Use the java procedure.</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2011/12/15/oraclehibernate-uuid-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysqldump corrupted utf8 data when dumping on windows machine</title>
		<link>http://fictionalrealm.com/coding/2011/05/29/mysqldump-corrupted-utf8-data-when-dumping-on-windows-machine/</link>
		<comments>http://fictionalrealm.com/coding/2011/05/29/mysqldump-corrupted-utf8-data-when-dumping-on-windows-machine/#comments</comments>
		<pubDate>Sun, 29 May 2011 09:33:16 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/coding/?p=357</guid>
		<description><![CDATA[What happened to me a couple of days back was that I discovered that one of my mysql dumps done with mysql&#8217;s own mysqldump utility has all texts in utf8 corrupted. Everything looked like this: ╘┐╒Ñ╒╢╒┐╓Ç╒╕╒╢╒í╒»╒í╒╢ ╒ú╓Ç╒í╒╜╒Ñ╒╢╒╡╒í╒» and this: ╘╗╒╢╒Ñ╒»╒╕╒ó╒í╒╢╒»╒╕╓é╒┤. The original text was in Armenian. The cause of all this beauty was my mistake. [...]]]></description>
			<content:encoded><![CDATA[<p>What happened to me a couple of days back was that I discovered that one of my mysql dumps done with mysql&#8217;s own mysqldump utility has all texts in utf8 corrupted. Everything looked like this: ╘┐╒Ñ╒╢╒┐╓Ç╒╕╒╢╒í╒»╒í╒╢ ╒ú╓Ç╒í╒╜╒Ñ╒╢╒╡╒í╒» and this: ╘╗╒╢╒Ñ╒»╒╕╒ó╒í╒╢╒»╒╕╓é╒┤. The original text was in Armenian.</p>
<p>The cause of all this beauty was my mistake. I shouldn&#8217;t have used piping when dumping the database in the powershell on my windows 7 machine. To avoid this kind of stuff in the future always use mysqldump&#8217;s -r flag when dumping the database. That way mysqldump opens the dump file and writes everything in it directly. If you don&#8217;t use the -r flag the dumped data will be first passed to your console program where it may be converted to some weird alien encoding and only after that it will be written to the file which the console program will create. In my case here all utf8 characters got converted into 2 characters. I don&#8217;t exactly know how this happened but each utf8 Armenian character is 2 bytes so to me it looks like powershell converted each character into 2 ascii ones.<span id="more-357"></span></p>
<p>I tried using &#8220;set names utf8;&#8221; tried re-encoding the dump file . . . . I tried lots of thing but none helped. In the end I ended up with the dumbest solution ever possible. I created a table containing the whole Armenian alphabet and punctuation marks, dumped it so that the data ended up corrupted, figured out what each letter got converted into and did a replace in the database. Here&#8217;s the query i ended up with:</p>
<pre class="brush: sql; title: ; notranslate">
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;-&quot;, &quot;-&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;,&quot;, &quot;,&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;;&quot;, &quot;;&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;.&quot;, &quot;.&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒¢&quot;, &quot;՛&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒¡&quot;, &quot;խ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒«&quot;, &quot;ծ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;/&quot;, &quot;/&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╖&quot;, &quot;շ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒¬&quot;, &quot;ժ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒│&quot;, &quot;ճ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒º&quot;, &quot;է&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒⌐&quot;, &quot;թ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓â&quot;, &quot;փ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒▒&quot;, &quot;ձ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╗&quot;, &quot;ջ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;)&quot;, &quot;)&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓ç&quot;, &quot;և&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓Ç&quot;, &quot;ր&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╣&quot;, &quot;չ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒í&quot;, &quot;ա&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ó&quot;, &quot;բ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓ü&quot;, &quot;ց&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ñ&quot;, &quot;դ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒Ñ&quot;, &quot;ե&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓å&quot;, &quot;ֆ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ú&quot;, &quot;գ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒░&quot;, &quot;հ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒½&quot;, &quot;ի&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╡&quot;, &quot;յ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒»&quot;, &quot;կ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒¼&quot;, &quot;լ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒┤&quot;, &quot;մ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╢&quot;, &quot;ն&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓à&quot;, &quot;օ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒║&quot;, &quot;պ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓ä&quot;, &quot;ք&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╝&quot;, &quot;ռ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╜&quot;, &quot;ս&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒┐&quot;, &quot;տ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓é&quot;, &quot;ւ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╛&quot;, &quot;վ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒╕&quot;, &quot;ո&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒▓&quot;, &quot;ղ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒¿&quot;, &quot;ը&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ª&quot;, &quot;զ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;Γäû&quot;, &quot;№&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;┬½&quot;, &quot;«&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;-&quot;, &quot;-&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;┬╗&quot;, &quot;»&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒₧&quot;, &quot;՞&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒â&quot;, &quot;Ճ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╖&quot;, &quot;Է&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╣&quot;, &quot;Թ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ô&quot;, &quot;Փ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ü&quot;, &quot;Ձ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ï&quot;, &quot;Ջ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;)&quot;, &quot;)&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓ç&quot;, &quot;և&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒É&quot;, &quot;Ր&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ë&quot;, &quot;Չ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╓ë&quot;, &quot;։&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘║&quot;, &quot;Ժ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘▒&quot;, &quot;Ա&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘▓&quot;, &quot;Բ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒æ&quot;, &quot;Ց &quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╡&quot;, &quot;Ե&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒û&quot;, &quot;Ֆ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘│&quot;, &quot;Գ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘┤&quot;, &quot;Դ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒Ç&quot;, &quot;Հ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╗&quot;, &quot;Ի&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒à&quot;, &quot;Յ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘┐&quot;, &quot;Կ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╝&quot;, &quot;Լ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ä&quot;, &quot;Մ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒å&quot;, &quot;Ն&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ò&quot;, &quot;Օ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒è&quot;, &quot;Պ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ö&quot;, &quot;Ք&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒î&quot;, &quot;Ռ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ì&quot;, &quot;Ս&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒Å&quot;, &quot;Տ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒Æ&quot;, &quot;Ւ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒Ä&quot;, &quot;Վ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ê&quot;, &quot;Ո&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒é&quot;, &quot;Ղ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╕&quot;, &quot;Ը&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╢&quot;, &quot;Զ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╘╜&quot;, &quot;Խ&quot;);
UPDATE pages SET `content`=REPLACE(`redirect_to`, &quot;╒ç&quot;, &quot;Շ&quot;);
</pre>
<p>Of course you can do the replacing in the dump file itself. Just remember to do the mappings for all characters your language has.</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2011/05/29/mysqldump-corrupted-utf8-data-when-dumping-on-windows-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TRMI instead of RMI, avoiding RMI drawbacks</title>
		<link>http://fictionalrealm.com/coding/2010/10/06/trmi-instead-of-rmi-avoiding-rmi-drawbacks/</link>
		<comments>http://fictionalrealm.com/coding/2010/10/06/trmi-instead-of-rmi-avoiding-rmi-drawbacks/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 21:39:08 +0000</pubDate>
		<dc:creator>Harut Martirosyan</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Useful Tools]]></category>
		<category><![CDATA[distributed programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[RMI]]></category>
		<category><![CDATA[TRMI]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/coding/?p=330</guid>
		<description><![CDATA[Let’s be honest, RMI is a great thing to use, but it’s still kind of raw, and has some drawbacks: Disconnections: There’s no centralized and convenient approach to handle disconnections, reconnections and all that network stuff, if something dies – you have a lot of things to do. The “remote” syndrome: In order to be [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s be honest, RMI is a great thing to use, but it’s still kind of raw, and has some drawbacks:</p>
<p><strong> </strong></p>
<ul>
<li><strong>Disconnections</strong>: There’s no centralized and convenient approach to handle disconnections, reconnections and all that network stuff, if something dies – you have a lot of things to do.<strong> </strong></li>
<li><strong>The “remote” syndrome</strong>: In order to be usable via RMI, everything should be remote. When somebody writes a service interface, he&#8217;s not usually foreseeing  that the thing will be exposed by RMI someday and vice versa &#8211; Remote objects are kind of weird when used only locally.</li>
<li><strong>Sexual relationships</strong>: You have to deal with artificial entities like skeletons and stubs, compile them, place in your classpath etc.</li>
<li><strong>Try/catch cumbersomeness</strong>: Every single call requires a try/catch block, or a corresponding something to avoid it, sometimes we don’t really need anything of the kind.</li>
</ul>
<p>You can use <strong>TRMI </strong>to avoid the above mentioned sruff. TRMI uses Java’s proxy and reflections to achieve it&#8217;s goals. It was developed by an Israeli guy named <em><strong>Guy</strong></em><strong> </strong><strong>Gur-Ari</strong><strong> </strong> of whom I am thankful, and the reason this article is being written by me.</p>
<p><span id="more-330"></span></p>
<p>Let’s take a look how a simple TRMI program looks like:</p>
<p>Suppose we have a Hello interface, which essentially is a service interface containing a single hello method.</p>
<pre class="brush: java; title: ; notranslate">public interface Hello {
    /**
    * Returns a hello string
    */
    public String hello();
}</pre>
<p>Note: It’s not remote and the hello() method doesn’t throw any RemoteException.</p>
<p>The implementation may look like this:</p>
<pre class="brush: java; title: ; notranslate">public class HelloImpl implements Hello {
    public String hello() {
        System.out.println(&quot;hello() called&quot;);
        return &quot;Hi there!&quot;;
    }
}</pre>
<p>The Server looks like this, note how simple it is, no export procedures, no ports, nothing, just a natural meaningful code.</p>
<pre class="brush: java; title: ; notranslate">import trmi.*;
public class HelloServer {
    public static void main(String[] args) {
        String name;
        // ...
        try {
            // Create the object --
            Hello hello = new HelloImpl();
            // -- and bind it
            Naming.rebind(name, hello, new Class[] {Hello.class});
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
        // ...
    }
}</pre>
<p>Now we should expose our server with a client program.</p>
<pre class="brush: java; title: ; notranslate">public class HelloClient {
    public static void main(String[] args) {
        String name;
        Hello hello;
        // ...
        try {
            // Look up the object
            hello = (Hello) trmi.Naming.lookup(name);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
        System.out.println(&quot;Saying hello...&quot;);
        // Make the call (look Ma, no try block!)
        String response = hello.hello();
        System.out.println(&quot;Hello server replied: &quot;+ response + &quot;\n&quot;);
    }
}</pre>
<p>If something seems weird to you, you can look through the code, it’s a very plain and easy thing, only 1 main package with about a dozen of classes to look through.<br />
Hope this will work for you and help to get started <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .<br />
There you go, the server is up and running, fault tolerant and easy to use. Enjoy!</p>
<p>The sourceforge URL: <a href="http://sourceforge.net/projects/trmi/">http://sourceforge.net/projects/trmi/</a></p>
<p>P.S. Don’t forget the security file stuff to run the program.</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2010/10/06/trmi-instead-of-rmi-avoiding-rmi-drawbacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause</title>
		<link>http://fictionalrealm.com/coding/2010/08/04/error-incorrect-table-definition-there-can-be-only-one-timestamp-column-with-current_timestamp-in-default-or-on-update-clause/</link>
		<comments>http://fictionalrealm.com/coding/2010/08/04/error-incorrect-table-definition-there-can-be-only-one-timestamp-column-with-current_timestamp-in-default-or-on-update-clause/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 05:25:53 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=306</guid>
		<description><![CDATA[This is a really small article and i&#8217;m not yet sure if i&#8217;m going to write many of these  in the future. But lets get to the point itself I got &#8220;Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause&#8221; error when creating a table as [...]]]></description>
			<content:encoded><![CDATA[<p>This is a really small article and i&#8217;m not yet sure if i&#8217;m going to write many of these  in the future. But lets get to the point itself <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I got &#8220;Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause&#8221; error when creating a table as shown bellow with <a href="http://www.webyog.com/en/">SQLyog</a> probably the best MySql GUI available at the moment</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE classroom (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`modifyDate` TIMESTAMP ,
`createDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
)
</pre>
<p>this error is fixed by adding &#8220;NULL DEFAULT NULL&#8221; to the modifyDate field as in the code bellow</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE classroom (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`modifyDate` TIMESTAMP NULL DEFAULT NULL,
`createDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
)
</pre>
<p>i&#8217;ve got 5.1.41 MySql and this is probably a bug, and i have no idea if it&#8217;s fixed in later builds <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2010/08/04/error-incorrect-table-definition-there-can-be-only-one-timestamp-column-with-current_timestamp-in-default-or-on-update-clause/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HOWTO: Choosing a good domain name</title>
		<link>http://fictionalrealm.com/coding/2010/03/01/howto-choosing-a-good-domain-name/</link>
		<comments>http://fictionalrealm.com/coding/2010/03/01/howto-choosing-a-good-domain-name/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:14:05 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Useful Tools]]></category>
		<category><![CDATA[domain name]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[project management]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[trademarks]]></category>
		<category><![CDATA[URLs]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=293</guid>
		<description><![CDATA[So this is one of the things i hate the most! And this hated moment of choice arises nearly every time you start doing something new. I really can't say that i'm good at this but i know some guidelines you should follow when choosing a domain name and some ways to help you to come up with something sane. So lets start with the guidelines.]]></description>
			<content:encoded><![CDATA[<p><a href="http://fictionalrealm.com/coding/files/2010/03/proper_domain_name.jpg"><img class="size-medium wp-image-300 alignright" style="border: 1px solid black;" src="http://fictionalrealm.com/wp-content/uploads/2010/03/proper_domain_name-300x187.jpg" alt="Selecting a proper domain name" width="300" height="187" /></a>Okay . . .  So this is one of the things i hate the most! And this hated moment of choice arises nearly every time you start doing something new. I really can&#8217;t say that i&#8217;m good at this but i know some guidelines you should follow when choosing a domain name and some ways to help you to come up with something sane &amp; proper. So lets start with the guidelines.</p>
<p><span id="more-293"></span></p>
<p><strong><span style="text-decoration: underline;">Guidelines you should follow</span></strong></p>
<ul>
<li><strong>Domain name = Website name</strong> Your domain name and the name of your business/website/organization should match. When the user clicks a link and lands on your website they don&#8217;t look at the address bar, they look at the title and guess what? they remember the title! So if they want to enter the website they visited yesterday they&#8217;ll type in the name of your website and hit enter. It&#8217;s in your best interest for the name to match with the domain name.</li>
<li><strong>.com rule</strong> Unless you&#8217;re not a non-profit organization(.org), governmental/educational institution(.gov/.edu), an internet related company(.net) or a business targeting UK (use co.uk in this case) go with the .com that&#8217;s what people will try first if they don&#8217;t remember your exact address. That&#8217;s what most of the browsers try appending to the end of address if it wasn&#8217;t found. And finally that&#8217;s what looks good!</li>
<li><strong>&lt; 10 characters </strong>The shorter your domain is &#8211; the better. Usually it&#8217;s desirable to have domain names shorter than 10 characters unless the words in it are really memorable. Using more than 2 words is also undesirable in most cases. I know it&#8217;s hard to follow this(most of 2 word name are already occupied) but do you best before buying someveryverylongshit.com.</li>
<li><strong>Google it first </strong>before buying. Suppose you&#8217;ve decided to name your website kakashka (gibberish names are very popular at the moment cause most of the non gibberish ones are already bought) just googling it will tell you that that&#8217;s not really something you want your business to be called(kakashka means shit in Russian). Besides that there&#8217;s always a chance that there&#8217;s something popular with that name already. If this is the case then climbing the Google result staircase to the first row will get much harder for you.</li>
<li><strong>No dashes, plural form, &#8220;The&#8221;, &#8220;My&#8221; or anything alike. </strong>Do you best to avoid the use of any of the mentioned unless it&#8217;s used not just because the original name was already bought &amp; there&#8217;s a meaning in the use ( like myspace.com ). Generally if you want your website to be named my-domain-name.com you should also buy mydomainname.com and set a redirect on it to point to the one with dashes. The same works for the plurals, &#8220;The&#8221; &amp; &#8220;my&#8221;. Also if you use dashes in your domain name it will get wrapped by many text editors which IMO ain&#8217;t a good thing.</li>
<li><strong>Memorable &amp; easy to pronounce. </strong>Your domain should be memorable and easy to pronounce so that if someone tells his friend on the phone your address (BTW this is the most effective viral channel) they won&#8217;t have to spell the address. For example your domain name almost certainly will have to be spelled if it contains &#8220;ph&#8221; instead of &#8220;f&#8221;, &#8220;y&#8221; instead of &#8220;i&#8221; or r instead of &#8220;er&#8221;. This kind of thing get less important once you gain huge popularity but things like these you never know beforehand.</li>
<li><strong>Trademarks, </strong>respect them. Don&#8217;t name your website betterthanamazon.com or iphonesotfware.com or anything else containing trademarks. Basically the trademark owner may really quickly take over any domain you have registered with his trademark in it.</li>
</ul>
<p>Looks like that&#8217;s it. Those are all the rules i know of which you should follow when buying a domain name.</p>
<p><strong><span style="text-decoration: underline;">How to come up with a good domain name</span></strong></p>
<ul>
<li>First of all i&#8217;d like to note that using your browser to check if the domain name is in use is a really-really bad idea <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Use services like <a href="http://www.bustaname.com/">BustAName</a>, <a href="http://checkfaster.com/">CheckFaster</a> or <a href="http://www.godaddy.com/">GoDaddy</a> to check for available domains.</li>
<li>Make up a list of words &amp; short phrases that are relevant to your business/organization. Consider adding some of the &#8220;Web 2.0&#8243; words to the list (words like feed, cloud, buzz, blog &amp; others). Try mixing them with one another to get something what&#8217;s not in use already. Most likely you won&#8217;t be very successful at this. So in case you fail there are a couple of good resources i know of which will help you to mix your words &amp; to come up with some new ones. The <strong>first</strong> one is <a href="http://www.dotomator.com/">Dotomator.com</a> this one is particularly good cause it has a huge list of words &amp; word parts in it  which you can mix the the words you&#8217;ve already came up with yourself. The <strong>second </strong>service you may find very useful is <a href="http://thesaurus.reference.com/">Thesaurus.com</a> which gives you list of synonyms for your words (is very helpful when you run out of words and need some new ones).</li>
<li>Write down a list of short adjectives (hot, cool, red, new, old . . .) and try combining them with your existing world list and see if something sensible is not occupied already.</li>
<li>Consider naming your website after some animal, plant or something other completely unrelated to you business but memorable. IMO it&#8217;s okay  for a image editing software being hosted on hippo.com BTW this kind of domain name also provides a logo idea.</li>
<li>Consider inventing your own word for the domain name. It should sound good, be easy to pronounce &amp; do not require itself to be spelled out when one tells his friend about your website. This has a little caveat though: for users it may be harder to remember that selfinvented word than something they understand but I don&#8217;t think this is really that big of an issue.</li>
<li>Do not hurry</li>
</ul>
<p>In the end i&#8217;d like to note that the last time i bought a domain name it took me 2+ weeks to decide what i want it to be. If you know of some other way to help out in this please comment about it and i&#8217;ll add it here.</p>
<p><strong><span style="text-decoration: underline;"><br />
</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2010/03/01/howto-choosing-a-good-domain-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Number Base Converter, converts numbers from any base to decimal and vice-versa</title>
		<link>http://fictionalrealm.com/coding/2009/12/27/number-base-converter-converts-numbers-from-any-base-to-decimal-and-vice-versa-2/</link>
		<comments>http://fictionalrealm.com/coding/2009/12/27/number-base-converter-converts-numbers-from-any-base-to-decimal-and-vice-versa-2/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 19:54:48 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Math & Algorithms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[base converting]]></category>
		<category><![CDATA[bcmath]]></category>
		<category><![CDATA[big numbers]]></category>
		<category><![CDATA[huge numbers]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[short urls]]></category>
		<category><![CDATA[tiny urls]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=265</guid>
		<description><![CDATA[Keep in mind that if you just want to address some URL in a short way then you don&#8217;t really need to read this article. You just have to use one of the multitude of services which provide URL mapping to tiny, generated URLs. Some of those services are: http://tinyurl.com/, http://u.nu/, http://bit.ly/. Just use the [...]]]></description>
			<content:encoded><![CDATA[<p>Keep in mind that if you just want to address some URL in a short way then you don&#8217;t really need to read this article. You just have to use one of the multitude of services which provide URL mapping to tiny, generated URLs. Some of those services are:  <a href="http://tinyurl.com/">http://tinyurl.com/</a>, <a href="http://u.nu/">http://u.nu/</a>, <a href="http://bit.ly/">http://bit.ly/</a>. Just use the one you find the sexiest <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>What i needed was a way to <strong>make URLs on my website as short as possible</strong>. I had a huge list of numbered entries each of which had it&#8217;s own unique ID and a URL looking like this: mywebsite.com/entries/789465479916 .  The best way of making the last number part of the URL as short as possible i found is converting the huge decimal number to the base of 62. Why 62? Because we&#8217;ve got 62 alphanumerical symbols there (0-9a-zA-Z) !</p>
<p>The first thing i found after some googling is that <strong>php actually provides a function named <a href="http://php.net/manual/en/function.base-convert.php">base_convert()</a></strong> which does what i want. <strong>BUT! It doesn&#8217;t support base of 62 and really huge numbers.</strong> A little disappointed i left this function be and resumed my search of the ideal solution! <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>In the comments of <a href="http://php.net/manual/en/function.base-convert.php">base_convert()</a> i found a wonderful <a href="http://www.php.net/manual/en/function.base-convert.php#52450">comment</a> doing nearly exactly what i want. The only bad thing about it was that <strong>it didn&#8217;t support bug numbers</strong>. So i <strong>modified the code to use the <a href="http://php.net/manual/en/book.bc.php">bcmath</a> php extension which provides support of huge number calculations</strong>. Bellow is the modified code.</p>
<p><span id="more-265"></span></p>
<pre class="brush: php; title: ; notranslate">
/**
 * BaseConverter provides support of number convertion from any base to
 * decimal base and vice-versa.
 * The code was originally written here:
 * http://www.php.net/manual/en/function.base-convert.php#55204
 * and was afterwards modified to support big number calculations.
 *
 * &lt;b&gt;WARNING!&lt;/b&gt; This code requires your PHP installation to have
 * enabled BCMath extension. See here for more details:
 * http://php.net/manual/en/book.bc.php
 *
 * @author Yervand Aghababyan ( http://fictionalrealm.com )
 * @version 1.0
 */
class BaseConverter {
	/**
	 * Digit list used for conversions to and from base 62
	 * @var string
	 */
	private static $digitList = &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;

	/**
	 * Converts $num number from decimal base to any custom base
	 *
	 * @param $num Your decimal integer. Should be passed as a string if it's
	 * 					bigger than float's maximum value
	 * @param $base Base to which you wish to convert $num (leave it 0 if you
	 * 					are	providing $index or omit if you're using the
	 * 					default base (62))
	 * @param $index If you wish to use the default list of digits
	 * 					(0-1a-zA-Z), omit this option, otherwise provide
	 * 					a string (ex.: &quot;zyxwvu&quot;)
	 * @return string converted number
	 */
	public static function dec2any($num, $base = 62, $index = false) {
		if (!$base) {
			$base = strlen ($index);
		} else if (!$index) {
			$index = substr (self::$digitList, 0, $base);
		}

		$out = &quot;&quot;;
		for($t = floor(log( $num, $base)); $t &gt;= 0; $t--) {
			$a = bcdiv($num, bcpow ($base, $t ), 0);
			$out = $out . substr ($index, $a, 1);
			$num = bcsub($num, (bcmul($a, bcpow($base, $t ))));
		}

		return $out;
	}

	/**
	 * Convert number from Custom base to Decimal
	 * @param $num Your custom-based number (string) (ex.: &quot;11011101&quot;)
	 * @param $base Base with which $num was encoded (leave it 0 if you
	 * 					are providing $index or omit if you're using the
	 * 					default base (62))
	 * @param $index If you wish to use the default list of digits
	 * 					(0-1a-zA-Z), omit this option, otherwise
	 * 					provide a string (ex.: &quot;abcdef&quot;)
	 * @return string decimal number
	 */
	public static function any2dec($num, $base = 62, $index = false) {
		if (! $base) {
			$base = strlen ( $index );
		} else if (! $index) {
			$index = substr ( self::$digitList, 0, $base );
		}

		$out = 0;
		$len = strlen($num) - 1;
		for($t = 0; $t &lt;= $len; $t ++) {
			$out = bcadd($out, bcmul(strpos($index, substr($num, $t, 1 )), bcpow($base, $len - $t )));
		}

		return $out;
	}

}
</pre>
<p>With the above code you&#8217;re free to do any possible base conversions (dec to hex, hex to bin, bin to dec and so on).<br />
Bellow is an example of the class in work:</p>
<pre class="brush: php; title: ; notranslate">
// Converting to base 62
echo BaseConverter::dec2any('1');							// 1
echo BaseConverter::dec2any('2'); 							// 2
echo BaseConverter::dec2any('10');							// a
echo BaseConverter::dec2any('61');							// Z
echo BaseConverter::dec2any('62');							// 10
echo BaseConverter::dec2any('63');							// 11
echo BaseConverter::dec2any('123');							// 1Z
echo BaseConverter::dec2any('78979744647246');				// mqtVtIp8
echo BaseConverter::dec2any('7984516546546463213216');		// 2trjkuyg9ZsJy
echo BaseConverter::dec2any('1646516164654654646464646');	// 8elwAeomcXtCWq

// Converting to decimal numbers
echo BaseConverter::any2dec('10');				// 62
echo BaseConverter::any2dec('mqtVtIp8');		// 78979744647246
echo BaseConverter::any2dec('2trjkuyg9ZsJy');	// 7984516546546463213216
echo BaseConverter::any2dec('8elwAeomcXtCWq');	// 1646516164654654646464646
</pre>
<p>Also keep in mind that the code requires installed <a href="http://php.net/manual/en/book.bc.php">bcmath</a> extension and that if you&#8217;re working with big numbers you need to pass those as string to the functions cause php&#8217;s rounding them so they&#8217;ll fit into a float variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2009/12/27/number-base-converter-converts-numbers-from-any-base-to-decimal-and-vice-versa-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using PHP ssh2 lib to create simple SSH client with ANSI support</title>
		<link>http://fictionalrealm.com/coding/2009/12/25/using-php-ssh2-lib-to-create-simple-ssh-client-with-ansi-support/</link>
		<comments>http://fictionalrealm.com/coding/2009/12/25/using-php-ssh2-lib-to-create-simple-ssh-client-with-ansi-support/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 08:37:18 +0000</pubDate>
		<dc:creator>CyberJoe</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[libssh2]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh client]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=239</guid>
		<description><![CDATA[If you&#8217;re a real geek, you might want to make an ssh client&#8230; using  php, well, this is something that no one will probably ever need to do&#8230; but if you&#8217;re reading this, maybe it happens so that you need it So, to start with, there is a php extension called libssh2, and it&#8217;s really [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a real geek, you might want to make an ssh client&#8230; using  php, well, this is something that no one will probably ever need to do&#8230; but if you&#8217;re reading this, maybe it happens so that you need it <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So, to start with, there is a php extension called libssh2, and it&#8217;s really tricky to install it on some server configurations. I&#8217;m not going to discuss that part here because it&#8217;s purely server administration issue. I will just get to the coding part.</p>
<p>What we want to do here is to create php script that would run from console, will connect to remote ssh server, execute commands, and display output just like every ssh client does. The first problem is &#8211; libssh2 documentation on php site really sucks.</p>
<p><span id="more-239"></span>Connecting to remote server is easy:</p>
<pre class="brush: php; title: ; notranslate">
$connection = ssh2_connect($host, 22);
ssh2_auth_password($connection, $user, $password);
$stream = ssh2_shell($connection);
</pre>
<p>What you do here is basically connect to remote server, and fetch a stream from ssh2_shell function which you will use to do IO operations.</p>
<p>Now here comes the tricky part, according to the manual, the way you do an output to ssh (like execute a command) is to call ssh2_exec function, but this doesn&#8217;t really work well. When you do output using that command,  your ssh stream gets reset, and you can&#8217;t just continue writing new commands that will work based on previous command. It&#8217;s like this &#8211; you cant do a &#8220;cd&#8221; command and then &#8220;ls&#8221;, cause &#8220;ls&#8221; will show contents of folder that was shown before you did &#8220;cd&#8221; (the logged in users home folder). Anyway here is the way I solved it:</p>
<p>You can use simple fwrite() function to work with your $stream variable,  like this</p>
<pre class="brush: php; title: ; notranslate">
fwrite($stream, $command.&quot;\n&quot;);
</pre>
<p>Now getting to the fetching output part, it might sound weird but don&#8217;t use fread() here <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  To get the server&#8217;s output you should use stream_get_contents function instead of fread. If you do &#8211; it works perfectly. Just keep in mind that server output will not appear immediately,  you need to wait for it (do a loop).</p>
<p>So this is nearly all you need to know to setup and maintain a simple ssh2 connection, execute commands, and get output in one session.</p>
<p>Here are some other aspects you might have problems with:</p>
<p>First of all, the obvious one, what if you typed a command like ping or top or something that is going to end only if you press, the Ctr+C keys? the way to imitate the Ctr+C combination is pretty easy, this combination actually sends a signal to the system that&#8217;s terminating the current process, and it&#8217;s just&#8230;.. number 3 character in ASCII table (Bingo! <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</p>
<p>It&#8217;s one of so called ETX signals (like end of text)</p>
<pre class="brush: php; title: ; notranslate">
fwrite($stream, chr(3));
</pre>
<p>You do this command, and ping or top or whatever it is &#8211; terminates.</p>
<p>Next thing, I want to tell you is that in ANSI terminal there is not only text, you can have Midnight Commander ( mc ) which is nice and coloured, and htop and lot&#8217;s of others, how does that work?</p>
<p>Very simple! There&#8217;s an ANSI mode for terminal which is getting some other types of signals, like not only text but &#8220;go to next line&#8221; or &#8220;set foreground colour to green&#8221; e.g. I&#8217;m not going to go through the aspects of ANSI terminal, I will just explain how to enable it on libssh2 because by default it is using simple text mode and output of htop command will be more than weird.</p>
<p>And again it&#8217;s not explained in the manual in any imaginable way, but here is how you do it:</p>
<pre class="brush: php; title: ; notranslate">
$stream = ssh2_shell($connection, 'ansi');
</pre>
<p>PHP Manual says that it&#8217;s possible to give the ANSI parameter to ssh2_exec, but in our case we do not use it (we had problems with the library when trying to implement this) so it appears, through not discussed in manual, that you can pass that parameter to ssh2_shell function as well and when using that stream you will get output in &#8220;ANSI&#8221; way. You just need to make sure you parse it correctly and display to end user as it&#8217;s supposed to be.</p>
<p>So that&#8217;s mainly it about creating this stuff using PHP, feel free to ask if you had any issues, or discovered some other methods <img src='http://fictionalrealm.com/coding/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2009/12/25/using-php-ssh2-lib-to-create-simple-ssh-client-with-ansi-support/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery conflicting with other libraries, solution</title>
		<link>http://fictionalrealm.com/coding/2009/12/23/jquery-conflicting-with-other-libraries-solution/</link>
		<comments>http://fictionalrealm.com/coding/2009/12/23/jquery-conflicting-with-other-libraries-solution/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 16:21:45 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=218</guid>
		<description><![CDATA[What if you already use some library that occupies the $ variable and you want to continue using it and jQuery together.  What happens in this case if you load jQuery is that it will override the variable to jQuery object and you won&#8217;t be able to use your existing library. Possible solutions of this are: Reassign jQuery from [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-228 alignright" style="margin-right: 10px;padding-top: 10px" src="http://fictionalrealm.com/coding/files/2009/12/jquery-logo.png" alt="jQuery logo" width="73" height="73" /></p>
<p>What if you already use some library that occupies the <strong>$</strong> variable and you want to continue using it and jQuery together.  What happens in this case if you load jQuery is that it will override the variable to jQuery object and you won&#8217;t be able to use your existing library. Possible solutions of this are:</p>
<ul>
<li>Reassign jQuery from <strong>$</strong> to something like <strong>$jq.</strong></li>
<li><strong><span style="font-weight: normal">Include jQuery first and after it the other library. After this instead of typing $ you will have to type jQuery. Example:  jQuery(&#8216;#mydivId&#8217;);</span></strong></li>
<li><strong><span style="font-weight: normal">You can also use the <strong>jQuery.noConflict()</strong> method to revert the $ to the value it had before jQuery was included in the page.<br />
<span id="more-218"></span><br />
</span></strong></li>
</ul>
<p>To me the 3rd option seems the best of all. This way you don&#8217;t have to worry about anything at all. Here&#8217;s a small example of it&#8217;s implementation taken from jQuery documentation:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
 &lt;head&gt;
   &lt;script src=&quot;prototype.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
   &lt;script&gt;
     jQuery.noConflict();

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery(&quot;div&quot;).hide();
     });

     // Use Prototype with $(...), even though you've loaded jQuery after loading prototype
     $('someid').hide();
   &lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;&lt;/body&gt;
 &lt;/html&gt;
</pre>
<p>This is in my opinion the cleanest solution to the issue.  Also if you use jQuery plugins load them before calling the jQuery.noConflict() method.</p>
<p>For more information see:</p>
<p><a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">jQuery Documentation: Integration with other Libraries</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2009/12/23/jquery-conflicting-with-other-libraries-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery inline form validation, custom positioning patch</title>
		<link>http://fictionalrealm.com/coding/2009/12/15/a-jquery-inline-form-validation-custom-positioning-patch/</link>
		<comments>http://fictionalrealm.com/coding/2009/12/15/a-jquery-inline-form-validation-custom-positioning-patch/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 15:46:30 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Useful Tools]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[inlive validation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[prompt positioning]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=190</guid>
		<description><![CDATA[Well, after using jQuery inline form validation plugin for some time the most serious problem with it was that it didn&#8217;t allow me to freely customize my UI. If i had a defined design of a form before writing the validation part I always had to alter design so that validation bubbles don&#8217;t pop onto [...]]]></description>
			<content:encoded><![CDATA[<p>Well, after using <a href="http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/">jQuery inline form validation plugin</a> for some time the most serious problem with it was that it didn&#8217;t allow me to freely customize my UI. If i had a defined design of a form before writing the validation part I always had to alter design so that validation bubbles don&#8217;t pop onto something important. Like a &#8220;Invalid CAPTCHA code!&#8221; poping up on the CAPTCHA image or other stuff like this. Check-boxes are also easy &#8220;eaten&#8221; by the validation bubbles.</p>
<p>What i&#8217;ve written is a simple patch for <a href="http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/">jQuery inline form validation plugin</a> allowing custom positioning of the validation bubbles. <strong>It gives you the possibility to override the default positioning by adding <em>promptPosition </em>attribute to the validated element with a value of any </strong><strong>possible</strong><strong> positioning pattern </strong><strong>supported by the plugin</strong><strong> (topLeft, topRight, bottomLeft,  centerRight, bottomRight</strong><em><strong>)</strong>.<span id="more-190"></span> </em>After doing this your validated input field should look something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;input id=&quot;captcha_code&quot; promptPosition=&quot;centerRight&quot; type='text' name='captcha_code' /&gt;
</pre>
<p>And all the magic that happens after customizing your form like this can be seen on the screenshot bellow:</p>
<p><div id="attachment_204" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-204" src="http://fictionalrealm.com/wp-content/uploads/2009/12/custom_positioning_plugin-300x181.jpg" alt="Example of my patch's working" width="300" height="181" /><p class="wp-caption-text">Example of my patch&#039;s working</p></div></p>
<p>The patch was written for <a href="http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/">jQuery inline form validation</a> <strong>version 1.6.2</strong>. It most surely won&#8217;t work with newer or later versions.</p>
<p>You can <strong>download</strong> the patch or the already modified <strong>jquery.validationEngine.js</strong> by clicking the links bellow:</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2009/12/15/a-jquery-inline-form-validation-custom-positioning-patch/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>jQuery Inline Form Validation Engine</title>
		<link>http://fictionalrealm.com/coding/2009/12/02/jquery-inline-form-validation-plugin/</link>
		<comments>http://fictionalrealm.com/coding/2009/12/02/jquery-inline-form-validation-plugin/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 12:52:18 +0000</pubDate>
		<dc:creator>Yervand Aghababyan</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[form validation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://fictionalrealm.com/?p=158</guid>
		<description><![CDATA[Recently I&#8217;ve been surfing the net in search of a jQuery powered form validation plugin, the best of what I found is the jQuery Inline Form Validation Engine. On the left is a screenshot of plugin&#8217;s performance which i find quite good from both programming and design point of views.  The screenshot is taken from [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_164" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-164 " src="http://fictionalrealm.com/wp-content/uploads/2009/12/img_form-300x221.jpg" alt="jQuery Inline Form Validation Engine" width="300" height="221" /><p class="wp-caption-text">jQuery Inline Form Validation Engine</p></div></p>
<p>Recently I&#8217;ve been surfing the net in search of a <a title="jQuery official website" href="http://jquery.com/">jQuery</a> powered form validation plugin, the best of what I found is the <a href="http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/">jQuery Inline Form Validation Engine</a>. On the left is a screenshot of plugin&#8217;s performance which i find quite good from both programming and design point of views.  The screenshot is taken from plugin&#8217;s author&#8217;s website at <a href="http://www.position-absolute.com">http://www.position-absolute.com</a>.</p>
<p>It&#8217;s quite easy to implement in your project and consists from just a couple of JS files one ( one of them contains  error messages and validation rules and the other validation code itself).  Also you have to include a single css file and that&#8217;s all. No images required at all.</p>
<p>You can easily add your own custom validation rules and tweak the stuff that&#8217;s already present in the code. Everything is pretty simple and requires a basic knowledge of JavaScript.</p>
<p><span id="more-158"></span>With this 3 files you get a <strong>really good looking error massage </strong>(you can change the design by tuning the CSS), <strong>regexp validation</strong>, some basic stuff that&#8217;s already implemented like <strong>email validation </strong>and <strong>confirm password field&#8217;s validation</strong>, <strong>typed in value&#8217;s length validation</strong> and <strong>AJAX validation</strong>. All you have to do to enable the validation engine is describe what validation procedures should be applied to a certain field of your form by adding various classes to it and call an initialization function of the validation engine. The end result looks something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form id=&quot;myFormId&quot; method=&quot;post&quot; action=&quot;myform.php&quot;&gt;
    &lt;input id=&quot;email&quot; class=&quot;validate[required, custom[email], ajax[ajaxEmailAvailability]]&quot; name=&quot;email&quot; type=&quot;text&quot; /&gt;
    &lt;input id=&quot;submitButton&quot; type=&quot;submit&quot; value=&quot;Submit Form&quot; /&gt;
&lt;/form&gt;
&lt;script&gt;
    $(&quot;#myFormId&quot;).validationEngine({});
&lt;/script&gt;
</pre>
<p><strong>The Cons of the plugin</strong> in my opinion are:</p>
<ul>
<li>Does not support window resize. When you resize the browser all the validation bubbles shift from the fields they should be attached to. Cause of this you have to close all the bubbles on window.resize event. A fix for this is planned for 1.7 release ( the current version is 1.6.2)</li>
<li>There&#8217;s no way to custom position the validation bubbles and if you got a form with a little complex design it&#8217;s possible that the bubbles will get on some other important stuff (mine was getting on the captcha image when validating the captcha code). It&#8217;s like this &#8211; can tell all the bubbles in the form to show in the upper right, lower right, upper left, lower left and just on the right of the input box but you can&#8217;t tell a specific bubble to appear in your desired location.  (I&#8217;ve written a patch allowing custom positioning located <a href="http://fictionalrealm.com/2009/12/a-jquery-inline-form-validation-custom-positioning-patch/">here</a>)</li>
</ul>
<p>Overall i highly recommend the plugin. It&#8217;s very comfortable to use and get accustomed to. And looks good!</p>
]]></content:encoded>
			<wfw:commentRss>http://fictionalrealm.com/coding/2009/12/02/jquery-inline-form-validation-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
