Saturday, March 3, 2012

OS X Finder open in path shortcuts for various Apps (ITerm2, Sublime Text 2, Vim)


While using Finder app a lot of times I need to open a terminal in the current path. Yes you can get info of the folder you are in, select path and then launch terminal and past the path... (sloooooow) :(


Luckily I found a neat useful app to open Terminal app in finders path. Since I am ITerm fan I tried to dig out more and found a script that can launch ITerm in path as well. You can find it here.


In order to make the use of this you will need to create application with the help of Automator. Just paste it to automator, click save and voila or download the apps I already bundled.


There are couple of more apps that I like using it this way so I created few more scripts and bundled apps for it:

  • ITerm 2
  • Sublime Text 2
  • MacVim
  • Vim
And here is how to install these sweeties:

  1. Download source code from bitbucket project (or clone it)
  2. Select apps you want and move application files to your Applications folder (e.g. /Applications)
  3.  Then pick up the application icon and drag it to finders toolbar
  4. There you go.. all set up.. enjoy!
Go ahead fork me up and add apps that you like using as well.

Sunday, February 26, 2012

JDK 1.7 on Mac OS X and in various IDEs

Hey JDK 1.7 is out for a while and here is how to use it in your favorite IDE.

But first you need to download JDK 1.7 OS X Preview. Follow the installation instructions and your JDD 1.7 installation should finish up in

/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/


Eclipse

  • Edit your eclipse.ini
    vim /Applications/Eclipse.app/Contents/MacOS/eclipse.ini

  • Add before first line:
    - vm
    /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java

NetBeans

  • Edit your netbeans.conf
    • "vim /Applications/NetBeans/NetBeans\ 7.1.app/Contents/Resources/NetBeans/etc/netbeans.conf"
  • Change netbeans_jdkhome to
    netbeans_jdkhome="/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"


IntelliJ IDEA

  • Edit your Info.plist
    vim /Applications/IntelliJ\ IDEA\ 11.app/bin/idea.sh

  • Add to the top:
    IDEA_JDK=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

  • Save and run IDEA by
    cd /Applications/IntelliJ\ IDEA\ 11.app/
    ./bin/idea.sh


Saturday, February 11, 2012

Distributed version control is natural way of thinking

Every day I get amazed with afraid looks in developer eyes when I mention working with distributed version control systems. These systems are now very mature and present for a long time and todays developers should feel confortable trying things out.

...BUT reality is very different. Since there are not many enthusiast out there experimenting every day, being passionate about software and focusing on their work in big enterprises I get the situation. I do not think this is good.

.. Yes yes I know it is expensive for an enterprise to upgrade some technology. There are banks out there still having their system on Java 1.2 with no upgrade plan (and of course there are many exams relaying on Cobol). And ok thats fine.

...BUT again we leave in a rapid changing world. We want to be productive and more efficient every day. We want to improve. We are engineers we move forward every day.. or at least some of us do.

I want to encourage positive thinking and educate people over the things I find useful and productive. DVCS are the thing to go.

WHY?

Because DVCS implemented natural human thinking behavior. Our thought BRANCH. They branch very often, and then we return and rethink what we have done and branch to other direction, and then rethink again and again branch and then we come to conclusion. Potentially not the best one but with a big chance to be the best one simple because we have been experimenting with different paths.

That is what distributed is all about. Experiment as much as you like. Branch whenever you need, be creative, productive and efficient.

What are the causes for not accepting this not so new movement? Developers learned to think as the machines worked and now when we managed to make machines work as we think not all of us have evolved to that level.

Do you remember working with MS SourceSafe? No? Good for you. I never personally used it (when I didn't had to) but have worked on educating many developers migrate from it.

LOCKS!

Developers love locking. You lock your file and work on it. So you are the only owner of the file and no one else is not interfering your work. Great in some world, but inefficient, slow and I am not thinking of indirect impact that this revision system caused to poor development teams that were not used to playing good in teams. They all worked in their own world. Their were thought and encouraged to work like that. Thats bad..

Somehow we all managed to overcome this and got used using SVN and merging files become normal.

BUT! SVN (and similars) are central systems. Whatever you want to do to you have to do it over server. Ok it is not the problem because internet is available everywhere. But why will you share all your mindmapping and your experiments with all other developers? Ok even if you want to share it, thats fine, but that is simple bloating the repository since it will be garbage for others but for you valuable process of thinking. And this process is slow! Branching in SVN is slow, comparing changes, listing history (arrrghhh I can scream at the thought of this again) ... all of this needs to go through the central repository.

So you try to overcome all of this and think linearly and keep working with constraints that are not natural to your mind and you transfer that limitations to your code. You do not let your mind play and explore. You do not search for great solutions, but instead just go with the flow, find the shortest path. Thats bad..

And then came DVCS. This is what we needed from the start, but machines were not ready, as machines evolved and our understanding of the ways how to interact with them evolved mankind came up with a way to allow developers work as their brains work, not imposing limitations but instead encouraged experiments. Then github came and made distributed a cool thing and others followed: bitbucket, gitorius, etc.. (I am more a Mercurial guy but do not mind git.. they are both great).

BUT! Enterprises didn't follow and this is bad thing! Enterprises do not realize how much are they loosing. Productivity is suffering. Employees are limited, they are not exploring, not finding better solutions. This should change. Everybody needs to move forward. Its in the nature of mankind. And trust me Mercurial is easy to setup in the enterprise and set up all permission models very similar to SVN so just go ahead an try it.

WHY should I bother?

DVC allows you to experiment. Start working on something, realize that you might do it differently, go back couple of steps start going to different direction, realize that you have a better way, and again go back and do it. Then merge something that you liked about your other work, cherry pick some part that you liked. And then you want to share with others. Its simple, pick what you want to share, share just some branches, rebase your changes and compact them to one change set. Remove the clutter for others. Its very very very easy.

And it gets even better!

You have multiple ways of sharing. E.g. you have a central push repository but during your work you want to share some pre alpha code with your coworker thats working on other part of the functionality. There is still no need to push this code to central and you SHOULDN'T. Share it by publishing it to your friend (multiple options here: shared folder, email, web server) and work together, exchange prepare the code and then push it to central. As you see easy and not limiting at all.

I strongly believe that DVCS make better software engineers, and those that are having trouble working this way are NOT welcome to my team. Unset your limits and let your minds free!

Wednesday, April 27, 2011

Using different fill colors for positive and negative values in AreaChart

Recently I have been playing with Flex AreaChart component and wanted to have different color fills for positive and negative values. This is not available out of the box and in order to achieve this new areaRenderer needs to be created.


I found great forum thread that tackles similar thing (http://forums.adobe.com/message/3005273) and this component needed few improvements to have good stroke colors on negative side as well. 


The biggest challenge was the part where line drops from positive to negative value and should change colors in between values and vice versa. Luckily there is renderedBase property available that holds info where is the zero point and with a little bit of trigonometry we can find out where are the important points where we need to split the line and draw different colors.


And at the end here is the code:


AreaChartRenderer:

package 
{
 
 import flash.display.Graphics;
 import flash.geom.Rectangle;
 
 import mx.charts.chartClasses.GraphicsUtilities;
 import mx.charts.renderers.AreaRenderer;
 import mx.graphics.IFill;
 import mx.graphics.IStroke;
 import mx.graphics.SolidColor;
 import mx.graphics.SolidColorStroke;
 
 public class AreaChartRenderer extends AreaRenderer
 {
  
  private var strokePositive:uint              = 0x127625;
  private var strokeNegative:uint              = 0xCC2800;
  
  private var fillPositive:uint                = 0x127625;
  private var alphaPositive:Number             = 0.2;
  private var fillNegative:uint                = 0xCC2800;
  private var alphaNegative:Number             = 0.2;
  
  
  private static var noStroke:SolidColorStroke = new SolidColorStroke(0, 0, 0);
  
  /**
   *  @private
   */
  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
  {
   super.updateDisplayList(unscaledWidth, unscaledHeight);
   if (!data)
   {
    return;
   }
   
   
   var fill:IFill     = null;
   var stroke:IStroke = null;
   
   var form:String    = getStyle("form");
   
   var g:Graphics     = graphics;
   g.clear();
   
   
   
   var boundary:Array /* of Object */                 = data.filteredCache;
   var n:int                          = boundary.length;
   if (n == 0)
   {
    return;
   }
   
   var xMin:Number;
   var xMax:Number = xMin = boundary[0].x;
   var yMin:Number;
   var yMax:Number = yMin = boundary[0].y;
   
   var v:Object;
   
   // loop through items and prepare fills
   for (var i:int = 0; i < n; i++)
   {
    v = boundary[i];
    
    xMin = Math.min(xMin, v.x);
    yMin = Math.min(yMin, v.y);
    xMax = Math.max(xMax, v.x);
    yMax = Math.max(yMax, v.y);
    
    if (!isNaN(v.min))
    {
     yMin = Math.min(yMin, v.min);
     yMax = Math.max(yMax, v.min);
    }
    
    //middle values
    var x1:Number, y1:Number;
    
    if (boundary[i + 1] != null && boundary[i].item.value > 0 && boundary[i + 1].item.value < 0)
    {
     // we have a transtion from positive to negative. We need to break this down to 2 areas for filling
     
     // determine middle point
     
     // y middle point
     
     y1 = data.renderedBase;
     
     x1 = Math.sqrt(Math.pow((boundary[i + 1].x - boundary[i].x), 2) * Math.pow((y1 - boundary[i].y), 2) / Math.pow((boundary[i + 1].y - boundary[i].y), 2)) + boundary[i].x;
     
     // color positive
     fill = new SolidColor(fillPositive, alphaPositive);
     stroke = new SolidColorStroke(strokePositive);
     
     
     fill.begin(g, new Rectangle(xMin, yMin, x1 - xMin, y1 - yMin), null);
     GraphicsUtilities.drawPolyLine(g, boundary, i, i + 2, "x", "y", noStroke, form);
     g.lineTo(x1, data.renderedBase);
     g.lineTo(boundary[i].x, data.renderedBase);
     g.endFill();
     
     // positive stroke
     drawStroke(g, boundary, i, stroke, form, x1, y1);
     
     // color negative
     fill = new SolidColor(fillNegative, alphaNegative);
     stroke = new SolidColorStroke(strokeNegative);
     
     fill.begin(g, new Rectangle(x1, y1, xMax - x1, yMax - y1), null);
     GraphicsUtilities.drawPolyLine(g, boundary, i, i + 2, "x", "y", noStroke, form);
     g.lineTo(boundary[i + 1].x, data.renderedBase);
     g.lineTo(x1, data.renderedBase);
     g.endFill();
     
     drawStroke(g, boundary, i, stroke, form, boundary[i + 1].x, boundary[i + 1].y, x1, y1);
     
     
    }
    else if (boundary[i + 1] != null && boundary[i].item.value < 0 && boundary[i + 1].item.value > 0)
    {
     // we have a transtion from negative to positive. We need to break this down to 2 areas for filling
     
     // determine middle point
     
     // y middle point
     
     y1 = data.renderedBase;
     
     x1 = Math.sqrt(Math.pow((boundary[i + 1].x - boundary[i].x), 2) * Math.pow((y1 - boundary[i].y), 2) / Math.pow((boundary[i + 1].y - boundary[i].y), 2)) + boundary[i].x;
     
     
     // color negative
     fill = new SolidColor(fillNegative, alphaNegative);
     stroke = new SolidColorStroke(strokeNegative);
     
     fill.begin(g, new Rectangle(xMin, yMin, x1 - xMin, y1 - yMin), null);
     GraphicsUtilities.drawPolyLine(g, boundary, i, i + 2, "x", "y", noStroke, form);
     g.lineTo(x1, data.renderedBase);
     g.lineTo(boundary[i].x, data.renderedBase);
     g.endFill();
     
     drawStroke(g, boundary, i, stroke, form, x1, y1);
     
     // color positive
     fill = new SolidColor(fillPositive, alphaPositive);
     stroke = new SolidColorStroke(strokePositive);
     
     
     fill.begin(g, new Rectangle(x1, y1, xMax - x1, yMax - y1), null);
     GraphicsUtilities.drawPolyLine(g, boundary, i, i + 2, "x", "y", noStroke, form);
     g.lineTo(boundary[i + 1].x, data.renderedBase);
     g.lineTo(x1, data.renderedBase);
     g.endFill();
     
     drawStroke(g, boundary, i, stroke, form, boundary[i + 1].x, boundary[i + 1].y, x1, y1);
    }
    else
    {
     
     if (boundary[i].item.value > 0)
     {
      fill = new SolidColor(fillPositive, alphaPositive);
      stroke = new SolidColorStroke(strokePositive);
     }
     else
     {
      fill = new SolidColor(fillNegative, alphaNegative);
      stroke = new SolidColorStroke(strokeNegative);
     }
     
     
     if (i < n - 1)
     {
      fill.begin(g, new Rectangle(xMin, yMin, xMax - xMin, yMax - yMin), null);
      GraphicsUtilities.drawPolyLine(g, boundary, i, i + 2, "x", "y", noStroke, form);
      g.lineTo(boundary[i + 1].x, data.renderedBase);
      g.lineTo(boundary[i].x, data.renderedBase);
      g.endFill();
      
      
      drawStroke(g, boundary, i, stroke, form);
     }
    }
   }
   
   
   
  }
  
  /**
   * Draws a line with a given stroke between 2 points. It either uses boundary point array or start and end points 
   * 
   * 
   */  
  
  private function drawStroke(g:Graphics, boundary:Array, i:int, stroke:IStroke, form:String, endX:Number = NaN, endY:Number = NaN, startX:Number = NaN, startY:Number = NaN):void
  {
   
   if (isNaN(startX))
   {
    g.moveTo(boundary[i].x, boundary[i].y);
   } else {
    g.moveTo(startX, startY);
   }
   
   var colorStroke:SolidColorStroke = stroke as SolidColorStroke;
   g.lineStyle(colorStroke.weight, colorStroke.color, colorStroke.alpha);
   
   if (boundary[i].element.minField != null && boundary[i].element.minField != "")
   {
    g.lineTo(boundary[i + 1].x, boundary[i + 1].min);
    
    GraphicsUtilities.drawPolyLine(g, boundary, i + 1, i, "x", "min", noStroke, form, false);
   }
   else
   {
    if (isNaN(endX))
    {
     g.lineTo(boundary[i + 1].x, boundary[i + 1].y);
    }
    else
    {
     g.lineTo(endX, endY);
    }
   }
   
   g.endFill();
  }
 }
}


And here is the final result:

Happy charting!

Sunday, March 20, 2011

Flex ArrayIndexOutOfBounds Exception in SDK 4.1 on incremental builds


There is an ArrayIndexOutOfBounds exception with the latest final build of Flex SDK 4.1 which manifests itself with incremental builds. Hopefully problem is solved!

There is no official full sdk release out there but in order to solve this you should replace mxmlc.jar in libs folder of your existing sdklocation.

Good mxmlc.jar file can be downloaded from: https://bugs.adobe.com/jira/secure/attachment/62348/mxmlc.jar

And the complete Jira issue is at: https://bugs.adobe.com/jira/browse/SDK-26799

Enjoy your incremental builds again :)

(it seams that this occurs when you are using halo and spark components al together only)

Tuesday, March 8, 2011

Embed fonts in Flex but smartly!


Embeded fonts have so many advantages instead of using system ones. As Adobe stated already over this topic:

  • Client environment does not need the font to be installed.
  • Embedded fonts can be rotated and faded.
  • Embedded fonts are anti-aliased, which means that their edges are smoothed for easier readability. This is especially apparent when the text size is large.
  • Embedded fonts provide smoother playback when zooming.
  • Text appears exactly as you expect when you use embedded fonts.
  • When you embed a font, you can use the advanced anti-aliasing information that provides clear, high-quality text rendering in SWF files. Using advanced anti-aliasing greatly improves the readability of text, particularly when it is rendered at smaller font sizes.

But there are drawbacks as well:

  • Increased application size (longer download time)
  • Problems with combining halo and spark components (halo must use embed-as-cff: false)
  • Increased compile time (more hitting over the keyboard and shouting ccmooon cmooooon :D )

So there must be some way to have both of 2 worlds of embeded vs non-embeded fonts and enjoy the coolness of embeded fonts. And yes, there is. There are some optimizations available like embeding just the range of characters. 



Flex 4 SDK brought us  '''fontswf''' tool to pack your fonts as swf, which I find as a great way to manage application fonts.


fontswf has some good arguments to optimize what you get as an output at the end eg. enter character range to be exported.


Sample command line:
fontswf -u U+0041-U+005A,U+0061-U+007A,U+0030-U+0039,U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E  -a Arial -o arial arial.ttf


More about this tool and command line arguments: http://bit.ly/gshXnH


And a bit about ranges (explanation what has been done above):
U 0041-U 005A, /* Upper-Case [A..Z] */
U 0061-U 007A, /* Lower-Case a-z */
U 0030-U 0039, /* Numbers [0..9] */
U 0020-U 002F, /* Punctuation */
U 003A-U 0040, /* Punctuation */
U 005B-U 0060, /* Punctuation */
U 007B-U 007E; /* Punctuation */

Monday, March 7, 2011

Coding in the Cloud

Update (03-17) new Cloud ide is available from the creators of Exo platform http://cloud-ide.com/


Everyone is speaking that we are in the years of Cloud. Cloud is everywhere. It leverages your infrastructure, it lowers operational costs, it scales whenever and how you need it, it helps you have your data wherever you go... well I will not discuss previously stated but it is definitely time for clouds to offer us something more. To allow us to live completely in the web. And for developers it means having great development tools online.


There is always a question over how useful is this but with the todays trend to have internet connected devices with not so great processing power and trend for collaboration on every step this might have a great potential. It would be great that you can code check over what your team is doing while you're on your tablet device and even contribute if you want.


....and how close are we to there.. well it seams its around the corner but there are still missing parts so this can be really productive.


Here is the list what is available that came to my attention:
And some of this have really cool features like collaborative editing and live chat, language validation and even compilation they still lack a lot of what you get in your favourite IDEs right now. Eg. 

  • support running just JavaScript
  • some have evaluation ability but fail with good editing features. 
  • you cannot add additional libraries to your project
  • there is no way to simulate running web applications
  • etc.. 
So basically what we have now is a syntax highlighting and some evaluation... but there is some cool factor in all this and certainly there would be some interesting updates and newcomers in this area so definitely something to watch. 

If you ask for my favorite at this time, I am setting my eye on Cloud9. They are basing their engine on ACE which is a successor of Mozilla Bespin (or SkyWriter) project so definitely have a good base.

So don't trow out your IDEs ... for now...