19 June, 2013

Custom fonts in Android (Part 1 of 3) - Adding to project and set by code

To use custom fonts in Android add the necessary font files to assets/fonts (you may need to create the assets folder).
To apply them by code use the following snippet:

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
textView.setTypeface(font);
On the second part of this series we'll apply custom fonts in xml.
UPDATE: Oh, and please don't include unnecessary fonts in the asstes folder as seen above as it will bloat your apk. Thanks.

15 April, 2013

Parcitypate is a Finalist

Hey everyone, just wanted the share my joy in these news.
My team (+Rui Milagaia (me) , +Lara Rodrigues and +Vasco Avillez) passed to the second phase of the Lisbon BIG Apps contest with our project Parcitypate.
Our project was one of the 15 chosen between 206 submitted from 10 countries.
Now, the hard work starts.
Wish me luck

01 April, 2013

Code Writer Helper

When working with MDA developers have a to write a lot of Transformer code. There are two important steps to write good code generation.

First step: write and test the end code to minimize errors.
Step two: write the transformer that will generate that code based on models.

The second step usually takes a lot of time as the developer has to write a lot os boilerplate prefix, suffix code in the transformer. To make sure the generated code is readable he must also write indentation related code.

Enter Code Writer Helper. It's just a very simple tool that accepts the prefix, suffix, empty row, add tab and remove tab strings, and returns the code ready to be pasted in the transformer file.
Everything written in the Original Code box is transformed in real time to the transformed Code box.

You can also creating different configurations by clicking on the "+" on the top right corner.

This was written in WPF and it's available on CodePlex.

Happy transforming.

Let machines to machine work

DRY - Don't Repeat Yourself

Every developer knows this principle, and a lot actually apply it, yet most are confined in the code-related meaning of it.
 "Let no line of code be repeated."

When its time to do documentation of a system or start the implementation of a new one, etc most of us either start from scratch or do a lot of copy paste. In no time, the documentation is dated and incorrect and so are year old systems that don't follow the new company standards. And that's the good perspective, because some systems won't be outdated because the company stops learning and starts its slow descent to failure.

Why must we continue to limit ourselves to the code and spend most of our working time repeating meaningless tasks over and over again.

Take documentation of a web service. The interface changes and lets update the document, it changes again, and again and again and.... why doesn't the document. If it is actually needed let the document be generated from the interface.

Take system deployment. Hopefully most don't have to do it by hand nowadays but some still do.

Whenever a task repeats itself those who repeat it lose a chance to create something new. And those who can't create won't learn. Most tasks can be automated, let your mind wonder and find new ways to automate your work. Let your imagination run wild and you will find something for sure. People are slow and error prone but the potential for madness that we have gives us creativity. Everyone loves doing what they are best at and no one likes to lose, so why keep competing with machines in these meaningless tasks instead of winning at creating new ones.

The creative mind should create. A great company must have its employees do human work. Once a task is done automate it however you can so you won't have to do it again. The future then awaits with new and exciting tasks of learning and creating new things and simply letting machines to machine work



25 May, 2012

Silverlight + XNA Full size render with System Tray and ApplicationBar

While developing a XNA +  Silverlight App (a Libra port for Windows Phone 7) the XNA rendered page wasn't occupying the whole screen.
After some googling i arrived at Samuel Blanchard blog (its in french) with the answer.
Turns out the System tray and the Application bar rendering is done differently from the rest of the page. And the System tray acts like the Application bar when it's opacity isn't set to 1 (they don't resize the screen area).
So, by setting the opacity of the System tray and the ApplicationBar to 0.99 and then adding margins equal to their height to the LayoutRoot I've managed to get a full XNA rendered layout with System Tray and ApplicationBar.

Opacity settings
shell:SystemTray.Opacity="0.99"
shell:ApplicationBar IsVisible="True" Opacity="0.99"

LayoutRoot margins (SystemTray Height = 32; ApplicationBar Height = 72)
Grid x:Name="LayoutRoot" Margin="0,32,0,72"

10 April, 2012

ODP.NET Slow first connection

I was having a problem with the first time the Oracle provider connection was made. I enabled the oracle log and it only started after the big delay.

Using ProcessMonitor i was finally able to verify that the w3wp process was having trouble creating some directories in the oracle client directory. 

The necessary directory structure was:

C:\oracle_client\log\diag\clients

This saved 20 seconds from the first connection delay. 

Hope it helps someone.

04 April, 2012

Split Large Xml file in smaller valid Xml Files using LinqToXml

Splitting a large xml file using Linq to Xml.

The main performance hit is the initial load of the xml to memory (must find a solution to load each node as needed). There is certaintly room for improvement but for now, its gets the job done.

string path = @"c:\large.xml";
int nrParts = 220;

XElement root = XElement.Load(path);
XElement cleanedRoot = new XElement(root);
cleanedRoot.RemoveAll();
XNode[] children = root.Nodes().ToArray();
int childrenCount = children.Count();

int nodeCountPerPart = (int)Math.Ceiling(childrenCount / (double)nrParts);
int totalNodesToAdd = childrenCount;
int indexBase = 0;

for (int i = 0; i < nrParts; i++)
{
    XElement newRoot = new XElement(cleanedRoot);
    indexBase = i * nodeCountPerPart;
    for (int j = 0; j < Math.Min(nodeCountPerPart, totalNodesToAdd) ; j++)
    {
        newRoot.Add(children[indexBase + j]);
    }

    newRoot.Save(string.Format(@"c:\large_part{0}.xml", i+1));
    totalNodesToAdd -= nodeCountPerPart;
}


UPDATEUsing this method +Master Aucrun  has created a simple WinForms project to easily split an xml file. Thanks +Master Aucrun. You can get it here.