(US) Internet has blacked out today to protest SOPA act.
This is so far the best Stop SOPA campaign I have seen.
From [The OatMeal]
யாதும் ஊரே; யாவரும் கேளிர்; | To us all towns are one, all men our kin;
(US) Internet has blacked out today to protest SOPA act.
This is so far the best Stop SOPA campaign I have seen.
From [The OatMeal]
Steve Jobs, Though I never owned any Apple products but I am a big fan of Steve Jobs. Like many, I liked his passion for the perfection and details. A man full of contradictions who made a remarkable impact on the world in many ways. May his soul rest in peace.
Tip: To create a proportionate size layout on the screen, create a container view group object with the layout_width and layout_height attributes set to fill_parent; assign the children height or width to 0 (zero); then assign relative weight values to each child, depending on what proportion of the screen each should have.
This is the tip from android developers website, I don’t know about you, but it took me five or six time to understand what it means. An example is better than thousand words.
As you can see, I have a ListView and two buttons, I want list view to take 60% of width and 20% each for the buttons.
Layout definition in xml, Take a look at these attributes, android:layout_width android:layout_weight
If you want have cleaner separation in your Android app, you definitely need to move your logic to classes other than Activity, like you do in any GUI patterns. When you try to do that, first obstacle you would face is lack of access to Context class. Context lets you access resources and controls in the Activity. You can achieve this with or with out a Dependency Injection tool.
One of the simplest and easiest way is to pass the Context around, Take a look at line# 7, I am passing application context not Activity’s context to avoid memory leaks. Only pass Activity’s context when its necessary and keep your eyes open for smelly code. This is not the greatest approach, but it will get you going fast. Be aware, you are opening up yourself to lot of repetitive code and potential memory leaks.
Another approach is, lets not pass the Context around, use Service Locator anti-pattern to resolve the Context. Little bit less code and we can’t pass around Activity’s context. But we made testing our code harder then before. Now you have to have another constructor to inject Context or have to mock the MyApplication class to provide testable Context.
Notice we are not passing context to the utility class, we are just creating an instance of the utility class. MyUtility class gets the application Context using some bare bone service locator,
Here MyApplication extends from Application and holds a static reference to itself. Don’t forget to set the Application name as MyApplication in manifest.xml file as described here.
Now lets see a cleaner approach using Robo Guice,
Install and wire up Robo Guice as suggested here, Lets take a look at our Application class, We are extending our application from RoboApplication. This is going to act as our IoC container.
Now we need a module to configure our injections. This module holds the injection map. Think this map as a way Robo Guice decides how to create classes for a particular type. See we haven't configured any mapping for Context, Robo Guice has built in mapping to resolve Context and Application.
Now lets take a look at out utility class, it has nothing interesting except the @Inject attribute, it tells Robo Guice to use this constructor to create MyUtility and resolve all the parameters.
Lets take look at the final piece of the puzzle, Activity class, Take a look at how cleaner it is, No cluttered onCreate method no nasty castings of controls. It is much more readable and less code. Robo Guice finds all the members with @Inject attribute and injects necessary types.
If you have a flat file and want to convert it to some other format like xml or CSV, this may help you. You need PowerShell to do this. All Windows 7 machines come with PowerShell installed, so for most people that shouldn't be a problem
We need some input to proceed, It can be a file or hard coded string or even clipboard. @" and "@helps you handle multiple lines without escaping it.
Now we have the input, lets go through line by line and spit out the output we want, `n is new line character for PowerShell. ` tells PowerShell that statement continues to next line. –f takes the format string and replaces {0} with input parameters.
If you are comfortable with one liners, you can do this, Move formatting string to separate statement, and use % for foreach.You get a nice readable online PowerShell script.
Netscape 6.0 is finally going into its first public beta. There never was a version 5.0. The last major release, version 4.0, was released almost three years ago. Three years is an awfully long time in the Internet world. During this time, Netscape sat by, helplessly, as their market share plummeted.
It's a bit smarmy of me to criticize them for waiting so long between releases. They didn't do it on purpose, now, did they? Well, yes. They did. They did it by making the single worst strategic mistake that any software company can make:
They decided to rewrite the code from scratch.
It’s harder to read code than to write it.
This is why code reuse is so hard. This is why everybody on your team has a different function they like to use for splitting strings into arrays of strings. They write their own function because it's easier and more fun than figuring out how the old function works.
Be conservative in what you send; be liberal in what you accept. - Postel's law
“code that sends commands or data to other machines (or to other programs on the same machine) should conform completely to the specifications, but code that receives input should accept non-conformant input as long as the meaning is clear.” –Wiki via The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)