<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">

 <title>Mohd Amree</title>
 
 <link href="http://ieatbinary.com/" />
 <updated>2012-01-27T05:29:16-08:00</updated>
 <id>http://ieatbinary.com/</id>
 <author>
   <name>Mohd Amree</name>
   <email>amree@linux.org.my</email>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ieatbinary" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="ieatbinary" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>See Full Referrer URL in Google Analytics</title>
   <link href="http://ieatbinary.com/2012/01/21/see-full-referrer-url-in-google-analytics/" />
   <updated>2012-01-21T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2012/01/21/see-full-referrer-url-in-google-analytics</id>
   <content type="html">&lt;h1&gt;See Full Referrer URL in Google Analytics&lt;/h1&gt;

&lt;p&gt;Most of the tutorial on the web focuses on the old version of Google Analytics. So, after poking around Google Analytics, I found out that there are two ways to see it (I stopped looking once I found the second method, so, there might be more).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to Custom Reporting tab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Edit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you've already added a tab, just click &amp;quot;+add report tab&amp;quot; for this purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Put the name of this report.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose Flat Table as the type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the Dimensions, search for Full Referrer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the Metrics, use Unique Visitors (or anything you see fits).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Save.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. You can refer to the screenshot below if you're feeling lost:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/posts/2012-01-21-ga.png" width="584"&gt;&lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A Not So Simple Introduction to Git</title>
   <link href="http://ieatbinary.com/2012/01/07/a-not-so-simple-introduction-to-git/" />
   <updated>2012-01-07T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2012/01/07/a-not-so-simple-introduction-to-git</id>
   <content type="html">&lt;h1&gt;A Not So Simple Introduction to Git&lt;/h1&gt;

&lt;p&gt;Found another presentation from Speaker Deck. I find it useful with its examples. Check it out.&lt;/p&gt;

&lt;script src="http://speakerdeck.com/embed/4ecfc649eee53a005000b88b.js"&gt;&lt;/script&gt;
</content>
 </entry>
 
 <entry>
   <title>A Good Introduction to Agile and Scrum</title>
   <link href="http://ieatbinary.com/2012/01/07/a-good-introduction-to-agile-and-scrum/" />
   <updated>2012-01-07T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2012/01/07/a-good-introduction-to-agile-and-scrum</id>
   <content type="html">&lt;h1&gt;A Good Introduction to Agile and Scrum&lt;/h1&gt;

&lt;p&gt;Found this in Speaker Deck. Love the simple explanation.&lt;/p&gt;

&lt;script src="http://speakerdeck.com/embed/4ea7b7b86428bd0054008cd4.js"&gt;&lt;/script&gt;
</content>
 </entry>
 
 <entry>
   <title>Renaming Author in Git</title>
   <link href="http://ieatbinary.com/2012/01/05/renaming-author-in-git/" />
   <updated>2012-01-05T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2012/01/05/renaming-author-in-git</id>
   <content type="html">&lt;h1&gt;Renaming Author in Git&lt;/h1&gt;

&lt;p&gt;In Linux, I use Netbeans a lot as a diff viewer. For now, I think it's the best diff viewer in Linux with side by side comparison and its easy to navigate UI. Plus, it's free.&lt;/p&gt;

&lt;p&gt;Recently, I noticed that there are other authors with a different name in my Git's history. Apparently, I've accidentally committed into the repository using a different author's name and email. This is mainly due to the way Netbeans stores author's information history.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/posts/2011-01-05-diff.png" width="584"&gt;&lt;/p&gt;

&lt;p&gt;So, in order to fix it, I ran this little script from Github in my master branch.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;

git filter-branch --env-filter &lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;

&lt;span class="s1"&gt;an=&amp;quot;$GIT_AUTHOR_NAME&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;am=&amp;quot;$GIT_AUTHOR_EMAIL&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;cn=&amp;quot;$GIT_COMMITTER_NAME&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;cm=&amp;quot;$GIT_COMMITTER_EMAIL&amp;quot;&lt;/span&gt;

&lt;span class="s1"&gt;if [ &amp;quot;$GIT_COMMITTER_EMAIL&amp;quot; = &amp;quot;your@email.to.match&amp;quot; ]&lt;/span&gt;
&lt;span class="s1"&gt;then&lt;/span&gt;
&lt;span class="s1"&gt;    cn=&amp;quot;Your New Committer Name&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;    cm=&amp;quot;Your New Committer Email&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;fi&lt;/span&gt;
&lt;span class="s1"&gt;if [ &amp;quot;$GIT_AUTHOR_EMAIL&amp;quot; = &amp;quot;your@email.to.match&amp;quot; ]&lt;/span&gt;
&lt;span class="s1"&gt;then&lt;/span&gt;
&lt;span class="s1"&gt;    an=&amp;quot;Your New Author Name&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;    am=&amp;quot;Your New Author Email&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;fi&lt;/span&gt;

&lt;span class="s1"&gt;export GIT_AUTHOR_NAME=&amp;quot;$an&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;export GIT_AUTHOR_EMAIL=&amp;quot;$am&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;export GIT_COMMITTER_NAME=&amp;quot;$cn&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;export GIT_COMMITTER_EMAIL=&amp;quot;$cm&amp;quot;&lt;/span&gt;
&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;To push it into the server, I need to use &lt;code&gt;git push -f&lt;/code&gt; instead of &lt;code&gt;git push&lt;/code&gt;. If you use the latter command, you'll end up with a merged history (every commit will have another one identical to it). &lt;/p&gt;

&lt;p&gt;If you use Redmine, you may need to fetch change set. Just run this command in your Redmine's directory:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;script/runner &amp;quot;Repository.fetch_changesets&amp;quot; -e production
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Netbeans committer's info are stored in (change the path based on your version):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~/.netbeans/7.0/config/Preferences/org/netbeans/modules/git.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;References:&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://theelitist.net/git-change-revision-author"&gt;http://theelitist.net/git-change-revision-author&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://help.github.com/change-author-info/"&gt;http://help.github.com/change-author-info/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Git Remote Commands</title>
   <link href="http://ieatbinary.com/2011/12/11/git-remote-commands/" />
   <updated>2011-12-11T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2011/12/11/git-remote-commands</id>
   <content type="html">&lt;h1&gt;Git Remote Commands&lt;/h1&gt;

&lt;p&gt;View some remote &lt;strong&gt;information&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git remote show origin
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;List&lt;/strong&gt; all remote branch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git branch -r
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Pushing&lt;/strong&gt; a branch to the remote:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git push origin newfeature
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or when you want to &lt;strong&gt;push in the checkout branch&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git push origin HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And use &lt;code&gt;-u&lt;/code&gt; to &lt;strong&gt;push and track&lt;/strong&gt; the remote branch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git push -u origin newfeature
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make an existing git branch to &lt;strong&gt;track a remote&lt;/strong&gt; branch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git branch --set-upstream newfeature1 origin/newfeature1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Deleting&lt;/strong&gt; a remote branch:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git push origin :newfeature
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Refresh&lt;/strong&gt; remote branch list:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git remote prune origin
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Checkout&lt;/strong&gt; a remote branch and &lt;strong&gt;track&lt;/strong&gt; it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git checkout -t origin/newfeature
&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Read MyKad</title>
   <link href="http://ieatbinary.com/2011/12/05/how-to-read-mykad/" />
   <updated>2011-12-05T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2011/12/05/how-to-read-mykad</id>
   <content type="html">&lt;h1&gt;How to Read MyKad&lt;/h1&gt;

&lt;p&gt;I've decided to merge posts about reading MyKad from my previous blog into a single post.&lt;/p&gt;

&lt;p&gt;Notes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;original codes were written by Xenon&lt;/strong&gt; from &lt;a href="http://forum.lowyat.net/"&gt;Lowyat.net&lt;/a&gt;. Somehow, he managed to reverse engineer MyKad's APDU so that we can read it without buying any SDK.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This application &lt;strong&gt;only&lt;/strong&gt; reads data from Jabatan Pendaftaran Negara (JPN).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Xenon also wrote two small example applications to read MyKad. I've listed them based on the programming language. Click on the link to download it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/amree/mykad-c"&gt;Visual C&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/amree/mykad-vb.net"&gt;Visual Basic .NET&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since there's no Java implementation of the code yet, I've decided to develop one. You can also get the source code from my &lt;a href="http://github.com/amree/mykad-java"&gt;Github&lt;/a&gt;. It's written using Netbeans.&lt;/p&gt;

&lt;p&gt;I'm not going to give explanation about the code. Instead, I'm going to guide you guys on how to setup your system (Linux and Windows) so that you can read the Java application to read a MyKad.&lt;/p&gt;

&lt;h1&gt;Windows&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download &lt;a href="http://www.musclecard.com/middle.html"&gt;Windows binary&lt;/a&gt; of JPC/SC Java API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the application which is in Netbeans project format from my Github.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You &lt;strong&gt;must include&lt;/strong&gt; &lt;code&gt;jpcsc.jar&lt;/code&gt; as the library. You can get the file from Step 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You also &lt;strong&gt;must put&lt;/strong&gt; &lt;code&gt;jpcsc.dll&lt;/code&gt; into your main project folder. Furthermore, if you want to distribute the application, you need to put it together with your main jar file. You can also get the file from Step 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Plug in your reader (obviously).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the application. I'd recommend you run it through Netbeans.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert a MyKad.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait until the application finish reading it (usually once the LED stop blinking).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A GUI will be displayed presenting your MyKad data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there's no data showing, there's a possibility that your MyKad chip is spoiled.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;Linux&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login as a &lt;strong&gt;root&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download &lt;a href="http://pcsclite.alioth.debian.org/"&gt;PCSC Lite&lt;/a&gt; and install it. You need to put some parameters in your &lt;code&gt;./configure&lt;/code&gt; if you want to enable &lt;code&gt;libusb&lt;/code&gt; support. Please check the &lt;code&gt;README&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;tar xvjf pcsc-lite-1.8.1.tar.bz2
cd pcsc-lite-1.8.1
./configure --enable-libusb --disable-libudev
make
make install
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download and install your reader's driver. I'm using &lt;a href="http://www.hidglobal.com/prod_detail.php?prod_id=171"&gt;OMNIKEY 5321 USB&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get &lt;a href="http://www.musclecard.com/middle.html"&gt;Windows binary&lt;/a&gt; of JPC/SC Java API. It's for Windows but it also has a precompiled Linux library in it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract, copy and update:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;unzip jpcsc-0.8.0.zip
cd jpcsc/bin/linux
cp libjpcsc.so /usr/lib
ldconfig
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start the pcsc service:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pcscd -d -f
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should get something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;00000000 pcscdaemon.c:233:main() pcscd set to foreground with debug send to stdout
00000044 configfile.l:287:DBGetReaderList() Parsing conf file: /usr/local/etc/reader.conf.d
00000008 pcscdaemon.c:518:main() pcsc-lite 1.8.1 daemon ready.
00001566 hotplug_libusb.c:514:HPAddHotPluggable() Adding USB device: 4:2:0
00008631 readerfactory.c:934:RFInitializeReader() Attempting startup of OMNIKEY CardMan 5x21 (USB iClass Reader) 00 00 using /usr/local/lib/pcsc/drivers/ifdokrfid_lnx_i
00000179 readerfactory.c:824:RFBindFunctions() Loading IFD Handler 3.0 HID HID Global OMNIKEY RFID  IA32 v2.9.1
00300863 readerfactory.c:296:RFAddReader() Using the reader polling thread
00001975 readerfactory.c:934:RFInitializeReader() Attempting startup of OMNIKEY CardMan 5x21 (USB iClass Reader) 00 01 using /usr/local/lib/pcsc/drivers/ifdokrfid_lnx_i
00000012 readerfactory.c:738:RFLoadReader() Reusing already loaded driver for /usr/local/lib/pcsc/drivers/ifdokrfid_lnx_i686-2.9.1.bundle/Contents/Linux/ifdokrfid.so
00000014 readerfactory.c:824:RFBindFunctions() Loading IFD Handler 3.0 HID HID Global OMNIKEY RFID  IA32 v2.9.1
00424985 readerfactory.c:453:RFAddReader() Using the reader polling thread
00444313 readerfactory.c:1301:RFWaitForReaderInit() Waiting init for reader: OMNIKEY CardMan 5x21 (USB iClass Reader) 00 01
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the Java application, it should be working right  now.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it, again, the full credit should goes to Xenon :)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>HUSM at Malaysia Open Source Conference 2011</title>
   <link href="http://ieatbinary.com/2011/07/12/husm-at-malaysia-open-source-conference-2011/" />
   <updated>2011-07-12T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2011/07/12/husm-at-malaysia-open-source-conference-2011</id>
   <content type="html">&lt;h1&gt;HUSM at Malaysia Open Source Conference 2011&lt;/h1&gt;

&lt;p&gt;On the 5th of July 2011, Hospital Universiti Sains Malaysia (HUSM) has been chosen as one of the speakers in Malaysia Open Source Conference 2011. It was presented by &lt;a href="http://my.linkedin.com/in/yusdirman"&gt;Mr Yusdirman Bin Yusoff&lt;/a&gt; as  “Open Source in Health Care: HUSM 10 Years of Innovation”.&lt;/p&gt;

&lt;p&gt;Basically it’s about &lt;strong&gt;what&lt;/strong&gt; and &lt;strong&gt;how&lt;/strong&gt; HUSM as one among few hospitals in Malaysia managed to develop its own Total Hospital Information System thus saved millions ringgit of taxpayers money. This is actually the first step for us (IT Unit, HUSM) to show to the world what we have done in this 10 years where most hospitals not willing to do.&lt;/p&gt;

&lt;script src="http://speakerdeck.com/embed/4efe89ef1b765f004c0015ea.js"&gt;&lt;/script&gt;
</content>
 </entry>
 
 <entry>
   <title>How to enable MySQL Support in Qt SDK for Windows</title>
   <link href="http://ieatbinary.com/2011/07/11/how-to-enable-mysql-support-in-qt-sdk-for-windows/" />
   <updated>2011-07-11T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2011/07/11/how-to-enable-mysql-support-in-qt-sdk-for-windows</id>
   <content type="html">&lt;h1&gt;How to enable MySQL Support in Qt SDK for Windows&lt;/h1&gt;

&lt;p&gt;It has been quite a while since I wrote the previous guide. Since that particular post gained a lot of visitors, I decided to write a new guide based on the new Qt SDK and MySQL so that it will help people with new version for both softwares.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download Qt SDK and install it. In my case, I installed it at &lt;code&gt;C:\QtSDK&lt;/code&gt;. You must make sure that you’ve chosen to install Qt Sources. If you have Qt SDK installed but you haven’t install Qt sources, just go to &lt;strong&gt;Start &amp;gt; All Programs &amp;gt; Qt SDK &amp;gt; Maintain Qt SDK&lt;/strong&gt; to install it.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/posts/2011-07-11-qt.png" alt="alt text"&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download MySQL and install it. In my case, I choose to install it at:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C:\Program Files (x86)\MySQL\MySQL Server 5.5. 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You don’t need to install everything if you want to compile the plugin. Make sure you will at least choose to &lt;strong&gt;install Client C API Library&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/posts/2011-07-11-mysql.png" alt="alt text"&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;strong&gt;Start &amp;gt; All Programs &amp;gt; Qt SDK &amp;gt; Desktop &amp;gt; Qt 4.7.3 for Desktop (MingW)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run these commands (change according to your environment):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt; set mysql=C:\PROGRA~2\MySQL\MYSQLS~1.5
&amp;gt; cd \
&amp;gt; cd QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql\

&amp;gt; qmake &amp;quot;INCLUDEPATH+=%mysql%\include&amp;quot; &amp;quot;LIBS+=%mysql%\lib\libmysql.lib&amp;quot; -o Makefile mysql.pro
&amp;gt; mingw32-make

&amp;gt; qmake &amp;quot;INCLUDEPATH+=%mysql%\include&amp;quot; &amp;quot;LIBS+=%mysql%\lib\libmysql.lib&amp;quot; -o Makefile mysql.pro &amp;quot;CONFIG+=release&amp;quot;
&amp;gt; mingw32-make
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should be able to run these commands &lt;strong&gt;without any error&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’ll find two directories (&lt;strong&gt;debug&lt;/strong&gt; and &lt;strong&gt;release&lt;/strong&gt;) created in the current directory. &lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;debug&lt;/strong&gt; directory, you’ll find &lt;code&gt;libqsqlmysqld4.a&lt;/code&gt; and &lt;code&gt;qsqlmysqld4.dll&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Meanwhile, in &lt;strong&gt;release&lt;/strong&gt; directory, you’ll find &lt;code&gt;libqsqlmysql4.a&lt;/code&gt; and &lt;code&gt;qsqlmysql4.dll&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Copy all these 4 files into&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\sqldrivers
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy &lt;code&gt;libmysql.dll&lt;/code&gt; (found in your MySQL installation directory) into C:\Windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create new project and put these codes to test your new plugin&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include &amp;lt;QApplication&amp;gt;
#include &amp;lt;QtSql&amp;gt;

int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);
  qDebug() &amp;lt;&amp;lt; QSqlDatabase::drivers();
  return a.exec();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure you have QtSql Module in your project configuration file (.pro file)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;QT += sql
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You’ll get these outputs showing that your Qt has supports for MySQL:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(&amp;quot;QSQLITE&amp;quot;, &amp;quot;QMYSQL3&amp;quot;, &amp;quot;QMYSQL&amp;quot;, &amp;quot;QODBC3&amp;quot;, &amp;quot;QODBC&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Things to watch out for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You can’t use MySQL 64 Bit (at the moment)&lt;/strong&gt; to compile the plugin.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you’ll &lt;strong&gt;use short path&lt;/strong&gt; type if you’ve installed MySQL into directory’s name containing spaces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Load sql module&lt;/strong&gt; in your .pro file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tested on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;11/7/2011 – Windows 64 Bit, MySQL Server 5.5.1 32 Bit (Community Version) and Qt 4.7.3.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr&gt;

&lt;p&gt;&lt;em&gt;I’m currently dedicating most of my time developing Rails application. So, I strongly encourage you guys to get help at &lt;a href="http://developer.qt.nokia.com/"&gt;Qt Developer Network&lt;/a&gt; if you have any problem. Those guys are very helpful.&lt;/em&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>A Simple Working Example for Qt NCReport</title>
   <link href="http://ieatbinary.com/2011/07/09/a-simple-working-example-for-qt-ncreport/" />
   <updated>2011-07-09T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2011/07/09/a-simple-working-example-for-qt-ncreport</id>
   <content type="html">&lt;h1&gt;A Simple Working Example for Qt NCReport&lt;/h1&gt;

&lt;h2&gt;Windows&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download NCReport with MingW for Windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install NCReport at &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C:\NCReport\2.6.1.mingw.eval
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the full &lt;a href="https://github.com/amree/ncreport-example"&gt;source code&lt;/a&gt; of the project at my Github.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to Projects (bar at the left) &amp;gt; Run Settings &amp;gt; Click Details on the Run Environment &amp;gt; Edit PATH’s variable and append the following line at the end of the string.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;;C:\NCReport\2.6.1.mingw.eval\bin
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the project in &lt;strong&gt;Debug&lt;/strong&gt; and &lt;strong&gt;Release&lt;/strong&gt; mode. You should be able to run the report by clicking the button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tested on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows 7 (64 bit), NCReport 2.6.1 with MingW for Windows, QtSDK 1.1.2, Qt 4.7.3 and Qt Creator 2.2.1.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Linux&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download NCReport for Linux.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install NCReport at &lt;code&gt;/opt/ncreport&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the full &lt;a href="https://github.com/amree/ncreport-example"&gt;source code&lt;/a&gt; of the project at my Github.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the project in &lt;strong&gt;Debug&lt;/strong&gt; and &lt;strong&gt;Release&lt;/strong&gt; mode. You should be able to run the report by clicking the button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tested on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slackware 13.37 (32 Bit), NCReport 2.6.1 for Linux, QtSDK 1.1.2, Qt 4.7.3 and Qt Creator 2.2.1&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Using Sybase with Ruby on Rails on Linux</title>
   <link href="http://ieatbinary.com/2011/07/01/using-sybase-with-ruby-on-rails-on-linux/" />
   <updated>2011-07-01T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2011/07/01/using-sybase-with-ruby-on-rails-on-linux</id>
   <content type="html">&lt;h1&gt;Using Sybase with Ruby on Rails on Linux&lt;/h1&gt;

&lt;p&gt;This guide will help you (mostly will help me in the future) to configure your Ruby on Rails to support connection to Sybase using sybase-ctlib in Linux. I wrote this tutorial after everything’s good, so, I might miss a few steps that I’ve forgotten. Feel free to comment about it.&lt;/p&gt;

&lt;p&gt;My setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby v1.9.2p180&lt;/li&gt;
&lt;li&gt;Gem v1.8.5&lt;/li&gt;
&lt;li&gt;RVM 1.6.14&lt;/li&gt;
&lt;li&gt;Linux Slackware (32 bit)&lt;/li&gt;
&lt;li&gt;Sybase Adaptive Server Enterprise v15&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Files you’ll need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="http://www.unixodbc.org/download.html"&gt;unixODBC v2.3.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.freetds.org/software.html"&gt;FreeTDS v0.82&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.sybase.com/"&gt;Sybase Adaptive Server Enterprise v15&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://raa.ruby-lang.org/project/sybase-ctlib/"&gt;sybase-ctlib v0.2.12&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, after you’ve downloaded all the files, let’s start by installing them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install unixODBC&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ tar zxvf unixODBC-2.3.0.tar.gz
$ cd unixODBC-2.3.0
$ ./configure --prefix=/usr/local/unix-odbc
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Install FreeTDS&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ tar zxvf freetds-stable.tar.gz
$ cd freetds-0.8.2
$ ./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unix-odbc
$ make
$ make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Let’s do some testing with &lt;strong&gt;FreeTDS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/usr/local/freetds/etc/freetds.conf&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ini"&gt;&lt;span class="k"&gt;[server]&lt;/span&gt;
&lt;span class="na"&gt;host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;www.server.com&lt;/span&gt;
&lt;span class="na"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;6060&lt;/span&gt;
&lt;span class="na"&gt;tds version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;5.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Run these commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd /usr/local/freetds/bin/
$ ./tsql -S server -U username -P password
locale is &amp;quot;C/UTF-8/C/C/C/C&amp;quot;
locale charset is &amp;quot;UTF-8&amp;quot;Msg 2401, Level 11, State 2, Server SERVER, Line 0Character set conversion is not available between client character set 'utf8' and server character set 'iso_1'.

Msg 2411, Level 10, State 1, Server SERVER, Line 0
No conversions will be done.

Msg 5704, Level 10, State 2, Server SERVER, Line 0
Changed client character set setting to '&amp;lt;NULL&amp;gt;'.

1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That means everything’s good.&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/usr/local/unix-odbc/etc/odbc.ini&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ini"&gt;&lt;span class="k"&gt;[sybase]&lt;/span&gt;
&lt;span class="na"&gt;Driver&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;FreeTDS&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;Sybase Database with FreeTDS&lt;/span&gt;
&lt;span class="na"&gt;Trace&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;No&lt;/span&gt;
&lt;span class="na"&gt;Server&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;www.server.com&lt;/span&gt;
&lt;span class="na"&gt;Port&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;6060&lt;/span&gt;
&lt;span class="na"&gt;TDS Version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;5.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Edit &lt;code&gt;/usr/local/unix-odbc/etc/odbcinst.ini&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ini"&gt;&lt;span class="k"&gt;[FreeTDS]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;v0.63 with protocol v8.0&lt;/span&gt;
&lt;span class="na"&gt;Driver&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/local/freetds/lib/libtdsodbc.so&lt;/span&gt;
&lt;span class="na"&gt;UsageCount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Time for testing, this time, it’s for &lt;strong&gt;unixODBC&lt;/strong&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd /usr/local/unix-odbc/bin
$ ./sql sybase username password
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Install &lt;strong&gt;Sybase Adaptive Server Enterprise&lt;/strong&gt; and export some variables:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;SYBASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/sybase
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;SYBASE_OCS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/opt/sybase/OCS-15_0/
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Install sybct-ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ tar zxvf sybct-ruby-0.2.12.tar.gz
$ cd sybct-ruby-0.2.12
$ vi extconf.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Edit your &lt;code&gt;extconf.rb&lt;/code&gt;. Mine would look like this. After that, generate &lt;code&gt;Makefile&lt;/code&gt; and compile it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ruby extconf.rb
creating Makefile
$ make
gcc -shared -o sybct.so sybct.o -L. -L/home/amree/.rvm/rubies/ruby-1.9.2-p180/lib -Wl,-R/home/amree/.rvm/rubies/ruby-1.9.2-p180/lib -L/opt/sybase/OCS-15_0/lib   -lsybct -lsybcs -lsybtcl -lsybcomn -lsybintl -rdynamic -ldl -lnsl -lm -Wl,-R -Wl,/home/amree/.rvm/rubies/ruby-1.9.2-p180/lib -L/home/amree/.rvm/rubies/ruby-1.9.2-p180/lib -lruby  -lpthread -lrt -ldl -lcrypt -lm   -lc
$
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Everthing looks good. Time for Sybase’s configuration:&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/opt/sybase/interfaces&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;SERVER
    master tcp ether www.server.com 6060
    query tcp ether www.server.com 6060
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Please be careful about the file’s whitespace. You can read more about the file settings at &lt;a href="http://www.outlands.demon.co.uk/sybase/index.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Time for some tests:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd sample
$ ruby -I ../ ./sqlsample.rb -S SERVER -U username -P password
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Just make sure you got connected, I did get some errors about privileges or something, but in the end I can query just fine. So, if you didn’t get any weird errors as if your Ruby cannot load sybsql, you should now put the necessary files into the correct path so that it can be loaded anywhere you want. To list down all your load path for Ruby, you can use &lt;code&gt;irb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since the sample ran fine, it’s time to put all the necessary files in your Ruby’s load path.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ irb
ruby-1.9.2-p180 :001 &amp;gt; $LOAD_PATH
 =&amp;gt; #... your load paths here
ruby-1.9.2-p180 :002 &amp;gt; quit
$ cp sybct.o sybct.so sybct.rb sybsql.rb /home/amree/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/i686-linux
$ irb
ruby-1.9.2-p180 :001 &amp;gt; require &amp;quot;sybsql.rb&amp;quot;
 =&amp;gt; true
ruby-1.9.2-p180 :002 &amp;gt; query=SybSQL.new( {'S'=&amp;gt;'SERVER', 'U'=&amp;gt;'username', 'P'=&amp;gt;'password'} )
 =&amp;gt; #... some weird things
ruby-1.9.2-p180 :003 &amp;gt; raise &amp;quot;ERROR: use dbname ...&amp;quot; unless( query.sql_norow(&amp;quot;use dbname&amp;quot;) )
 =&amp;gt; nil
ruby-1.9.2-p180 :004 &amp;gt; query.sql(&amp;quot;select top 10 * from table&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The last line (query) should ran without any errors. It’s time for your Rails database configuration.&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;database.yml&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;development:
  adapter: sybase
  host: SERVER
  username: username
  password: password
  database: dbname
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Install &lt;strong&gt;activerecord-sybase-adapter&lt;/strong&gt; gem. You need to use this command to make sure there’s no error.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install activerecord-sybase-adapter -s http://gems.rubyonrails.org
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Put &lt;strong&gt;activerecord-sybase-adapter&lt;/strong&gt; in your &lt;code&gt;Gemfile&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem 'activerecord-sybase-adapter' 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Use bundler:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ bundle install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Everything should be working by now. However, I do notice that you can’t do queries that involve limiting the result. It’s most probably because of the way Sybase’s queries work. For an example, I have to use &lt;code&gt;table.find_all_by(&amp;quot;col&amp;quot;)&lt;/code&gt; instead of &lt;code&gt;table.find_by(&amp;quot;col&amp;quot;)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That’s it folks and good luck! Remember, feel free to comment if you got something to improve or correct this guide :)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Running Multiple MySQL on a Single Server</title>
   <link href="http://ieatbinary.com/2011/03/15/running-multiple-mysql-on-a-single-server/" />
   <updated>2011-03-15T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2011/03/15/running-multiple-mysql-on-a-single-server</id>
   <content type="html">&lt;h1&gt;Running Multiple MySQL on a Single Server&lt;/h1&gt;

&lt;p&gt;I’m pretty sure I’m going to forget these steps, so, just to be safe, I’m putting it here.&lt;/p&gt;

&lt;p&gt;I’m dividing this tutorial into two sections, one for default MySQL that comes from Slackware and the other one is for new MySQL.&lt;/p&gt;

&lt;h2&gt;Using the Default MySQL&lt;/h2&gt;

&lt;p&gt;We need to create separate (different from the default) directory for the data to be stored. I’m going to create a new one for it. I’m going to name the directory as &lt;code&gt;mysql-1&lt;/code&gt;. Make sure you use full path when running &lt;code&gt;mysql_install_db&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd /var/lib
$ mkdir mysql-1
$ chown -R mysql.mysql mysql-1
$ mysql_install_db --datadir=/var/lib/mysql-1 --user=mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We also need a new configuration file so that it won’t clash with the default MySQL.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cp /etc/my-small.cnf /etc/my-1.cnf
$ nano /etc/my-1.cnf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These are the settings that I’ve changed from the default file (other settings remain unchanged).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[client]
port = 3307
socket = /var/run/mysql/mysql-1.sock

[mysqld]
port = 3307
socket = /var/run/mysql/mysql-1.sock
server-id = 10

innodb_data_home_dir = /var/lib/mysql-1/
innodb_log_group_home_dir = /var/lib/mysql-1/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To run our newly configured MySQL instance, use this command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ /usr/bin/mysqld_safe --defaults-file=/etc/my-1.cnf --datadir=/var/lib/mysql-1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;By checking background process, you should see something like this&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ps ax | grep mysql

23416 pts/1    S      0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my-1.cnf --datadir=/var/lib/mysql-1
23515 pts/1    Sl     0:00 /usr/libexec/mysqld --defaults-file=/etc/my-1.cnf --basedir=/usr --datadir=/var/lib/mysql-1 --user=mysql --log-error=/var/lib/mysql-1/eebox.err --pid-file=/var/lib/mysql-1/eebox.pid --socket=/var/run/mysql/mysql-1.sock --port=3307
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Time for some test, we need to make sure we’re connecting to the correct server. One way to do this is by checking the &lt;code&gt;server_id&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mysql -u root -h 127.0.0.1 -P 3307
mysql&amp;gt; SHOW VARIABLES LIKE &amp;quot;server_id&amp;quot;;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 10    |
+---------------+-------+
1 row in set (0.00 sec)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, we have the same server_id as we specified in our my-1.cnf. You can use this command to shut it down.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mysqladmin -h 127.0.0.1 -P 3307 shutdown
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Using new Downloaded MySQL&lt;/h2&gt;

&lt;p&gt;Download &lt;a href="http://dev.mysql.com/downloads/"&gt;MySQL Download&lt;/a&gt; &amp;gt; MySQL Community Server &amp;gt; Linux Generic &amp;gt; Linux – Generic 2.6 (x86, 32-bit), Compressed TAR Archive&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cp mysql-5.5.9-linux2.6-i686.tar.gz /opt
$ cd opt
$ tar zxvf mysql-5.5.9-linux2.6-i686.tar.gz
$ mv mysql-5.5.9-linux2.6-i686 mysql
$ cd mysql
$ chown -R mysql.mysql .
$ ./scripts/mysql_install_db --user=mysql
$ cp support-files/my-small.cnf /etc/my-2.cnf
$ nano /etc/my-2.cnf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;/etc/my-2.cnf&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[client]
port = 3308
socket = /var/run/mysql/mysql-2.sock

[mysqld]
port = 3308
socket = /var/run/mysql/mysql-2.sock
server-id = 20

innodb_data_home_dir = /var/lib/mysql-1/
innodb_log_group_home_dir = /var/lib/mysql-1/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To run it, you need to specify some parameters&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/opt/mysql/bin/mysqld --defaults-file=/etc/my-2.cnf --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/eebox.err
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To shut it down, you can use the following command&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;./bin/mysqladmin -h 127.0.0.1 -P 3308 shutdown
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can test the server connection just like the method I used above.&lt;/p&gt;

&lt;p&gt;That's it, good luck!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Adding memcached support to PHP in Slackware 13.1</title>
   <link href="http://ieatbinary.com/2010/10/09/adding-memcached-support-to-php-in-slackware-13-1/" />
   <updated>2010-10-09T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2010/10/09/adding-memcached-support-to-php-in-slackware-13-1</id>
   <content type="html">&lt;h1&gt;Adding memcached support to PHP in Slackware 13.1&lt;/h1&gt;

&lt;p&gt;I just started learning Zend Framework and in one of the tutorials I read, I need to enable memcached in my PHP which is not available by default.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Install &lt;a href="http://slackbuilds.org/repository/13.1/libraries/libevent/"&gt;libevent&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install &lt;a href="http://slackbuilds.org/repository/13.1/network/memcached/"&gt;memcached&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install &lt;a href="http://slackbuilds.org/repository/13.1/libraries/libmemcached/"&gt;libmemcached&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install memcache.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget http://pecl.php.net/get/memcache-2.2.6.tgz
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
phpize &amp;amp;&amp;amp; ./configure --enable-memcache &amp;amp;&amp;amp; make
cp modules/memcache.so /usr/lib/php/extensions/
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Load the module using .ini files in /etc/php&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;touch /etc/php/memcached.ini
echo 'extension=memcache.so' &amp;gt; /etc/php/memcached.ini
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Put this file in your web directory and run it. It should be rendered without any error.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$memcache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Memcache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$memcache&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;localhost&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11211&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Could not connect&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$memcache&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getVersion&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Server&amp;#39;s version: &amp;quot;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$version&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&amp;lt;br/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$tmp_object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="k"&gt;stdClass&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$tmp_object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;str_attr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;test&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$tmp_object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;int_attr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$memcache&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$tmp_object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Failed to save data at the server&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Store data in the cache (data will expire in 10 seconds)&amp;lt;br/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$get_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$memcache&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Data from the cache:&amp;lt;br/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$get_result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://my2.php.net/manual/en/memcache.installation.php"&gt;http://my2.php.net/manual/en/memcache.installation.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://stackoverflow.com/questions/1442411/using-memcache-vs-memcached-with-php"&gt;http://stackoverflow.com/questions/1442411/using-memcache-vs-memcached-with-php&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Configuring Linux to work with NVidia Hybrid SLI Technology</title>
   <link href="http://ieatbinary.com/2010/02/21/configuring-linux-to-work-with-nvidia-hybrid-sli-technology/" />
   <updated>2010-02-21T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2010/02/21/configuring-linux-to-work-with-nvidia-hybrid-sli-technology</id>
   <content type="html">&lt;h1&gt;Configuring Linux to work with NVidia Hybrid SLI Technology&lt;/h1&gt;

&lt;p&gt;First of all, at the time of this writing, NVIDIA Hybrid SLI Technology is &lt;a href="http://www.nvnews.net/vbulletin/showpost.php?p=1613349&amp;postcount=2"&gt;not supported&lt;/a&gt; on Linux and without proper configuration, you won’t even be able to load your Desktop Environment such as Xfce.&lt;/p&gt;

&lt;p&gt;That’s not the only problem, based on an &lt;a href="http://www.nvnews.net/articles/hybrid_sli_interview/index.shtml"&gt;interview&lt;/a&gt; with NVIDIA’s Tom Petersen, one of its main feature is called HybridPower which basically allows users to shut off the graphics card when not needed and dramatically reduce power consumption. This means, there is a possibility that if we can’t find a way to turn off the second GPU, it will consume more power that it should be. &lt;/p&gt;

&lt;p&gt;But that’s another problem. Right now, we just want to boot into our Desktop Environment properly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Running &lt;code&gt;startx&lt;/code&gt; would show these error messages from &lt;code&gt;/var/log/Xorg.0.log&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(!!) More than one possible primary device found
(--) PCI: (0:2:0:0) 10de:06e8:1028:0271 rev 161, Mem @ 0xae000000/16777216, 0xd0000000/268435456, 0xac000000/33554432, I/O @ 0x00004000/128
(--) PCI: (0:3:0:0) 10de:0866:1028:0271 rev 177, Mem @ 0xaa000000/16777216, 0xb0000000/268435456, 0xcc000000/33554432, I/O @ 0x00005000/128, BIOS @ 0x????????/131072
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate the default configuration for your X (using root):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ nvidia-xconfig
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the list of the GPUs.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ lspci
02:00.0 VGA compatible controller: nVidia Corporation G98 [GeForce 9200M GS] (rev a1)
03:00.0 VGA compatible controller: nVidia Corporation C79 [GeForce 9400M G] (rev b1)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will get a long list of devices connected to your PCI buses. We are only    interested with the VGA controller.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As you can see, we have two VGA controller, we just need to specify which one we would like to use.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ nano /etc/X11/xorg.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to your Device section and set Bus ID for your controller in it. So, in the end, if I chose the second controller, my &lt;code&gt;Xorg.conf&lt;/code&gt; would somehow look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Section &amp;quot;Device&amp;quot;
    Identifier     &amp;quot;Device0&amp;quot;
    Driver         &amp;quot;nvidia&amp;quot;
    VendorName     &amp;quot;NVIDIA Corporation&amp;quot;
    BoardName      &amp;quot;GeForce 9400M G&amp;quot;
    BusID          &amp;quot;PCI:3:0:0&amp;quot;
EndSection
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The configuration is simple, you just need to &lt;strong&gt;add the 6th line&lt;/strong&gt;. Just make sure  you put it in the correct format &lt;code&gt;PCI:X:X:X&lt;/code&gt;, X possibly refers to the last 3   digit number in your error log.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>How to Enable MySQL Support in Qt SDK for Linux</title>
   <link href="http://ieatbinary.com/2009/07/22/how-to-enable-mysql-support-in-qt-sdk-for-linux/" />
   <updated>2009-07-22T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2009/07/22/how-to-enable-mysql-support-in-qt-sdk-for-linux</id>
   <content type="html">&lt;h1&gt;How to Enable MySQL Support in Qt SDK for Linux&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download Qt SDK for Linux/X11 at Qt Software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install it anywhere you want, just make sure you remember the path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To build MySQL as a plugin, you need to know two other paths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;MySQL header directory's files example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;decimal.h   m_string.h      my_dbug.h    my_list.h        my_sys.h     mysql_embed.h    mysqld_error.h  sql_state.h        typelib.h
errmsg.h    my_alloc.h      my_dir.h     my_net.h         my_xml.h     mysql_time.h     raid.h          sslopt-case.h
keycache.h  my_attribute.h  my_getopt.h  my_no_pthread.h  mysql.h      mysql_version.h  readline.h      sslopt-longopts.h
m_ctype.h   my_config.h     my_global.h  my_pthread.h     mysql_com.h  mysqld_ername.h  sql_common.h    sslopt-vars.h
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MySQL library directory's files example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;libdbug.a    libmyisammrg.a      libmysqlclient.so@         libmysqlclient_r.a    libmysqlclient_r.so.15@      libmysys.a
libheap.a    libmysqlclient.a    libmysqlclient.so.15@      libmysqlclient_r.la*  libmysqlclient_r.so.15.0.0*  libvio.a
libmyisam.a  libmysqlclient.la*  libmysqlclient.so.15.0.0*  libmysqlclient_r.so@  libmystrings.a
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For Slackware v12.2, it should be at:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Headers directory
/usr/include/mysql  

# Libraries directory
/usr/lib/mysql      
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go your main Qt SDK installation's path:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd /opt/qtsdk-2009.03/
cd qt/src/plugins/sqldrivers/mysql/
# Replace all the path based on your computer environment. 
# Make sure 'qmake' can be run from anywhere or you'd have to specify the full path for it.
qmake -o Makefile &amp;quot;INCLUDEPATH+=/usr/include/mysql&amp;quot; &amp;quot;LIBS+=-L/usr/lib/mysql -lmysqlclient&amp;quot; mysql.pro
make
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should have these files created for you&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Makefile
README
libqsqlmysql.so*
main.cpp
main.o
moc_qsql_mysql.cpp
moc_qsql_mysql.o
mysql.pro
qsql_mysql.moc
qsql_mysql.o
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy MySQL plugin to your Qt’s plugins directory,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cp libqsqlmysql.so /opt/qtsdk-2009.03/qt/plugins/sqldrivers
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new project and put these codes to test your new plugin. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;QT       += core sql
QT       -= gui

TARGET    = mysql
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure you have &lt;code&gt;mysql&lt;/code&gt; included in your &lt;code&gt;.pro&lt;/code&gt; file.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include &amp;lt;QCoreApplication&amp;gt;
#include &amp;lt;QtSql&amp;gt;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    qDebug() &amp;lt;&amp;lt; QSqlDatabase::drivers();

    return a.exec();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should get these outputs when you ran the application:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(&amp;quot;QSQLITE&amp;quot;, &amp;quot;QMYSQL3&amp;quot;, &amp;quot;QMYSQL&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it, good luck!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Reading Mifare 1K Card using Java in Linux</title>
   <link href="http://ieatbinary.com/2009/02/11/reading-mifare-1k-card-using-java-in-linux/" />
   <updated>2009-02-11T00:00:00-08:00</updated>
   <id>http://ieatbinary.com/2009/02/11/reading-mifare-1k-card-using-java-in-linux</id>
   <content type="html">&lt;h1&gt;Reading Mifare 1K Card using Java in Linux&lt;/h1&gt;

&lt;h2&gt;The Story&lt;/h2&gt;

&lt;p&gt;In the end of last year, my friends and I were tasked to read our staff card. The main objective was pretty simple which is to create a library where we don’t have to depend on the vendor every time we want to read our own staff card and the library should also work in Linux and Windows (that means Java to us).&lt;/p&gt;

&lt;p&gt;Working environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slackware 12.2&lt;/li&gt;
&lt;li&gt;JDK 6 Update 11&lt;/li&gt;
&lt;li&gt;Netbeans 6.5&lt;/li&gt;
&lt;li&gt;libusb 0.1.12&lt;/li&gt;
&lt;li&gt;Windows Binary of JPC/SC Java API 0.8.0&lt;/li&gt;
&lt;li&gt;Smartcard Reader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s talk about the reader first. You need to get a reader that supports Mifare 1K card (obviously) which to be exact a reader that supports ISO14443A/B or ISO15693 (contactless standard). Now, to make your life easier, you should get a reader that can read contactless standards compliant using the same framework as ISO7816 compliant contact cards. In simple terms, you can use APDU to get the data that you want.&lt;/p&gt;

&lt;p&gt;So, for this little project, we use &lt;strong&gt;OMNIKEY CardMan 5321&lt;/strong&gt; RFID reader. It has everything that we need, Linux/Windows supports, APDU calls to the contactless card, it even comes a contact card’s reader too and it’s also inexpensive.&lt;/p&gt;

&lt;p&gt;Make sure you choose the correct reader or you won’t be able to use this tutorial. Some reader requires you to read using their own specific code, which means you can only use the code you wrote on that particular reader, unlike readers that support APDU calls to contactless cards.&lt;/p&gt;

&lt;h2&gt;The Card&lt;/h2&gt;

&lt;p&gt;1024 byte memory is organised as sixteen sectors, each of which is made up of four blocks and each block is 16 bytes long. The first block in the memory (Block 0) is read-only and is set in the factory to contain the four-byte serial number (UID), check bytes and manufacturers data. The last block of each sector (Blocks 3, 7, 11, 15 … 59, 63) is the Sector Trailer Block which contains the &lt;strong&gt;two security Key codes (KeyA and KeyB&lt;/strong&gt;) and the Access bits that define how the sector can be accessed.&lt;/p&gt;

&lt;p&gt;Taking into account the Serial Number/Manufacturers Block and the Sector Trailer Blocks then there are 752 bytes of free memory for user storage. For all Read and Write operations the Mifare card memory is addressed by Block number (in hexadecimal format).&lt;/p&gt;

&lt;h2&gt;The Installation&lt;/h2&gt;

&lt;p&gt;Before you begin coding your codes, you need to make sure your environment is ready for you. To do that, just follow steps from my previous tutorial which is pretty much the same.&lt;/p&gt;

&lt;h2&gt;General Steps to Read the Card&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Load Mifare key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authenticate&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;The Code&lt;/h2&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="lineno"&gt;  1&lt;/span&gt; &lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="n"&gt;my&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;husm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;mifare&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  2&lt;/span&gt; 
&lt;span class="lineno"&gt;  3&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.nio.ByteBuffer&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  4&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.List&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  5&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.smartcardio.Card&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  6&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.smartcardio.CardChannel&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  7&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.smartcardio.CardException&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  8&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.smartcardio.CardTerminal&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;  9&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.smartcardio.TerminalFactory&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt; 10&lt;/span&gt; 
&lt;span class="lineno"&gt; 11&lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Read&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 12&lt;/span&gt; 
&lt;span class="lineno"&gt; 13&lt;/span&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Read&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 14&lt;/span&gt;        
&lt;span class="lineno"&gt; 15&lt;/span&gt;        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 16&lt;/span&gt; 
&lt;span class="lineno"&gt; 17&lt;/span&gt;            &lt;span class="n"&gt;CardTerminal&lt;/span&gt; &lt;span class="n"&gt;terminal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt; 18&lt;/span&gt; 
&lt;span class="lineno"&gt; 19&lt;/span&gt;            &lt;span class="c1"&gt;// show the list of available terminals&lt;/span&gt;
&lt;span class="lineno"&gt; 20&lt;/span&gt;            &lt;span class="n"&gt;TerminalFactory&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TerminalFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDefault&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt; 21&lt;/span&gt;            &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CardTerminal&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;terminals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;terminals&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt; 22&lt;/span&gt; 
&lt;span class="lineno"&gt; 23&lt;/span&gt;            &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;readerName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt; 24&lt;/span&gt; 
&lt;span class="lineno"&gt; 25&lt;/span&gt;            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;terminals&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 26&lt;/span&gt; 
&lt;span class="lineno"&gt; 27&lt;/span&gt;                &lt;span class="n"&gt;readerName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;terminals&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;substring&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="lineno"&gt; 28&lt;/span&gt;                                    &lt;span class="n"&gt;terminals&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 29&lt;/span&gt; 
&lt;span class="lineno"&gt; 30&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readerName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;01&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 31&lt;/span&gt;                    &lt;span class="n"&gt;terminal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;terminals&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 32&lt;/span&gt;                &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt; 33&lt;/span&gt;            &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt; 34&lt;/span&gt; 
&lt;span class="lineno"&gt; 35&lt;/span&gt;            &lt;span class="c1"&gt;// Establish a connection with the card&lt;/span&gt;
&lt;span class="lineno"&gt; 36&lt;/span&gt;            &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Waiting for a card..&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 37&lt;/span&gt;            &lt;span class="n"&gt;terminal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;waitForCardPresent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 38&lt;/span&gt; 
&lt;span class="lineno"&gt; 39&lt;/span&gt;            &lt;span class="n"&gt;Card&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;terminal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;T=0&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 40&lt;/span&gt;            &lt;span class="n"&gt;CardChannel&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBasicChannel&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt; 41&lt;/span&gt; 
&lt;span class="lineno"&gt; 42&lt;/span&gt;            &lt;span class="c1"&gt;// Start with something simple, read UID, kinda like Hello World!&lt;/span&gt;
&lt;span class="lineno"&gt; 43&lt;/span&gt;            &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;baReadUID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="lineno"&gt; 44&lt;/span&gt; 
&lt;span class="lineno"&gt; 45&lt;/span&gt;            &lt;span class="n"&gt;baReadUID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]{(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xCA&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 46&lt;/span&gt;                                   &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="lineno"&gt; 47&lt;/span&gt; 
&lt;span class="lineno"&gt; 48&lt;/span&gt;            &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;UID: &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;baReadUID&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="lineno"&gt; 49&lt;/span&gt;            &lt;span class="c1"&gt;// If successfull, the output will end with 9000&lt;/span&gt;
&lt;span class="lineno"&gt; 50&lt;/span&gt; 
&lt;span class="lineno"&gt; 51&lt;/span&gt;            &lt;span class="c1"&gt;// OK, now, the real work&lt;/span&gt;
&lt;span class="lineno"&gt; 52&lt;/span&gt;            &lt;span class="c1"&gt;// Get Serial Number&lt;/span&gt;
&lt;span class="lineno"&gt; 53&lt;/span&gt;            &lt;span class="c1"&gt;// Load key&lt;/span&gt;
&lt;span class="lineno"&gt; 54&lt;/span&gt;            &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;baLoadKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="lineno"&gt; 55&lt;/span&gt; 
&lt;span class="lineno"&gt; 56&lt;/span&gt;            &lt;span class="n"&gt;baLoadKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]{(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x82&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 57&lt;/span&gt;                                      &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x1&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x06&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 58&lt;/span&gt;                                      &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 59&lt;/span&gt;                                      &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="lineno"&gt; 60&lt;/span&gt; 
&lt;span class="lineno"&gt; 61&lt;/span&gt;            &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;LOAD KEY: &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;baLoadKey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="lineno"&gt; 62&lt;/span&gt;            &lt;span class="c1"&gt;// If successfull, will output 9000&lt;/span&gt;
&lt;span class="lineno"&gt; 63&lt;/span&gt; 
&lt;span class="lineno"&gt; 64&lt;/span&gt;            &lt;span class="c1"&gt;// Authenticate&lt;/span&gt;
&lt;span class="lineno"&gt; 65&lt;/span&gt;            &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;baAuth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="lineno"&gt; 66&lt;/span&gt; 
&lt;span class="lineno"&gt; 67&lt;/span&gt;            &lt;span class="n"&gt;baAuth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]{(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x88&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 68&lt;/span&gt;                                &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x09&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x60&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="lineno"&gt; 69&lt;/span&gt; 
&lt;span class="lineno"&gt; 70&lt;/span&gt;            &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;AUTHENTICATE: &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;baAuth&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="lineno"&gt; 71&lt;/span&gt;            &lt;span class="c1"&gt;// If successfull, will output 9000&lt;/span&gt;
&lt;span class="lineno"&gt; 72&lt;/span&gt; 
&lt;span class="lineno"&gt; 73&lt;/span&gt;            &lt;span class="c1"&gt;// Read Serial&lt;/span&gt;
&lt;span class="lineno"&gt; 74&lt;/span&gt;            &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;baRead&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="lineno"&gt; 75&lt;/span&gt; 
&lt;span class="lineno"&gt; 76&lt;/span&gt;            &lt;span class="n"&gt;baRead&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]{(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xFF&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;xB0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="lineno"&gt; 77&lt;/span&gt;                                &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x09&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mh"&gt;0x10&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
&lt;span class="lineno"&gt; 78&lt;/span&gt; 
&lt;span class="lineno"&gt; 79&lt;/span&gt;            &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;READ: &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;baRead&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="lineno"&gt; 80&lt;/span&gt;            &lt;span class="c1"&gt;// If successfull, the output will end with 9000&lt;/span&gt;
&lt;span class="lineno"&gt; 81&lt;/span&gt; 
&lt;span class="lineno"&gt; 82&lt;/span&gt;        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 83&lt;/span&gt;            &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt; 84&lt;/span&gt;        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt; 85&lt;/span&gt;    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt; 86&lt;/span&gt; 
&lt;span class="lineno"&gt; 87&lt;/span&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CardChannel&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 88&lt;/span&gt; 
&lt;span class="lineno"&gt; 89&lt;/span&gt;        &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt; 90&lt;/span&gt; 
&lt;span class="lineno"&gt; 91&lt;/span&gt;        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;baResp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;258&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="lineno"&gt; 92&lt;/span&gt;        &lt;span class="n"&gt;ByteBuffer&lt;/span&gt; &lt;span class="n"&gt;bufCmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ByteBuffer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;wrap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 93&lt;/span&gt;        &lt;span class="n"&gt;ByteBuffer&lt;/span&gt; &lt;span class="n"&gt;bufResp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ByteBuffer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;wrap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;baResp&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt; 94&lt;/span&gt; 
&lt;span class="lineno"&gt; 95&lt;/span&gt;        &lt;span class="c1"&gt;// output = The length of the received response APDU&lt;/span&gt;
&lt;span class="lineno"&gt; 96&lt;/span&gt;        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt; 97&lt;/span&gt; 
&lt;span class="lineno"&gt; 98&lt;/span&gt;        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt; 99&lt;/span&gt; 
&lt;span class="lineno"&gt;100&lt;/span&gt;            &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;transmit&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bufCmd&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bufResp&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="lineno"&gt;101&lt;/span&gt; 
&lt;span class="lineno"&gt;102&lt;/span&gt;        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CardException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt;103&lt;/span&gt;            &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt;104&lt;/span&gt;        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt;105&lt;/span&gt; 
&lt;span class="lineno"&gt;106&lt;/span&gt;        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt;107&lt;/span&gt;            &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;%02X&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;baResp&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]);&lt;/span&gt;
&lt;span class="lineno"&gt;108&lt;/span&gt;            &lt;span class="c1"&gt;// The result is formatted as a hexadecimal integer&lt;/span&gt;
&lt;span class="lineno"&gt;109&lt;/span&gt;        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt;110&lt;/span&gt; 
&lt;span class="lineno"&gt;111&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="lineno"&gt;112&lt;/span&gt;    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt;113&lt;/span&gt; 
&lt;span class="lineno"&gt;114&lt;/span&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="lineno"&gt;115&lt;/span&gt;        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Read&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="lineno"&gt;116&lt;/span&gt;    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="lineno"&gt;117&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Make sure you have set the right connection protocol at line 43, as pointed out by Animesh (previous commentator).&lt;/p&gt;

&lt;p&gt;These codes use Java API to read the smartcard, but I suggest you use the jpcsc library. It’s much more robust when it comes to error handling. &lt;/p&gt;

&lt;h2&gt;The APDU Commands&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;# Load Key
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|   FF   |   82   |   20   |   1A   |   06   |   FF   |   FF   |   FF   |   FF   |   FF   |   FF   |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|   1    |   2    |   3    |   4    |   5    |   6    |   7    |   8    |   9    |   10   |   11   |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

1   = CLA : (Fixed)
2   = INS : (Fixed)
3   = P1  : (Fixed)
4   = P2  : Key type, could be 00, 1A, 1B
5   = LC  : Key length, usually 6 for 6 byte
6   = XX  : ----+
7   = XX  :     |
8   = XX  :     |__ The Key (eg. FF FF FF FF FF FF)
9   = XX  :     |
10  = XX  :     |
11  = XX  : ----+

# Autenthicate
+--------+--------+--------+--------+--------+--------+
|   FF   |   88   |   00   |   01   |   60   |   00   |
+--------+--------+--------+--------+--------+--------+
|   1    |   2    |   3    |   4    |   5    |   6    |
+--------+--------+--------+--------+--------+--------+

1   = CLA : (Fixed)
2   = INS : (Fixed)
3   = P1  : (Fixed)
4   = P2  : Block Number you want to authenticate in Hex
5   = P3  : Mifare Block Number LSB
6   = XX  : Key type, could be 00, 1A, 1B

# Read
+--------+--------+--------+--------+--------+
|   FF   |   B0   |   00   |   01   |   10   |
+--------+--------+--------+--------+--------+
|   1    |   2    |   3    |   4    |   5    |
+--------+--------+--------+--------+--------+

1   = CLA : (Fixed)
2   = INS : (Fixed)
3   = P1  : (Fixed)
4   = P2  : Block Number that you want to read in Hex
5   = Le  : (Fixed)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, that’s it, good luck!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Printing to PDF using CUPS</title>
   <link href="http://ieatbinary.com/2008/09/10/printing-to-pdf-using-cups/" />
   <updated>2008-09-10T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2008/09/10/printing-to-pdf-using-cups</id>
   <content type="html">&lt;h1&gt;Printing to PDF using CUPS&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install CUPS-PDF&lt;/strong&gt; based on your distro, you can download if from &lt;a href="http://www.physik.uni-wuerzburg.de/~vrbehr/cups-pdf/download.shtml"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="http://localhost:631"&gt;http://localhost:631&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the page requested a username and password, just enter your root as username and password for your root.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;strong&gt;Administration &amp;gt; Add Printer&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;Add Printer&lt;/strong&gt; page, &lt;strong&gt;put a name&lt;/strong&gt; for your virtual PDF printe, any name will do. Then click &lt;strong&gt;Continue&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the &lt;strong&gt;Device for a&lt;/strong&gt;, you should &lt;strong&gt;select CUPS-PDF&lt;/strong&gt; (Virtual PDF Driver). If it’s not there, then you haven’t executed &lt;strong&gt;Step 1&lt;/strong&gt; successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the 3rd page, choose &lt;strong&gt;Generic as the Make&lt;/strong&gt; and then click &lt;strong&gt;Continue&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the 4th page, &lt;strong&gt;choose Generic CUPS-PDF Printer (en)&lt;/strong&gt; as the model and then click &lt;strong&gt;Add Printer&lt;/strong&gt;. For now, you’re done, but we need to customize where the file will be generated when you printed it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edit &lt;code&gt;/etc/cups/cups-pdf.conf&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Put these lines at the end of the file and save it (both can be customized):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Out /home/${USER}/Desktop
Label 1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first line actually tell CUPS to print your file to the Desktop and the second  line will make sure your file won’t be overwritten by a newer one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restart CUPS&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, that’s all and good luck !&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Java Printing Fix for Linux</title>
   <link href="http://ieatbinary.com/2008/09/09/java-printing-fix-for-linux-with-cups/" />
   <updated>2008-09-09T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2008/09/09/java-printing-fix-for-linux-with-cups</id>
   <content type="html">&lt;h1&gt;Java Printing Fix for Linux&lt;/h1&gt;

&lt;p&gt;Apparently, there's a bug in Java where people using newer version of CUPS cannot print (can't even display the print dialog) due to a null pointer exception and this is actually a known bug. So, how do we fix this? For people who use Gnome, you can refer to this &lt;a href="https://bugs.launchpad.net/ubuntu/+source/sun-java6/+bug/156191/comments/18"&gt;page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, for people who uses non desktop environment such as Fluxbox, Openbox and etc (Gnome and KDE user can use these steps too), you can fix it by editing your CUPS printers configuration file. You can get edit the file at &lt;code&gt;/etc/cups/printers.conf&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;DefaultPrinter Printer&amp;gt;
# Printer configuration file for CUPS v1.3.7
# Written by cupsd on 2008-09-08 11:24
.
.
.
Option orientation-requested 3
&amp;lt;/Printer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure you &lt;code&gt;Option orientation-requested 3&lt;/code&gt; to every configuration for every printer you've installed. If you cannot find the file, it's possible that you haven't configured any printer yet.&lt;/p&gt;

&lt;p&gt;This fix is simply to make sure CUPS will provide a page orientation setting to Java.&lt;/p&gt;

&lt;p&gt;The exception:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Caused by: java.lang.NullPointerException: null attribute
        at sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1147)
        at sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2121)
        at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1263)
        at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:437)
        at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:195)
        at sun.print.ServiceDialog.(ServiceDialog.java:124)
        at javax.print.ServiceUI.printDialog(ServiceUI.java:188)
        at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:855)
        at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:421)&amp;lt;/code&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Please refer to some of the discussions here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://bugs.launchpad.net/ubuntu/+source/sun-java6/+bug/156191/"&gt;Ubuntu Bugs Report&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6633656"&gt;Java Bugs Report&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;FYI, you need to &lt;strong&gt;restart your CUPS&lt;/strong&gt; after editing the configuration (Thanks to Brandon Bell).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Auto Resize JTable Column Width</title>
   <link href="http://ieatbinary.com/2008/08/13/auto-resize-jtable-column-width/" />
   <updated>2008-08-13T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2008/08/13/auto-resize-jtable-column-width</id>
   <content type="html">&lt;h1&gt;Auto Resize JTable Column Width&lt;/h1&gt;

&lt;p&gt;This code should resize your JTable column width based on the contents of the header and data.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;JTable&lt;/span&gt; &lt;span class="nf"&gt;autoResizeColWidth&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JTable&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DefaultTableModel&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAutoResizeMode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JTable&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;AUTO_RESIZE_OFF&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setModel&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;margin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColumnCount&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;                     &lt;span class="n"&gt;vColIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;DefaultTableColumnModel&lt;/span&gt; &lt;span class="n"&gt;colModel&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DefaultTableColumnModel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColumnModel&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;TableColumn&lt;/span&gt;             &lt;span class="n"&gt;col&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;colModel&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColumn&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vColIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;                     &lt;span class="n"&gt;width&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Get width of column header&lt;/span&gt;
        &lt;span class="n"&gt;TableCellRenderer&lt;/span&gt; &lt;span class="n"&gt;renderer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getHeaderRenderer&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;renderer&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;renderer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTableHeader&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getDefaultRenderer&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;Component&lt;/span&gt; &lt;span class="n"&gt;comp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;renderer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTableCellRendererComponent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getHeaderValue&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;comp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPreferredSize&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Get maximum width of column data&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRowCount&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;renderer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCellRenderer&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vColIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;comp&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;renderer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTableCellRendererComponent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValueAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vColIndex&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vColIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;max&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;comp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPreferredSize&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Add margin&lt;/span&gt;
        &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Set the width&lt;/span&gt;
        &lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setPreferredWidth&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;DefaultTableCellRenderer&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTableHeader&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getDefaultRenderer&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;setHorizontalAlignment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;SwingConstants&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LEFT&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// table.setAutoCreateRowSorter(true);&lt;/span&gt;
    &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTableHeader&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;setReorderingAllowed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="c1"&gt;// Must pass the model&lt;/span&gt;
&lt;span class="n"&gt;DefaultTableModel&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DefaultTableModel&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;jTable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;autoResizeColWidth&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jTable&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Printing to Zebra S4M Using Java and ZPL II</title>
   <link href="http://ieatbinary.com/2008/05/11/printing-to-zebra-s4m-using-java-and-zpl-ii/" />
   <updated>2008-05-11T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2008/05/11/printing-to-zebra-s4m-using-java-and-zpl-ii</id>
   <content type="html">&lt;h1&gt;Printing to Zebra S4M Using Java and ZPL II&lt;/h1&gt;

&lt;p&gt;Apparently there're some codes scattered on the net telling people that you can print to a Zebra printer by sending ZPL II codes using &lt;code&gt;PrintService&lt;/code&gt;. But the problem is, it's not working, I don't know why, maybe because of a different version of printer or model but I'm pretty sure the thing that came out from the printer are just ordinary texts not barcode which is what the code was supposed to output.&lt;/p&gt;

&lt;h2&gt;New Version&lt;/h2&gt;

&lt;p&gt;Thanks to Oleg (a commentator) for pointing out on how to print using Zebra S4M connected either via USB or network.&lt;/p&gt;

&lt;p&gt;The solution is pretty simple, all you have to do is do not install Zebra S4M as a Zebra S4M (sounds weird, I know), instead, just install it as a local raw printer (Linux) or generic text printer (Windows).&lt;/p&gt;

&lt;p&gt;For CUPS user in Linux, this is the example for the correct configurations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/etc/cups/printers.conf&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;Printer Zebra&amp;gt;
  Info
  Location
  DeviceURI socket://10.1.1.5:9100
  State Idle
  StateTime 1223445299
  Accepting Yes
  Shared Yes
  JobSheets none none
  QuotaPeriod 0
  PageLimit 0
  KLimit 0
  OpPolicy default
  ErrorPolicy stop-printer
  Option orientation-requested 3
&amp;lt;/Printer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can always add the printer using the web interface, just make sure you choose RAW as the Make/Manufacturer and Model/Driver.&lt;/p&gt;

&lt;p&gt;Test this Java code, it should print out a barcode:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.Doc&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.DocFlavor&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.DocPrintJob&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.PrintException&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.PrintService&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.PrintServiceLookup&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.SimpleDoc&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.attribute.PrintServiceAttribute&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.print.attribute.standard.PrinterName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SimplePrint&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       
       &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           
           &lt;span class="n"&gt;PrintService&lt;/span&gt; &lt;span class="n"&gt;psZebra&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
           &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;sPrinterName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
           &lt;span class="n"&gt;PrintService&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PrintServiceLookup&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lookupPrintServices&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           
           &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
               
               &lt;span class="n"&gt;PrintServiceAttribute&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="na"&gt;getAttribute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PrinterName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
               &lt;span class="n"&gt;sPrinterName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;PrinterName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
               
               &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sPrinterName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toLowerCase&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;indexOf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;zebra&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                   &lt;span class="n"&gt;psZebra&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
                   &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
               &lt;span class="o"&gt;}&lt;/span&gt;
           &lt;span class="o"&gt;}&lt;/span&gt;
           
           &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;psZebra&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
               &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Zebra printer is not found.&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
               &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
           &lt;span class="o"&gt;}&lt;/span&gt;
           &lt;span class="n"&gt;DocPrintJob&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;psZebra&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createPrintJob&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

           &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

           &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBytes&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
           &lt;span class="n"&gt;DocFlavor&lt;/span&gt; &lt;span class="n"&gt;flavor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DocFlavor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;BYTE_ARRAY&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;AUTOSENSE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
           &lt;span class="n"&gt;Doc&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;SimpleDoc&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flavor&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           
       &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PrintException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;      
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Print using FTP:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.io.FileInputStream&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.commons.net.ftp.FTP&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.commons.net.ftp.FTPClient&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FtpPrint&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

       &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

           &lt;span class="n"&gt;FTPClient&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;FTPClient&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;            

           &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;10.1.127.3&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;login&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;anonymous&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFileType&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FTP&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ASCII_FILE_TYPE&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;                            

           &lt;span class="n"&gt;FileInputStream&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;FileInputStream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;/path/to/file&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;storeFile&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;filename&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
               &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Upload ok&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="o"&gt;}&lt;/span&gt;                

           &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;logout&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
           &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;disconnect&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

       &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Print using socket:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.io.DataOutputStream&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.net.Socket&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SocketPrint&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

       &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;clientSocket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Socket&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;10.1.127.3&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9100&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;DataOutputStream&lt;/span&gt; &lt;span class="n"&gt;outToServer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DataOutputStream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clientSocket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOutputStream&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
           &lt;span class="n"&gt;outToServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;writeBytes&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;clientSocket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;(got it from &lt;a href="https://support.zebra.com"&gt;Zebra's website&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.zebra.com/id/zebra/na/en/index/products/printers/industrial_commercial/s4m.4.tabs.html"&gt;Download guide to ZPL II&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Automatically Sign JARs Using Ant and Bash</title>
   <link href="http://ieatbinary.com/2008/04/14/automatically-sign-jars-using-ant-and-bash/" />
   <updated>2008-04-14T00:00:00-07:00</updated>
   <id>http://ieatbinary.com/2008/04/14/automatically-sign-jars-using-ant-and-bash</id>
   <content type="html">&lt;h1&gt;Automatically Sign JARs Using Ant and Bash&lt;/h1&gt;

&lt;p&gt;This guide is more towards Netbeans project, but it can be used as a reference for you to customize the script to suit your needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;signer.bash&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
find . -name &lt;span class="s2"&gt;&amp;quot;*.jar&amp;quot;&lt;/span&gt; -exec jarsigner -keystore /path/to/your/key -storepass yourpassword &lt;span class="s1"&gt;&amp;#39;{}&amp;#39;&lt;/span&gt; yourkeystorename &lt;span class="se"&gt;\;&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;JARs signed&amp;#39;&lt;/span&gt;;
&lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This script &lt;strong&gt;will search all files ending with .jar&lt;/strong&gt; from the current directory recursively and &lt;strong&gt;then sign it&lt;/strong&gt;. This means, it can be used separately without ant script. Just make it executable and run it.&lt;/p&gt;

&lt;p&gt;Put this in the last line of your &lt;code&gt;build.xml&lt;/code&gt; but it must before the closing tag of the &amp;quot;project&amp;quot; (&lt;code&gt;build.xml&lt;/code&gt; can be found in your main project directory)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;build.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;&lt;span class="nt"&gt;&amp;lt;project&amp;gt;&lt;/span&gt;
    .
    .
    .
    &lt;span class="nt"&gt;&amp;lt;target&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;-post-jar&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;exec&lt;/span&gt; &lt;span class="na"&gt;dir=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;${dist.dir}&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;executable=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;/path/to/your/signer.bash&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;os=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Linux&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/target&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/project&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This script will basically sign the jars after all the jars has been build. Please note that it'd better if you set all the path using absolute path.&lt;/p&gt;

&lt;p&gt;After this, you just have to use &lt;strong&gt;Clean and Build&lt;/strong&gt; to generate the jars and also automatically sign it. This script will also sign all of your included libraries. &lt;/p&gt;

&lt;p&gt;Good luck :)&lt;/p&gt;
</content>
 </entry>
 

</feed>

