Friday, 29 April 2011

Extend NTFS Volume

I've had and odd issue with a NTFS partition that I think it's worth to share, if not for others at least for a future me confronted to a similiar issue in the future.

I've been lately ejecting some Hard Disks from an old PC and putting them in external HD cases to have easy access to the tons of dubiously useful old stuff stored there.
One of them had some small System partitions (Windows, Linux) and some large (well, not by today's standards) Data partitions. As the System partitions are no longer needed I thought I would merge them with the Data ones. So, launch GParted from Ubuntu to start off the process.
So far GParted had been a well behaved piece of software that had helped me on many ocasions, but this time something went wrong and crashed in the middle of the process. To my horror, the 127 GBs NTFS partition that I was trying to merge with the 10 GBs System partition was unusable (and the 10 GBs one was gone).

I launched Windows 7, ran a chkdsk, and after some minutes my NTFS data partition was alive and well, but with the original 127GBs size (based on the Explorer readings), and the 10GBs one was missing.

Opening the Computer Management -> Disk Management MMC I was presented with this:

So now my partition was showed on the section below as taking up 136 GBs, but above it was showed as occupying the 127 GBs that Explorer was displaying. So, what the fuck???

After some googling I found out somewhere (sorry, I can't locate the link now), that probably this was a mismatch between the Partition and the NTFS Volume. The partition, as showed on the lower section, is 136 GBs, but the NTFS Volume (that is what Explorer and the upper section show), is 127 GBs.

Hopefully, this can be fixed fast and easy with a Windows utility (it's part of the OS normal installation) that I was unaware of, Diskpart, as explained here.

In my case, contrary to what is stated in the article, chkdsk was not showing the the same info as Explorer, but 133 GBs, but Diskpart was showing the expected 136 GBs.

So, just type:

DISKPART> select volume 5 (in my case)

DISKPART> extend filesystem

and as you can see in the below screenshot, we're done and well!

Monday, 25 April 2011

JavaScript Async Loop

Something that I've needed several times in the last months is calling a JavaScript asynchronous function several consecutive times. This is not a normal loop, as we have to wait for the async function (that invokes a callback once it's done) to return in order to call the next iteration. I've needed this for invoking several animations in a row, where every animation has to wait for the previous one to finish before starting. I've also used it for doing consecutive Ajax calls.
Usually I create an object with a counter and a function that is passed as callback to the async function to be invoked once it's done.

so we would have an object like this:

var runner = {
curVal: 0,
endVal: 10,
run: function(){
if (this.curVal == this.endVal)
var self = this;
codeFunc(this.curVal, 1000, function(){});

to control the invocation of a function like this:

var codeFunc = function(i, delay, callback){
printf("execution " + i + " started " );
printf("execution " + i + " finished");

It would be elegant to use some sort of loop construct for these cases, so after some thinking I've come up with this factory function that simulates a loop:

//@incFunc: loop increment-decrement
//@codeFunc: code to be run "inside the loop", it's a function with a signature like this: codeFunc(i, additionalValues, callback)
//@args: arguments to codeFunc
function steppedFor(startVal, endVal, incFunc, codeFunc, args){
var curVal = startVal;
return function myLoop(){
if(curVal == endVal)
var totalArgs = [curVal];
for(var i=0; i≶args.length; i++)
codeFunc.apply(this, totalArgs);
curVal = incFunc(curVal);

that will be used like this:

(steppedFor(0, 5, function(i){return ++i;}, function(i, delay, callback){
printf("execution " + i + " started");
printf("execution " + i + " finished");

You can find the code here

Monday, 18 April 2011

Distant Lights (Lichter)

Distant Lights (Lichter) is another excellent German film, this time not that recent, as it dates back to 2003. I knew about this film when checking the list of works by Hans-Christian Schmid, the director of Requiem, another film that I absolutely enjoyed some years ago.

The film takes place in two border cities (Frankfurt am Oder and Stubice), located one across from the other, in the German-Polish border drawn by the Oder river.

It portrays several different partially independent stories, but all of them sharing the same baseline, the desperation to achieve a better life (be it in a "better" country or in a better business), how political borders establish personal borders, how unaware of the others a few meters away we can be just because of that imaginary and dramatic line drawn by the "Masters", how nice, contemptible, deceptive, cold... the human nature can be...

The film is set previous the incorporation of Poland to the European Union, so at that time crossing the bridges over the Oder was quite a different story from now, there was a much clearer border there then, a border that hopefully, has partially faded (sure there are economical and social clear differences between both countries, but things are easing up).

Unfortunately, even today some of the characters of the film would have to face the same border faced almost 10 years ago. For Ukrainians, like "second class" Europeans, entering the European Union is still a problem. In spite of sharing with the rest of us the same history of feudalism, invasions, wars for territory, wars for religions... in spite of having had their borders redrawn in countless occasions... they still don't have the freedom of movement that other Europeans enjoy... I hope some day all European countries will be part of a same European State, yes, a State, not the blurred economical "union" that we have now...

The choice of place and nationalities involved happens to be particularly clever to me in showing how absurd some borders are. First, Frankfurt am Oder used to be a German city (well, Prussia encompassed good part of modern day Poland), but after the WWII it was split between Germany and Poland (giving birth to Stubice), then, the differences that German (or EU for this matter) government draws between Polish and Ukrainian citizens are especially stupid if we take into account that the borders between Eastern Poland and Western Ukraine have changed multiple times over the years (territories on both sides conform the historical region of Galitzia).

The overall (very positive) impression that the film left on me is not unlike the one left but this other great film Import-Export dealing with similar topics.

Last summer I was lucky enough to enjoy a few days in the astonishing beautiful city of Strasbourg. Among its many beauties, one that I especially enjoyed was the fact that after so many wars, after all the pain of WWI and WWII... now a pedestrian bridge crosses the Rhin, joining Strasbourg (currently France) with Kehl (Germany), making it extremely pleasant to go through a border too many times outlined in blood.

Tuesday, 5 April 2011

Last month Interesting Stuff (March 2011)

Last month was a rather convulse one, the tragedy in Japan with the Tsunami and the ensuing Nuclear problems and the civil war in Libya have kept people busy jumping from one news source to another. On my side I was rather busy with several things, some of which I'll share here:

  • I've been striving to make my JavaScript code easier to read and maintain, and a bit more elegant, these are to key references:
    JavaScript Guidelines and Code Conventions from the almighty Crockford

    this one from Google was new to me, and makes a rather interesting reading.

  • At this moment, from all the goodies that html5 brings to us, the one I'm more interested in is the Canvas element (I'm mainly interested in playing with images: breaking them in pieces, applying effects), so I've started to play around with it a bit, and these are two rather good references for a beginner:

    Dive into html5

    Opera Dev

  • Years ago I used to follow with great interest all the advances in the development of the JavaScript language (mainly all the Python inspired new features that Mozilla kept adding with each new version of their JavaScript engine). However, in the last years, with the development of so powerful libraries-frameworks and the advent of html5 most people attention seemed to move towards the libraries thing and forget a bit how the language itself could evolve. On my side, my fear to see JavaScript turned into a conventional (class based) language (ECMAScript 4) made me lose interest on the future of the language. So, to my surprise, I've found out that the just released Firefox 4 and IE 9 both already support JavaScript 1.8.5 (aka ECMAScript 5, that has nothing to do with the plans in ECMAScript 4, that have been abandoned :-).
    You can read about future versions here, and get an overview of the new features available in the MDN. One of the goodies that sure will be fun to play with is the Proxy API

  • In the C# world, I found an interesting question about introspecting Dynamic Objects

  • Out of the Programming world, I watched a pretty interesting interview with the Slovenian philosopher, Slavoj Zizek (the setting is excellent) and watched a rather good action film (Running Scared/La prueba del crimen)

  • This is a good reference to try to understand a bit of what's going on in Japan's infamous nuclear reactors