<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5435484311231149857</id><updated>2011-12-16T09:02:02.791Z</updated><category term='gsl_rng_set'/><category term='random seed'/><category term='cluster'/><category term='MPI'/><category term='random number'/><title type='text'>My Struggle</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-651190798450634704</id><published>2009-10-26T10:56:00.002Z</published><updated>2009-10-26T11:23:24.585Z</updated><title type='text'>How to make Snow Leopard REALLY work with Exchange</title><content type='html'>I was very excited when Apple released the Snow Leopard, also known as Mac OS X 10.6. The main benefit would be the native support of Microsoft Exchange in iCal, Address Book and Mail.app. And this is something I was complaining about for years.&lt;br /&gt;&lt;br /&gt;So, I upgraded my computers as soon as I could, and I was initially quite surprised how easy it was to configure the applications to work with Exchange server. (Yes, we have Mictosoft Exchange 2007 over here).&lt;br /&gt;&lt;br /&gt;But the very next moment some dire disappointments came:&lt;br /&gt;&lt;OL&gt;&lt;br /&gt;&lt;LI&gt;&lt;b&gt;Push email doesn't work&lt;/b&gt; with Exchange account any more. If I want to be able to react to emails instantly, in a kind of IM way, I would have to poll the servers every minute or so. This clogs the network and puts extra workload on my workstation. And it is so archaic to poll your email in 2009.&lt;/LI&gt;&lt;br /&gt;&lt;LI&gt;Every so often the message counter would show that I have some &lt;b&gt;unread messages&lt;/b&gt;, while in fact I don't. White day glitch. I would have to go to "Mailbox ⟶ Rebuild" to reindex the account to get rid of this glitch. And it would happen again next day.&lt;/LI&gt; &lt;br /&gt;&lt;/OL&gt;&lt;br /&gt;&lt;br /&gt;After suffering for a couple of weeks and hoping for a fix from Apple, I have found a workaround to make Snow Leopard work with Exchange almost the way I want it to work. The whole procedure is very simple and only takes 10 seconds more than usual setup. The only additional requirement is to have IMAP access enabled on your Exchange server. Ask your system administrator.&lt;br /&gt;&lt;br /&gt;&lt;OL&gt;&lt;br /&gt;&lt;LI&gt;Open Mail.app and add your Exchange account just the way you normally would. This will add the Exchange account to your iCal and Address Book as well.&lt;/LI&gt;&lt;br /&gt;&lt;LI&gt;Now, you have to &lt;b&gt;remove&lt;/b&gt; the newly created Exchange account from Mail.app. This would still leave the accounts for iCal and Address Book.&lt;/LI&gt;&lt;br /&gt;&lt;LI&gt;Create a new account in Mail.app using "Exchange IMAP" account type instead. Sometimes this option is not available as Mail.app detects your Exchange server and disables the choice. Just type a fake email address in the first screen to avoid that. Something like &lt;i&gt;asdfhj@sad.geweg.aj.net&lt;/i&gt; would do. Then select "Exchange IMAP" as an account type, and fill in all the appropriate options. Don't forget to change your email address to a normal form (from a fake one) once you have your account created.&lt;/LI&gt;&lt;br /&gt;&lt;/OL&gt;&lt;br /&gt;&lt;br /&gt;Enjoy push email, proper counting of unread messages, and iCal support of Exchange calendars at the same time!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-651190798450634704?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/651190798450634704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=651190798450634704' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/651190798450634704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/651190798450634704'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2009/10/how-to-make-snow-leopard-really-work.html' title='How to make Snow Leopard REALLY work with Exchange'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-7410584475854646637</id><published>2009-02-10T15:13:00.001Z</published><updated>2009-02-10T15:14:02.943Z</updated><title type='text'>iPhone support in Google Calendar</title><content type='html'>Hurray! Now google calendar supports instant sync with an iPhone!&lt;br /&gt;http://www.google.com/mobile/apple/sync.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-7410584475854646637?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/7410584475854646637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=7410584475854646637' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/7410584475854646637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/7410584475854646637'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2009/02/iphone-support-in-google-calendar.html' title='iPhone support in Google Calendar'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-8966965609358235859</id><published>2008-12-03T17:44:00.002Z</published><updated>2008-12-03T17:49:20.153Z</updated><title type='text'>Google Calendar now supports Apple iCal</title><content type='html'>Breaking news from Google: &lt;a href="http://googlemac.blogspot.com/2008/12/google-calendar-now-supports-apple-ical.html"&gt;Google Calendar now supports Apple iCal&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;It is not really a solution for synchronising with Exchange, though a very useful extension to Google calendar. With a couple of tweaks it will be possible to synch Google calendar to Exchange too. The only feature missing that prevents Google calendar to be a proxy between Exchange and iCal is free/busy service. I am afraid that the only solution for fellow Mac users is to wait until Snow Leopard is released, and hope that the new incarnation of iCal would support Exchange natively.&lt;br /&gt;&lt;br /&gt;Follow the link to the official Google blog above to find the instructions on how to use Google calendar with iCal.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-8966965609358235859?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/8966965609358235859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=8966965609358235859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8966965609358235859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8966965609358235859'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2008/12/google-calendar-now-supports-apple-ical.html' title='Google Calendar now supports Apple iCal'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-8757385764992694027</id><published>2008-06-17T15:06:00.002+01:00</published><updated>2008-06-17T15:10:11.507+01:00</updated><title type='text'>Exchange support coming to iCal next year</title><content type='html'>Finally some good news. It is official now, iCal will support Microsoft Exchange calendars in the next version of Mac OS X which is expected to be released in 2009.&lt;br /&gt;The official Apple press release can be found at &lt;a href="http://www.apple.com/pr/library/2008/06/09snowleopard.html"&gt;http://www.apple.com/pr/library/2008/06/09snowleopard.html&lt;/a&gt; and it states:&lt;br /&gt;&lt;blockquote&gt;For the first time, OS X includes native support for Microsoft Exchange 2007 in OS X applications Mail, iCal® and Address Book, making it even easier to integrate Macs into organizations of any size.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The only problem is that we have to wait for at least another year.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-8757385764992694027?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/8757385764992694027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=8757385764992694027' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8757385764992694027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8757385764992694027'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2008/06/exchange-support-coming-to-ical-next.html' title='Exchange support coming to iCal next year'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-8956376481264112415</id><published>2008-06-09T20:47:00.002+01:00</published><updated>2008-06-09T20:54:36.732+01:00</updated><title type='text'>Will Mobile Me solve the synchronization problem?</title><content type='html'>Apple have announced an extension to their .Mac service, and they have rebranded it as "Mobile Me". The initial information available at their web pages at &lt;a href="http://www.apple.com/uk/mobileme/"&gt;http://www.apple.com/uk/mobileme&lt;/a&gt; promises seamless integration with Mac and PC. They particularly claim that Mobile Me calendar will synchronize with Outlook and iCal and will provide push updates across all the computers connected to the account. &lt;br /&gt;&lt;br /&gt;Imagine the following scenario: you run Microsoft Outlook on Parallels or on a dedicated computer at work. Outlook synchronizes your Exchange calendar to Mobile Me, and your iCal  also works through that service.&lt;br /&gt;Given that Mobile Me is developed by Apple, I'd imagine that it would actually work and be more secure than using some third party synchronization proxies from companies I have never heard about.&lt;br /&gt;&lt;br /&gt;Unfortunately, they are not rolling Mobile Me just yet, but please come back after they have, and I'll tell you if it worked for me.&lt;br /&gt;&lt;br /&gt;Any speculations on whether it is going to work or not?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-8956376481264112415?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/8956376481264112415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=8956376481264112415' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8956376481264112415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8956376481264112415'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2008/06/will-mobile-me-solve-synchronization.html' title='Will Mobile Me solve the synchronization problem?'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-8287203835369574874</id><published>2008-03-06T18:57:00.002Z</published><updated>2008-03-06T19:02:41.513Z</updated><title type='text'>Any hopes for Exchange support now?</title><content type='html'>I am currently watching the iPhone SDK press conference. They have announced that the iPhone will soon support proper communication with the Exchange. This includes complete Calendar support. What I wish they have done is to license the same technology for the iCal. That would have been an ideal solution for all of us who suffers being a Mac user within a corporate environment. &lt;br /&gt;&lt;br /&gt;I do understand that it may be possible to sync the appointments between iCal and Exchange either by using current solutions or through syncing with an iPhone, but what I am looking for is free/busy integration as well. &lt;br /&gt;&lt;br /&gt;So, we all have two hopes now, the first one is that the Groupcal will be updated, and the second one (Oh, that would be fantastic) that Apple will begin to support enterprise standards for calendars.&lt;br /&gt;&lt;br /&gt;Stay tuned for more updates.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-8287203835369574874?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/8287203835369574874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=8287203835369574874' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8287203835369574874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8287203835369574874'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2008/03/any-hopes-for-exchange-support-now.html' title='Any hopes for Exchange support now?'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-1152729805905141768</id><published>2007-11-28T12:49:00.000Z</published><updated>2007-11-28T13:00:21.389Z</updated><title type='text'>Sample from Gamma distribution in Java</title><content type='html'>Back to the Java struggles. &lt;br /&gt;Today I am giving away a piece of Java code which allows one to sample a random variable from &lt;a href="http://en.wikipedia.org/wiki/Gamma_distribution"&gt;Gamma distribution&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;pre&gt;import java.util.Random;&lt;br /&gt;&lt;br /&gt;public class Samplers {&lt;br /&gt;  private static Random rng = new Random(&lt;br /&gt;      Calendar.getInstance().getTimeInMillis() +&lt;br /&gt;      Thread.currentThread().getId());&lt;br /&gt;&lt;br /&gt;  public static double sampleGamma(double k, double theta) {&lt;br /&gt;    boolean accept = false;&lt;br /&gt;    if (k &lt; 1) {&lt;br /&gt; // Weibull algorithm&lt;br /&gt; double c = (1 / k);&lt;br /&gt; double d = ((1 - k) * Math.pow(k, (k / (1 - k))));&lt;br /&gt; double u, v, z, e, x;&lt;br /&gt; do {&lt;br /&gt;  u = rng.nextDouble();&lt;br /&gt;  v = rng.nextDouble();&lt;br /&gt;  z = -Math.log(u);&lt;br /&gt;  e = -Math.log(v);&lt;br /&gt;  x = Math.pow(z, c);&lt;br /&gt;  if ((z + e) &gt;= (d + x)) {&lt;br /&gt;   accept = true;&lt;br /&gt;  }&lt;br /&gt; } while (!accept);&lt;br /&gt; return (x * theta);&lt;br /&gt;    } else {&lt;br /&gt; // Cheng's algorithm&lt;br /&gt; double b = (k - Math.log(4));&lt;br /&gt; double c = (k + Math.sqrt(2 * k - 1));&lt;br /&gt; double lam = Math.sqrt(2 * k - 1);&lt;br /&gt; double cheng = (1 + Math.log(4.5));&lt;br /&gt; double u, v, x, y, z, r;&lt;br /&gt; do {&lt;br /&gt;  u = rng.nextDouble();&lt;br /&gt;  v = rng.nextDouble();&lt;br /&gt;  y = ((1 / lam) * Math.log(v / (1 - v)));&lt;br /&gt;  x = (k * Math.exp(y));&lt;br /&gt;  z = (u * v * v);&lt;br /&gt;  r = (b + (c * y) - x);&lt;br /&gt;  if ((r &gt;= ((4.5 * z) - cheng)) ||&lt;br /&gt;                    (r &gt;= Math.log(z))) {&lt;br /&gt;   accept = true;&lt;br /&gt;  }&lt;br /&gt; } while (!accept);&lt;br /&gt; return (x * theta);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-1152729805905141768?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1152729805905141768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1152729805905141768'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/11/sample-from-gamma-distribution-in-java.html' title='Sample from Gamma distribution in Java'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-719115737885017651</id><published>2007-11-21T00:54:00.000Z</published><updated>2007-11-21T01:02:51.062Z</updated><title type='text'>The last hope for working with Exchange</title><content type='html'>Following on the topics of using iCal with the Exchange server. AppleInsider published &lt;a href="http://www.appleinsider.com/articles/07/11/19/road_to_mac_office_2008_entourage_08_vs_mail_3_0_and_ical_3_0.html"&gt;a very interesting comparison&lt;/a&gt; of iCal and Mail.app to the coming Entourage 2008.&lt;br /&gt;&lt;br /&gt;The AppleInsider Article left me very upset, as it is evident that there will be no improvement to synchronisation with iCal. Hopefully Office will become much faster, as it will be compiled as a universal binary...&lt;br /&gt;&lt;br /&gt;The only remaining hope is for&lt;a href="http://www.snerdware.com/groupcal/"&gt; Snerdware's GroupCal&lt;/a&gt;. Guys from AppleInsider got it wrong, as GroupCal is not yet working with Leopard. We have to wait a little, and hope that the developers from Snerdware solve their problems and release a new version soon.&lt;br /&gt;&lt;br /&gt;Forget my complaints about the price. I will buy the new GroupCal on the first day it is released.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-719115737885017651?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/719115737885017651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=719115737885017651' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/719115737885017651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/719115737885017651'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/11/last-hope-for-working-with-exchange.html' title='The last hope for working with Exchange'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-1591243380695716481</id><published>2007-11-08T10:57:00.000Z</published><updated>2007-11-13T02:52:00.838Z</updated><title type='text'>Boeing CalDAV proxy for Microsoft Exchange</title><content type='html'>I concluded the previous post with a rumor that Boeing have developed a CalDAV proxy for Microsoft Exchange. This was my last hope for using iCal with my work Exchange account. &lt;br /&gt;&lt;br /&gt;Unfortunately, this is the dead end. I have found what this software is and why it will never give me the functionality I want.&lt;br /&gt;&lt;br /&gt;First of all, Boeing have developed a Free-Busy connector for Exchange, not a complete CalDAV proxy. This is a web application (an ASP by the way) which takes someones e-mail as an input and returns their Free-Busy information in a format compatible with some CalDAV servers. I have tried using it with &lt;a href="http://www.bedework.org/bedework/"&gt;Bedework&lt;/a&gt; CalDAV server and I found it absolutely useless. This is a very good first attempt, but there are the following shortfalls: &lt;OL&gt;&lt;LI&gt;You need to run this special connector service, and you need to run it on a Windows machine.&lt;/LI&gt;&lt;LI&gt;This initial implementation does not have any built-in security. It just accesses the Exchange server through one preconfigured account. You canot use different users for different requests&lt;/LI&gt;&lt;LI&gt;This will only allow you to see whether john@example.com is free or busy from 9am to 10am, but would not let John know if you are busy.&lt;/LI&gt;&lt;LI&gt;This example service in not available in the wild.&lt;/LI&gt;&lt;/OL&gt;&lt;br /&gt;&lt;br /&gt;On the other hand, this is a good first step towards integration with Exchange. If the community demonstrates any interest, there will be someone to make further road.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-1591243380695716481?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/1591243380695716481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=1591243380695716481' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1591243380695716481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1591243380695716481'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/11/boeing-caldav-proxy-for-microsoft.html' title='Boeing CalDAV proxy for Microsoft Exchange'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-9156171415823895014</id><published>2007-10-30T20:13:00.001Z</published><updated>2010-06-30T14:54:47.318+01:00</updated><title type='text'>How to synchronize iCal with Exchange?</title><content type='html'>Apple iCal is a very neat calendaring application. I love it. It synchronizes with my iPhone. It works reliably. The new version supplied with Leopard has everything I need: scheduling appointments, booking rooms, inviting other people, tells other people when I am busy or free.&lt;br /&gt;&lt;br /&gt;Though, it is not compatible with Microsoft Exchange server our University uses.&lt;br /&gt;&lt;br /&gt;I have run a little investigation on how to resolve the problem, and I'd like to share my finding with you.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 1:&lt;/b&gt; &lt;i&gt;Use Microsoft Entourage.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Entourage is a part of Microsoft Office for Mac. It is a Mac version of Outlook. It will allow you to manage your mail and calendars well.  You can even synchronise your calendar with iCal! Automatically!&lt;br /&gt;Just go to &lt;b&gt;&lt;code&gt;Entourage&lt;/code&gt;&lt;/b&gt;&amp;gt;&lt;code&gt;preferences&lt;/code&gt;, and select &lt;code&gt;Sync Services&lt;/code&gt;.&lt;br /&gt;Now, on the right, you can ask Entourage to synchronise your calendar with iCal. This will create an additional calendar in your iCal called Entourage. It gives you three options. &lt;ol&gt;&lt;li&gt;Take verything from Exchange and put it into iCal, &lt;/li&gt;&lt;li&gt;take everything from that special calendar in iCal and put it into Exchange,&lt;/li&gt;&lt;li&gt;Merge the calendars, and make sync work both ways.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;If you want to book a room, you can do it with Entourage. If you just want to notify your colleagues that you are not available for a meeting every workday from 1pm to 2pm, just create a recurring appointment called "Lunch" and they will know you are busy.&lt;br /&gt;&lt;br /&gt;If you are happy with this solution, go for it! It will even synchronise with your iPhone! Thanks for coming, and you know how to &lt;b&gt;make a blogger happy&lt;/b&gt; - read carefully what Google guys suggest to you in the right part of the page.&lt;br /&gt;&lt;br /&gt;Now, why I don't like Entourage.&lt;br /&gt;&lt;br /&gt;First of all, I just love iCal and Mail.app. I do not want to use Entourage, even though I get it for free through the site license.&lt;br /&gt;&lt;br /&gt;Second, the current version of Entourage was written years ago, when Macs were made with PowerPC processors. Those processors spoke a different language to what Intel processors speak. If you run Entourage (which is written in the ancient language of PowerPC) on you shiny new Intel Mac, you use a translator with a Rosetta Stone (go and find what it is in Wikipedia, it is interesting). The point is that the translator is slow. And iCal is written in plain English, oops... in plain Intel, and it works natively.&lt;br /&gt;&lt;br /&gt;Third, Entourage can only synchronize your calendars while it is running. You cannot say it synchronize, and go on using iCal and mail.app alone. You still need to run Entourage. Though, you can run it hidden, press Command-H when Entourage is open and it is now hidden.&lt;br /&gt;&lt;br /&gt;Fourth.... I do not like Entourage. I do not want to support Microsoft... I want everything to be simple....&lt;br /&gt;&lt;br /&gt;We all hope that Microsoft will update their Office for Mac early next year, and hopefully some of my problems will be resolved. I am not sure, though, if it is worth the money people pay for it.&lt;br /&gt;&lt;br /&gt;Oh, if you are a representative of Microsoft marketing, please, contact me and I will let you know what I want for Christmas.&lt;br /&gt;&lt;br /&gt;If you are still with me, than you are probably looking for an alternative, so there you go:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 2:&lt;/b&gt; &lt;i&gt;Use GroupCal from Snerdware&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The guys have made quite a job. It really works! Everything I ever wanted. Though, it does not work under Leopard.... yet...&lt;br /&gt;Go and see for yourself: &lt;a href="http://www.snerdware.com/groupcal/"&gt;www.snerdware.com/groupcal&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I would be happy, but...&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;It does not work with Leopard.... yet...&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The way you see other people's free/busy time, and if the room is available is not nice. How I wish it worked just exactly like iCal in Leopard promises...&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I do not have a site license, and my Boss will tell me to go and use Windows. So, paying $55 from my own pocket is unpleasant. Please, fix the problems and make it a 20...&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;So, I went on went on with my investigation&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 3:&lt;/b&gt; &lt;i&gt;Use open standards! Like iCal Server!&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Oh, if you are powerful enough, you can save yourself quite a buck by not using Exchange at all! Go for CalDAV solution which will do everything you ever waned for free. It will work seamlessly with iCal in the end. And remember, iCal Server is open source, you can install it on one of your Macs for free. Whatever Apple charge for OS X Server, they charge it for the convenience of seamless installation. Contact the (smart) tech support.&lt;br /&gt;&lt;br /&gt;This was not an option for me... so I went on and discovered another twisted solution.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 4:&lt;/b&gt; &lt;i&gt;iCal to Google Calendar to Outlook to Exchange. All aboard! &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Bad news - you won't be able to see busy/free time of other people, and you still have to pay $50.&lt;br /&gt;Good news - it will also synchronise with Google Calendar, and even send you SMS with notifications if you want.&lt;br /&gt;&lt;br /&gt;The solution consists of two parts. The first one is to use  magical &lt;b&gt;&lt;code&gt;Spanning Sync&lt;/code&gt;&lt;/b&gt;. This is a little program which will synhronize your iCal with Google Calendar. Works like a charm. Go for it even if you do not want anything else. Leopard compatible. Best program you can buy for your Mac, and just $25 for a year.&lt;br /&gt;&lt;br /&gt;The second part is to use SyncMyCal tool from www.syncmycal.com on a Windows machine. I have enough of old computers I can hide in a cupboard at work which will run a scheduled synchronisation of Google Calendars with my Exchange...&lt;br /&gt;&lt;br /&gt;Well... maybe Entourage is not all that bad after all... This is a really twisted solution. I am not going to use it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 5:&lt;/b&gt; &lt;i&gt;Use Outlook Web Access&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;This is a web application to access your mail and calendars on the Exchange servers. Many companies have it. Clumsy and awful... I will use it only if I have no other choise whatsoever.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 6:&lt;/b&gt; &lt;i&gt;Do it the geeky way&lt;/i&gt;&lt;br /&gt;Here is how: &lt;a href="http://www.macosxhints.com/article.php?story=20041110141248547"&gt;http://www.macosxhints.com/article.php?story=20041110141248547&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have to admit that I never tried this idea. Tell me if it works for you.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Solution 7:&lt;/b&gt; &lt;i&gt;Hosted services&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;There are a number of synchronisation services, free and commercial, which will allow you to synchronise your calendars across different platforms. I have tried these:&lt;ul&gt;&lt;li&gt;Xchange network&lt;/li&gt;&lt;li&gt;ScheduleWorld&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;The main problem with these is that I do not want my calendars to be hosted somewhere else. I do not want even a potential breach of my privacy.&lt;br /&gt;&lt;br /&gt;Now iCal supports proper communication with Microsoft Exchange server. If you are looking for &lt;a title="hosted Exchange solution" href="http://www.sherweb.com/hosted-exchange"&gt;hosted Exchange solution&lt;/a&gt; check out SherWeb at http://www.sherweb.com/ &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Nonexisting Solution:&lt;/b&gt; &lt;i&gt;CalDAV connector to Exchange&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;This is what I would like to see. I want to have a CalDAV server, like iCal Server from Apple, able to fetch all the data from Exchange. This has to work transparently, as if I am using CalDAV.&lt;br /&gt;&lt;br /&gt;The project itself does not sound impossibe. There are open source CalDAV implementations. There is Evolution Exchange Connector, an open source client for Microsoft Exchange. The final step is to make a transparent implementation of CalDAV server which talk to Exchange. Everyone will be happy then.&lt;br /&gt;&lt;br /&gt;If you are a developer, and you can make this happen, then please, do! Make it cheap, like $20-$30, and you will sell a ton of copies. Send me a cheque for the idea if it works out well. Seriously, contact me if you are interested in this development, I can contribute to requirements. We can make millions happy.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I ended up printing out my calendar and sticking it to my door. People have to ask me if I am free at any particular moment, and I will check with my iCal. I do not synchronise with Exchange.&lt;br /&gt;&lt;br /&gt;I really hope, the whole problem can be resolved in the year to come.&lt;br /&gt;&lt;br /&gt;So far... dead end....&lt;br /&gt;&lt;br /&gt;Thanks for reading. I guess, there must be some other solutions. Please, share your experiences and ideas in the comments. Check out what Google suggests in the right pane, they may have found a better solution elsewhere.&lt;br /&gt;&lt;br /&gt;I do not hold any stock in any companies mentioned in this article. Your feedback is always welcome.&lt;br /&gt;&lt;br /&gt;Cheers!&lt;br /&gt;&lt;br /&gt;&lt;i&gt;PS: I just have found that Boeing claim they have implemented an Exchange connector for CalDAV. I could not find any more details about this rumor.&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-9156171415823895014?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/9156171415823895014/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=9156171415823895014' title='48 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/9156171415823895014'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/9156171415823895014'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/10/how-to-synchronize-ical-with-exchange.html' title='How to synchronize iCal with Exchange?'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>48</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-6474184307676604356</id><published>2007-10-09T13:49:00.000+01:00</published><updated>2007-10-09T13:58:46.459+01:00</updated><title type='text'>Curvy tabs in your Eclipse RCP Application</title><content type='html'>You might have noticed that the default look and feel of your Eclipse RCP application is slightly different to what you are used to while using Eclipse IDE. Many developers want to have exactly the same "Curvy" shape of tabs for the views instead of "lame" square ones. There are two ways of achieving that.&lt;br /&gt;&lt;br /&gt;Way 1: The proper one. Depending on the version of Eclipse platform you are using, you have to edit (or create) either preferences.ini or plugin_customization.ini file in the root of your defining plugin. Add the following line to that file:&lt;br /&gt;org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=false&lt;br /&gt;and voila! &lt;br /&gt;&lt;br /&gt;Way 2: The working one. I have no idea why the previous (proper) way of parameter definition fails sometimes. I have found a neat fix for the problem: you might want to set this workbench preference in your application workbench window adviser.&lt;br /&gt;In ApplicationWorkbenchWindowAdviser.java add the following line:&lt;br /&gt;&lt;br /&gt;PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false); &lt;br /&gt;&lt;br /&gt;to public void preWindowOpen() method. and everything will begin to work like magic!&lt;br /&gt;&lt;br /&gt;Good luck!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-6474184307676604356?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/6474184307676604356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=6474184307676604356' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/6474184307676604356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/6474184307676604356'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/10/curvy-tabs-in-your-eclipse-rcp.html' title='Curvy tabs in your Eclipse RCP Application'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-726484814897059617</id><published>2007-10-04T16:38:00.000+01:00</published><updated>2007-10-04T16:50:33.500+01:00</updated><title type='text'>Dynamic Palettes in GEF</title><content type='html'>Hello again, I am finally back from holiday. Today I will describe a short trick for dynamically updating your GEF Palette.&lt;br /&gt;I wanted to change the contents of the palette in graphical editor depending on user's choice in one of the combo boxes. Imagine combining two models into one by giving user a choice which one to use.&lt;br /&gt;&lt;br /&gt;The original palette is usually created on graphical editor initialisation. You, however, can change the contents of this palette dynamically by modifying the PaletteRoot of your graphical editor.&lt;br /&gt;&lt;br /&gt;So, I have created an additional method in my graphical editor:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;pre&gt;public void updatePalette(LogicalModel model) {&lt;br /&gt;  PaletteRoot root = getPaletteRoot();&lt;br /&gt;  List children = root.getChildren();&lt;br /&gt;  for (int i = 0; i &lt; children.size(); i++) {&lt;br /&gt;   if (children.get(i) instanceof PaletteGroup) {&lt;br /&gt;    PaletteGroup entry = (PaletteGroup) children.get(i);&lt;br /&gt;    if (entry.getLabel().equals("Plots")) {&lt;br /&gt;     // This is a group we want to update&lt;br /&gt;     List&lt;Plot&gt; plots = model.getPlots();&lt;br /&gt;     int size = entry.getChildren().size();&lt;br /&gt;     for (int j = 0; j &lt; size; j++) {&lt;br /&gt;      entry.getChildren().remove(0);&lt;br /&gt;     }&lt;br /&gt;     for (int j = 0; j &lt; plots.size(); j++) {&lt;br /&gt;      CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry(plots.get(j).getName(), plots.get(j).getName(),&lt;br /&gt;        Plot.class, new SimpleFactory(Plot.class), ImageDescriptor.createFromFile(ResultsEditor.class,&lt;br /&gt;          "icons/plot.gif"), ImageDescriptor.createFromFile(ResultsEditor.class, "icons/plot.gif"));&lt;br /&gt;      entry.add(component);&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;This method flushes the whole content of the palette group named "Plots", and recreates it from some logical model.&lt;br /&gt;All I have to do now is to call this new method from an appropriate listener to combo's selection change.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-726484814897059617?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/726484814897059617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/726484814897059617'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/10/dynamic-palettes-in-gef.html' title='Dynamic Palettes in GEF'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-7768995863647217239</id><published>2007-08-15T10:14:00.000+01:00</published><updated>2007-08-15T10:30:45.702+01:00</updated><title type='text'>Storing binary information in XML</title><content type='html'>Sometimes we need to store some binary information within XML format, which is textual.&lt;br /&gt;Designing schemata for your data you should avoid using binary representations if possible, but there are some cases when you absolutely need it. For example, what if you want to store a picture within your XML?&lt;br /&gt;&lt;br /&gt;The problem is that binary data may contain special characters which are prohibited for use in XML.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The solution to this problem is to recode your binary data into a textual form using, for example, Base64 or UUEncode algorithms. The following fragment of Java code demonstrates how to convert an array of bytes (a chunk of binary data) into a properly formed String using Base64 algorithm.&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;byte[] data = getMyBinaryData();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;String encodedData = new sun.misc.BASE64Encoder().encode(data);&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You then can use encodedData as a value for some XML element.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The reverse process of decoding a String into an array of bytes can be done using the following Java code:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;String encodedData = getEncodedData();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;byte[] data = new sun.misc.BASE64Decoder().decodeBuffer(encodedData);&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;UUEncode/UUDecode algorithms are also available in &lt;span style="color: rgb(51, 204, 255);"&gt;sun.misc&lt;/span&gt; package.&lt;br /&gt;This approach will, unfortunately, fail in an Applet, as the access to &lt;span style="color: rgb(51, 204, 255);"&gt;sun.&lt;/span&gt; packages is prohibited for applets. You have to use a different implementation of a transcoding algorithm in such cases. One of the alternatives is:&lt;a href="http://iharder.sourceforge.net/current/java/xmlizable/"&gt; http://iharder.sourceforge.net/current/java/xmlizable/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-7768995863647217239?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/7768995863647217239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=7768995863647217239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/7768995863647217239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/7768995863647217239'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/08/storing-binary-information-in-xml.html' title='Storing binary information in XML'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-1754658941175246335</id><published>2007-08-01T12:03:00.000+01:00</published><updated>2007-08-01T12:56:40.275+01:00</updated><title type='text'>Computing MD5 digest (checksum) in Java</title><content type='html'>MD5 digests are useful to track file (or, in fact, data) modifications. It is very unlikely that two files will have the same MD5 digests. It is extremely unlikely that a minor modification to a file will preserve its MD5 digest.&lt;br /&gt;&lt;br /&gt;I use MD5 digests to decide whether a precomputed result is still valid. For example, you simulate a system of differential equations defined in file "system.xml", and you save the result to a file "result.xml". But what if the user modifies the original system of equations? The computed result will not be correct anymore. The solution is to store the MD5 digest of the original system of equations with your result. When result is selected for display, you check whether the digest of your current system of equations matches the one stored with the result, and if they don't match, the result is not valid.&lt;br /&gt;&lt;br /&gt;There is a number of ways to compute MD5 digests. You can find hundreds of implementations on the web. I stick to the one which comes with standard Java Runtime Environment distribution from Sun Microsystems. Below is my function which returns a String representation of MD5 digest for an arbitrary file:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;public&lt;/span&gt; String checksum(File file) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;try&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    InputStream fin = &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;new&lt;/span&gt; FileInputStream(file);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    java.security.MessageDigest md5er =&lt;br /&gt;        MessageDigest.getInstance(&lt;span style="font-weight: bold; color: rgb(51, 51, 255);"&gt;"MD5"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;byte&lt;/span&gt;[] buffer = &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;new&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;byte&lt;/span&gt;[1024];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;int&lt;/span&gt; read;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;do&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      read = fin.read(buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;if&lt;/span&gt; (read &amp;gt; 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;        md5er.update(buffer, 0, read);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    } &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;while&lt;/span&gt; (read != -1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    fin.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;byte&lt;/span&gt;[] digest = md5er.digest();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;if&lt;/span&gt; (digest == &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;return null&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    String strDigest = &lt;span style="font-weight: bold; color: rgb(51, 51, 255);"&gt;"0x"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;for&lt;/span&gt; (&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; digest.length; i++) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      strDigest += Integer.toString((digest[i] &amp; 0xff) &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;                + 0x100, 16).substring(1).toUpperCase();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;return&lt;/span&gt; strDigest;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  } &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;catch&lt;/span&gt; (Exception e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;    return null&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And if you are using Eclipse RCP and want to compute MD5 digest for an IFile object, here you are:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;public&lt;/span&gt; String checksum(IFile file) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;try&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    InputStream fin = file.getContents(&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    java.security.MessageDigest md5er =&lt;br /&gt;        MessageDigest.getInstance(&lt;span style="font-weight: bold; color: rgb(51, 51, 255);"&gt;"MD5"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;byte&lt;/span&gt;[] buffer =&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt; new byte&lt;/span&gt;[1024];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;int&lt;/span&gt; read;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;do&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      read = fin.read(buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;if&lt;/span&gt; (read &amp;gt; 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;        md5er.update(buffer, 0, read);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    } &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;while&lt;/span&gt; (read != -1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    fin.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;byte&lt;/span&gt;[] digest = md5er.digest();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;if&lt;/span&gt; (digest == &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;null&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;return null&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    String strDigest = &lt;span style="font-weight: bold; color: rgb(51, 51, 255);"&gt;"0x"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;for&lt;/span&gt; (&lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; digest.length; i++) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;      strDigest += Integer.toString((digest[i] &amp; 0xff) &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;                + 0x100, 16).substring(1).toUpperCase();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;return&lt;/span&gt; strDigest;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  } &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;catch&lt;/span&gt; (Exception e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span style="font-weight: bold; color: rgb(153, 51, 153);"&gt;return null&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-1754658941175246335?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/1754658941175246335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=1754658941175246335' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1754658941175246335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1754658941175246335'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/08/computing-md5-digest-checksum-in-java.html' title='Computing MD5 digest (checksum) in Java'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-2744418343771420797</id><published>2007-07-30T23:55:00.000+01:00</published><updated>2007-07-31T00:00:00.885+01:00</updated><title type='text'>Eclipse JRE Configuration to work with Mac OS X</title><content type='html'>Just a short tip for today. When you are configuring your Eclipse framework (Preferences/Java/Compiler) or a particular Java project, select the compiler compliance level to 5.0, as JDK 6.0 is not yet available on Mac OS X (it is still in a beta state, so everything may change soon). This ensures that your final product will run on Mac OS X when you export it in the end.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-2744418343771420797?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/2744418343771420797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=2744418343771420797' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/2744418343771420797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/2744418343771420797'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/eclipse-jre-configuration-to-work-with.html' title='Eclipse JRE Configuration to work with Mac OS X'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-6259262109834828369</id><published>2007-07-27T14:56:00.000+01:00</published><updated>2007-07-27T15:09:29.965+01:00</updated><title type='text'>JNI on Mac OS X</title><content type='html'>JNI (Java Native Interface) is a way to use native (read "C") functions in your Java program. You can read more details about this approach at &lt;a href="http://java.sun.com/j2se/1.4.2/docs/guide/jni/"&gt;Sun Java Web Site&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;A particular problem I was struggling with is how the libraries are loaded when running on Mac OS X. The standard naming convention for using the dynamic libraries in Mac OS X is to use "lib" prefix, and ".dylib" as the suffix. Java Virtual Machine, however, does not follow this convention when trying to load a library, and requires you to use ".jnilib" suffix (and "lib" prefix) instead.&lt;br /&gt;&lt;br /&gt;The typical loadLibrary call:&lt;br /&gt;&lt;code style="color: rgb(51, 204, 255);"&gt;System.loadLibrary("mine");&lt;/code&gt;&lt;br /&gt;will search for &lt;code&gt;libmine.jnilib&lt;/code&gt; in your &lt;code&gt;java.library.path;&lt;/code&gt; and if you have named your library &lt;code&gt;libmine.dylib&lt;/code&gt;, it will produce you an &lt;code&gt;UnsatisfiedLinkError&lt;/code&gt; exception.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-6259262109834828369?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/6259262109834828369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=6259262109834828369' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/6259262109834828369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/6259262109834828369'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/jni-on-mac-os-x.html' title='JNI on Mac OS X'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-4557169624355345339</id><published>2007-07-19T16:24:00.000+01:00</published><updated>2007-07-19T16:30:42.347+01:00</updated><title type='text'>Eclipse SWT: Disabling selection event in a Table</title><content type='html'>Sometimes we do not want users to be able to select cells or rows in the tables, but the standard styles for SWT Table widget do not give a NOSELECTION option.&lt;br /&gt;&lt;br /&gt;This, however, can be easily achieved by masking the selection event, Just use the following piece of code for creating your tables:&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;final Table table = new Table(group, SWT.SINGLE | SWT.BORDER);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;table.addListener(SWT.EraseItem, new Listener() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    public void handleEvent(Event event) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;        if((event.detail &amp; SWT.SELECTED) != 0 ){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;            event.detail &amp;= ~SWT.SELECTED;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;});&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-4557169624355345339?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/4557169624355345339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=4557169624355345339' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4557169624355345339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4557169624355345339'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/eclipse-swt-disabling-selection-event.html' title='Eclipse SWT: Disabling selection event in a Table'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-4276382345047630126</id><published>2007-07-17T14:58:00.000+01:00</published><updated>2007-07-17T15:45:01.713+01:00</updated><title type='text'>Eclipse RCP: NullPointerException when creating the SaveAs dialog</title><content type='html'>When using standard editors from org.eclipse.ui.ide, the default &lt;span style="font-style: italic;"&gt;Save As&lt;/span&gt; action usually fails, throwing a &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;NullPointerException&lt;/span&gt;. This happens when the program tries to create a Save As Dialog. A particular exception usually looks something like:&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;java.lang.NullPointerException&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.ui.dialogs.SaveAsDialog.createContents(SaveAsDialog.java:102)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.jface.window.Window.create(Window.java:426)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1124)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.performSaveAs(AbstractDecoratedTextEditor.java:1580)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.ui.editors.text.TextEditor.performSaveAs(TextEditor.java:115)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at org.eclipse.ui.texteditor.AbstractTextEditor.doSaveAs(AbstractTextEditor.java:3538)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    at ....MultiPageEditor.doSaveAs(MultiPageEditor.java:196)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    ....&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;This, actually, happens when the dialog tries to set the banner image for the dialog, but the image is not available. The default &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;IDEWorkbenchAdvisor&lt;/span&gt; registers such an image for the default &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;IDE&lt;/span&gt;, so must your application. The solution is the following:&lt;br /&gt;1) Make sure you add org.eclipse.ui.ide to the dependencies of your &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;plugin&lt;/span&gt;&lt;br /&gt;2) In your &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;WorkbenchAdvisor&lt;/span&gt; class add the following code to the initialise() method implementation:&lt;br /&gt;       &lt;code&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;Bundle &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;ideBundle&lt;/span&gt; = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    final String banner = "/icons/full/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;wizban&lt;/span&gt;/&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;saveas&lt;/span&gt;_&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;wiz&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;png&lt;/span&gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    URL &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;url&lt;/span&gt; = &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;ideBundle&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;getEntry&lt;/span&gt;(banner);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;ImageDescriptor&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;desc&lt;/span&gt; = &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;ImageDescriptor&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;createFromURL&lt;/span&gt;(&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;url&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;    configurer.declareImage(IDEInternalWorkbenchImages.IMG_DLGBAN_SAVEAS_DLG, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;desc&lt;/span&gt;, true);&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;This will declare a standard banner image from the org.eclipse.ui.ide &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_19"&gt;plugin&lt;/span&gt; as the proper banner image for &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_20"&gt;SaveAs&lt;/span&gt; dialog in the same way as it is done in the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_21"&gt;IDEWorkbenchAdvisor&lt;/span&gt;. Running your application again demonstrates the correct behaviour. If you are still getting a &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_22"&gt;NullPointerException&lt;/span&gt;, check whether you declared &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_23"&gt;plugin&lt;/span&gt; dependencies, and whether you included org.eclipse.ui.ide to your target platform.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-4276382345047630126?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/4276382345047630126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=4276382345047630126' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4276382345047630126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4276382345047630126'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/eclipse-rcp-nullpointerexception-when.html' title='Eclipse RCP: NullPointerException when creating the SaveAs dialog'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-8920100873106012345</id><published>2007-07-11T13:03:00.000+01:00</published><updated>2007-07-11T13:20:44.242+01:00</updated><title type='text'>A follow-up to SBML-related post</title><content type='html'>I contacted the SBML team to discuss the problems I wrote about last week. And I really appreciate their prompt response and collaboration. Especially, I want to thank Michael Hucka, who clarified a lot of things to me.&lt;br /&gt;&lt;br /&gt;First of all, as Michael pointed out, XML Schema standard requires the targetNamespace to be an URI, which does not mean this should resolve to a real web resource. So my reasoning about what schemata you obtain when trying to fetch the namespace URI does not hold water.&lt;br /&gt;&lt;br /&gt;More importantly, is what are the target namespaces for different SBML standards:&lt;br /&gt;Level 2 Version 1 &lt;a href="http://www.sbml.org/sbml/level2"&gt;http://www.sbml.org/sbml/level2&lt;/a&gt;&lt;br /&gt;Level 2 Version 2 &lt;a href="http://www.sbml.org/sbml/level2/version2"&gt;http://www.sbml.org/sbml/level2/version2&lt;/a&gt;&lt;br /&gt;Level 2 Version 3 &lt;a href="http://www.sbml.org./sbml/level2/version3"&gt;http://www.sbml.org/sbml/level2/version3&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So, libSBML version 2.3.4, indeed, supports Level 2 Version 1 specification only, and it crashes when other version is processed. The SBML team is working on fixes to this problem, and a pre-release version of libSBML 3.0.0 works with the newer specification perfectly fine. You code, however, might need some changes due to architecture redesign in libSBML.&lt;br /&gt;&lt;br /&gt;Michael also agreed that it won't hurt to make the web server serve different versions of the SBML schema to different URLs, so the schemata are now served as I (and JAXB) expected.&lt;br /&gt;&lt;br /&gt;Summary:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Check the schema twice, and make sure that you are really using the proper schema.&lt;/li&gt;&lt;li&gt;If you need to support SBML L2 V 2 or 3 - use libSBML 3.0.0&lt;/li&gt;&lt;li&gt;Thanks to everyone from the SBML team for your help&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-8920100873106012345?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/8920100873106012345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=8920100873106012345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8920100873106012345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/8920100873106012345'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/follow-up-to-sbml-related-post.html' title='A follow-up to SBML-related post'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-3835022800805555684</id><published>2007-07-07T14:50:00.001+01:00</published><updated>2007-07-07T14:55:33.056+01:00</updated><title type='text'>SBML standard and problems with libsbml</title><content type='html'>I have spent several days fighting a problem with my Java program which uses libsbml indirectly through the Java Native Interface. Every once in a while the whole java virtual machine would crash while reading an SBML model. So, I performed a detailed investigation of what is wrong about libsbml and the standard itself.&lt;br /&gt;&lt;br /&gt;Let's begin with an SBML schema. My program was using SBML Level 2 Version 2 schema, and the most recent one is SBML Level 2 Version 3. I specifically checked if this problem persists, and my comments are still valid. So, the key point. &lt;a href="http://sbml.org/xml-schemas/"&gt;The schema&lt;/a&gt; defines a specific XML namespace for SBML, and for SBML Level 2 Version 3 it is:&lt;br /&gt;&lt;pre style="color: rgb(51, 204, 255);"&gt;targetNamespace="http://www.sbml.org/sbml/level2/version3" &lt;/pre&gt;However, libsbml, being a &lt;span style="font-style: italic;"&gt;de facto&lt;/span&gt; standard library for SBML support crashes badly when processing a model compliant to the standard. I begin my model with the following:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;sbml xmlns="http://www.sbml.org/sbml/level2/version3" level="2" version="3"&amp;gt;&lt;/code&gt;&lt;/blockquote&gt;Which is exactly what the schema prescribes. Next, I am trying to read this model with &lt;span style="color: rgb(51, 204, 255);"&gt;readSBML&lt;/span&gt; example program supplied with libsbml. Guess what happens?&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;$ ./readSBML model1.xml&lt;br /&gt;Segmentation fault&lt;/code&gt;&lt;/blockquote&gt;Too bad, as this means that the problem is not with my code, but with libsbml itself. Running readSBML with valgrind demonstrates obvious memory management errors in libsbml's XML parser. The problem persists with both expat and xerces-c implementations.&lt;br /&gt;&lt;br /&gt;But why the majority of software tools work fine with this implementation of XML parser? I went on and took a look on what Copasi produces when exporting a model to SBML. Surprisingly, the model produced  with Copasi does not comply to the SBML standard. And the root element of the produced model uses the wrong namespace:&lt;br /&gt;&lt;pre style="color: rgb(51, 204, 255);"&gt;http://www.sbml.org/sbml/level2&lt;/pre&gt;I tried to feed that (non-compliant) model to readSBML, and everything went fine. I even tried to valgrind readSBML with the new model and look:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==15583== ERROR SUMMARY: 0 errors from 0 contexts&lt;br /&gt;==15583== All heap blocks were freed -- no leaks are possible.&lt;/code&gt;&lt;/blockquote&gt;Unbelievable! But is it a problem with Version 3 (and Version 2) schema support or with the whole SBML standard? Just type that namespace http://www.sbml.org/sbml/level2 in your browser, and it will show you the proper schema. The schema, however, clearly specifies:&lt;br /&gt;&lt;pre style="color: rgb(51, 204, 255);"&gt;targetNamespace="http://www.sbml.org/sbml/level2/version3"&lt;/pre&gt;So,  the standard itself is inconsistent, and standard support is badly broken.&lt;br /&gt;&lt;br /&gt;What can we do at the moment? Well, the only way around is to break the standard and continue using the wrong namespace. Does it require any attention from the SBML consortium? I think so. What can I do to write an SBML compliant software tool? Write my own SBML support library. Will a properly SBML compliant tool read the vast majority of published models? I doubt it.&lt;br /&gt;&lt;br /&gt;What have I done to fix my problem? I produced a little routine which converts proper models to the broken form and then reads them with libsbml parser.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-3835022800805555684?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/3835022800805555684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=3835022800805555684' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/3835022800805555684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/3835022800805555684'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/sbml-standard-and-problems-with-libsbml_07.html' title='SBML standard and problems with libsbml'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-1065909493073739178</id><published>2007-07-06T10:22:00.001+01:00</published><updated>2007-07-06T15:45:49.229+01:00</updated><title type='text'>Valgrind it</title><content type='html'>A student was executing his tasks on the same machines as mine, and over the night his task allocated almost all the available memory causing incredible amount of swapping and stopping any progress of all the tasks (not to mention that he started the task by directly logging in to a computer rather than through a queue). Here is a very important advice, and if you follow it you can avoid upsetting many people in a shared computing resources environment: &lt;span style="font-weight: bold; font-style: italic;"&gt;always check your program for memory management errors and memory leaks.&lt;/span&gt; It is pretty easy to do with a modern Linux system, just use a tool called valgrind.&lt;br /&gt;&lt;br /&gt;I recommend to start in a standard way, and read valgrind manual page, just type&lt;br /&gt;&lt;code style="color: rgb(51, 204, 255);"&gt;$ man valgrind&lt;/code&gt;&lt;br /&gt;in your terminal.&lt;br /&gt;&lt;br /&gt;Going beyond referring users to a manual page, here is a little example of how this tool can be used. Imagine starting with the following C program:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char** argv) {&lt;br /&gt;char* string = (char*) malloc(sizeof(char)*strlen(argv[0]));&lt;br /&gt;strcpy(string,argv[0]);&lt;br /&gt;printf("My name is %s\n",string);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/code&gt;&lt;/blockquote&gt;Well done! You have won 5 points if you noticed all the three problems. Let's imagine you haven't.&lt;br /&gt;First, you compile your program with debugging options:&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;$ gcc -ggdb ex1.c -o ex1&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;No compilation time errors, no warnings. If you run the program, the result usually depends on how lucky you are. I am lucky, and the result is exactly what I expected:&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;$ ./ex1&lt;br /&gt;My name is ./ex1&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;But something can be wrong about this program. Let's use valgrind to check. Start with the default checking, and run:&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;$ valgrind ./ex1&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;The tool detects 2 errors and a memory leak of 3 bytes. The first error is:&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523== Invalid write of size 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523==    at 0x4006A2C: strcpy (mc_replace_strmem.c:272)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523==    by 0x8048406: main (ex1.c:7)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523==  Address 0x401F02B is 0 bytes after a block of size 3 alloc'd&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523==    at 0x4005400: malloc (vg_replace_malloc.c:149)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;==10523==    by 0x80483EF: main (ex1.c:6)&lt;/span&gt;&lt;/code&gt;&lt;/blockquote&gt;So, at line 7 of my program I am writing 1 byte beyond the allocated memory block. Did you read Kernighan-Ritchie book? Every string has to be ended by a zero (\0) character. This character is not counted when computing the length of a string, but is copied when copying a string.&lt;br /&gt;The second error is:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==10523== Invalid read of size 1&lt;br /&gt;==10523==    at 0x4006283: strlen (mc_replace_strmem.c:246)&lt;br /&gt;==10523==    by 0xB2A0C1: vfprintf (in /lib/libc-2.5.so)&lt;br /&gt;==10523==    by 0xB2F602: printf (in /lib/libc-2.5.so)&lt;br /&gt;==10523==    by 0x8048419: main (ex1.c:8)&lt;br /&gt;==10523==  Address 0x401F02B is 0 bytes after a block of size 3 alloc'd&lt;br /&gt;==10523==    at 0x4005400: malloc (vg_replace_malloc.c:149)&lt;br /&gt;==10523==    by 0x80483EF: main (ex1.c:6)&lt;/code&gt;&lt;/blockquote&gt;this is directly caused by the previous one. That 1 byte written outside of the memory block is now read when printing the string out. So, I should fix my program by extending the size of the allocated memory block. I create a new program called ex2.c:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char** argv) {&lt;br /&gt;char* string = (char*) malloc(sizeof(char)*(strlen(argv[0])+1));&lt;br /&gt;strcpy(string,argv[0]);&lt;br /&gt;printf("My name is %s\n",string);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/code&gt;&lt;/blockquote&gt;See? I added 1 symbol to the end of my string. Compile and run the program in exactly the same way.&lt;br /&gt;Running with valgrind produces the following output:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==10812== ERROR SUMMARY: 0 errors from 0 contexts&lt;/code&gt;&lt;/blockquote&gt;Congratulations, we fixed both of the errors. But there is a little more to this program:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==10812== LEAK SUMMARY:&lt;br /&gt;==10812==    definitely lost: 6 bytes in 1 blocks.&lt;br /&gt;==10812==      possibly lost: 0 bytes in 0 blocks.&lt;br /&gt;==10812==    still reachable: 0 bytes in 0 blocks.&lt;br /&gt;==10812==         suppressed: 0 bytes in 0 blocks.&lt;br /&gt;==10812== Use --leak-check=full to see details of leaked memory.&lt;/code&gt;&lt;/blockquote&gt;Let's follow the advice, and run leak detection tool:&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;$ valgrind --leak-check=full ./ex2&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;It produces the following report:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==10932== 6 bytes in 1 blocks are definitely lost in loss record 1 of 1&lt;br /&gt;==10932==    at 0x4005400: malloc (vg_replace_malloc.c:149)&lt;br /&gt;==10932==    by 0x80483F2: main (ex2.c:6)&lt;/code&gt;&lt;/blockquote&gt;This means that 6 bytes allocated with our malloc in line 6 were never released. Adding&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;free(string);&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;to the end of the program (and naming it ex3.c) gives us an ideal result:&lt;br /&gt;&lt;blockquote style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;==11013== ERROR SUMMARY: 0 errors from 0 contexts&lt;br /&gt;==11013== All heap blocks were freed -- no leaks are possible.&lt;/code&gt;&lt;/blockquote&gt;Now you can be more sure that your program is correct.&lt;br /&gt;&lt;br /&gt;A couple of closing remarks.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Remember, valgrind checks only that part of your program which was executed. If you have several branches (if-then-else) or subroutines, make sure that you have a decent set of test scenarios to cover it all. You might want to search Google for test coverage methodologies (just type &lt;span style="color: rgb(51, 204, 255);"&gt;&lt;code&gt;man gcov&lt;/code&gt;&lt;/span&gt; if you do not know how to use Google)&lt;/li&gt;&lt;li&gt;Leaving such dynamic memory management errors causes segmentation faults. The most nasty ones appear when such a problem is located inside a shared library called from Java native method. The java virtual machine will crash leaving you frustrated and incapable of catching an exception or something to recover your program on the fly.&lt;/li&gt;&lt;li&gt;Just having a memory leak in a shared library will eventually waste all your virtual memory, and the system will need to be rebooted. Guess why Windows servers have to be rebooted every month or so?&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-1065909493073739178?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/1065909493073739178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=1065909493073739178' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1065909493073739178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1065909493073739178'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/valgrind-it.html' title='Valgrind it'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-4327284382621785716</id><published>2007-07-05T19:40:00.000+01:00</published><updated>2007-07-05T11:40:19.738+01:00</updated><title type='text'>Starting the Blog</title><content type='html'>This time I am starting a real blog, devoted solely to the professional questions and tricky problems I have to deal with every day. Hopefully my enthusiasm will last a little longer this time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-4327284382621785716?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/4327284382621785716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=4327284382621785716' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4327284382621785716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/4327284382621785716'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/starting-blog.html' title='Starting the Blog'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5435484311231149857.post-1545368184030620337</id><published>2007-07-05T11:43:00.000+01:00</published><updated>2007-07-05T12:05:28.088+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gsl_rng_set'/><category scheme='http://www.blogger.com/atom/ns#' term='random number'/><category scheme='http://www.blogger.com/atom/ns#' term='cluster'/><category scheme='http://www.blogger.com/atom/ns#' term='MPI'/><category scheme='http://www.blogger.com/atom/ns#' term='random seed'/><title type='text'>Stochastic Processes and Distributed Computations</title><content type='html'>The most disturbing problem I am struggling with way too often is related to the way random numbers are generated in the majority of modern computers. As many of you know, those are not really random, and are generated with some kind of a numerical algorithm. Most of the random number generation algorithms rely on something called "random number generator seed", that is a parameter to such an algorithm to start a particular pseudo-random sequence. But beware - the majority of algorithms will spit out exactly the same random sequence when given the same seed. The traditional solution for this problem is to initialise the seed with the current time (when the program is started), something akin to:&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;gsl_rng_set(r,time(NULL));&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;if you are using C and GSL.&lt;br /&gt;&lt;br /&gt;This, however, will not help if you are running distributed computations on a cluster, and you need to get an independent random sequence for each of the processes. The solution in this case is to generate a unique random seed for each of the processes. Adding the rank of the current job to the current time value works the best for me when using MPI. The solution looks like the following:&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;gsl_rng_set(r,time(NULL) + MPI::COMM_WORLD.Get_rank());&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;for C++, and&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;int rank;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;gsl_rng_set(r,time(NULL) + rank);&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;if you are using C.&lt;br /&gt;&lt;br /&gt;If you are not using MPI, but rather run independent jobs through the execution queue, you cannot compute such a rank, but you can use hostname checksum / process id combination instead. It is extremely unlikely (I am speaking about the most UNIX architectures) that two instances of your program will be run on the same host within the same second and have exactly the same process id. If it is the case, you have to think a little, but you already have the general idea.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5435484311231149857-1545368184030620337?l=vyshemirsky.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vyshemirsky.blogspot.com/feeds/1545368184030620337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5435484311231149857&amp;postID=1545368184030620337' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1545368184030620337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5435484311231149857/posts/default/1545368184030620337'/><link rel='alternate' type='text/html' href='http://vyshemirsky.blogspot.com/2007/07/stochastic-processes-and-distributed.html' title='Stochastic Processes and Distributed Computations'/><author><name>Vlad</name><uri>http://www.blogger.com/profile/16075641913378869254</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_B82PhAeLbzQ/Sv1iFCoB3xI/AAAAAAAAANo/XEGuJBfAp-0/S220/photo-1.jpg'/></author><thr:total>0</thr:total></entry></feed>
