Tuesday, July 4, 2017

Create Scala Project using SBT and Jar using sbt-assembly


  1. Download and install SBT - http://www.scala-sbt.org/download.html
  2. Create SBT Scala Project by running this command - sbt new sbt/scala-seed.g8
  3. When prompted for the project name, type HelloWorld. This will create a new project under a directory named HelloWorld.
  4. Run the sample application by access HelloWorld folder, type sbt, compile and run.
  5. Add sbt-assembly as a dependency in project/assembly.sbt
    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")
  6. Type assembly.
  7. Now you'll have an awesome new assembly task which will compile your project, run your tests, and then pack your class files and all your dependencies into a single JAR file: target/scala_X.X.X/projectname-assembly-X.X.X.jar.
  8. Type java -jar target/scala_X.X.X/projectname-assembly-X.X.X.jar to run the program.
References:

Wednesday, April 12, 2017

18 Important Notes To Be a Tech Founder

Why Tech Startup failed badly? Below are the 18 important notes to be a Tech Founder.
  1. You must be willing to wear multiple hat.
  2. Do one on ones, build borne with your employee.
  3. You can make money if you have an audience to your website, either by sponsorship or charging.
  4. Learn to be a Salesman. Follow up!!! Most of the developer just don’t know how to sell and market. This is related to point 1 – be willing to wear multiple hats. If you just can’t sell, find a co-founder might be a solution.
  5. Just because you would use and pay for a product, it doesn’t anyone else will. Customer validation is very important.
  6. Most businesses are built at networking groups. Join those meeting group if you want to be effective, you make friends, collecting business card and helping people.
  7. You can always find freelance or contractor to build your software.
  8. Writing is 50% writing, 50% self-promotion. Basically, you can request a blogger to link your page to your article. i.e. I like your blog. Your blog helps me up so much and thank you for doing. By the way, I just put up a blog post on XXX and I would like to get your feedback and link up if there anyway you can help us promote it. That’s will be awesome.
  9. You don’t have to give someone equity unless they want it. As a born developer, when you find someone can work well together, you tend to offer a partnership. Actually, you could hire him an employee and give a great bonus when the company grow. Giving equity might not give you problem now, might be later.
  10. Pay professionals when its matter. i.e. hire a designer if you are not with it.
  11. Provide value to others and it will come back to you.
  12. Consulting is a good way to build a company.
  13. Hire slow, fire fast. Spend time in the hiring process. i.e. invite the candidate to work together in a week. If you see he is no good fix, try to get them out as soon as possible.
  14. Don’t over engineer. i.e. build your own billing system.
  15. Spam – It works. The mailing list is really valuable.
  16. Over-deliver to your customer by giving them extra feature that they need it.
  17. Advertise about each new feature.
  18. Don’t be afraid of giving away. i.e. free weekend access by code school.

Thursday, January 19, 2017

JavaScript: Module Pattern with Anonymous Closure

Most developers create module JavaScript only with Public properties.
var ARMORY = {
  weaponList : [ * List of weapon object * ],
  removeWeapon : function(...){},
  replaceWeapon : function(...){},
  makeArmorRequest : function(...){}
};
Above module has a bunch of public variables and methods which can still be accessed by any code that know the name of the space and its properties.

What if we wanted some stuff to be accessible only to the module? Some privacy? This can be easily accomplished by wrap the entire set of properties in an anonymous immediately invoked function expression (IIFE).
var ARMORY = (function(){

  // Private
  var weaponList = [ * List of weapon object * ];
  var removeWeapon = function(...){};
  var replaceWeapon = function(...){};

  // Public
  return{
    makeArmorRequest: function(...){}
  }

})();
With IIFE, you can only have a single instance and you can call the instance without New. E.g.:
ARMORY.makeArmorRequest();

JavaScript: Ternary Conditional

Some simple conditionals take a lot of code to choose on assignment.
let isAuthor = false;
let weapon;

if (isAuthor) {
  weapon = "Exalibur";
} else {
  weapon = "Longsword";
};
Let's use a syntax trick to make this more concise!

The ternary conditional provides a shortcut over lengthier conditional blocks. Ternary conditional syntax:
someCondition ? pickThisIfTrue : pickThisIfFalse ;
Let's turn our lengthy conditional example to ternary conditional.
let isAuthur = false;
let weapon = isAuthor ? "Exalibur" : "Longsword";

JavaScript: Loop Optimazation

Here are the common For loop scenario.
let data = {name:["Simon", "Alvin", "Sharmal"]};

for(let i=0; i<data.name.length; i++){
  console.log(data,name[i]);
};
This is not  the best way because, at the start of each potential loop cycle, the program will need to find and retrieve:
  1. the value of i
  2. the data object
  3. the name property
  4. the array pointed by the property
  5. the length property of the array
We can use "caches values" to curtail lengthy, repetitive access to the same data.
let data = {name:["Simon", "Alvin", "Sharmal"]};

for(let i=0, x= data.name.length; i<x; i++){
  console.log(data,name[i]);
};
Memory access during loop control now only needs to:
  1. retrieve the value of i
  2. retrieve the value of x

JavaScript: Short Performance Tips

1. Use a document fragment to insert additional all at once.
  • Each new addition to the DOM causes document "reflow", which can really hinder user experience.
  • Fragments are invisible containers that hold multiple DOM elements without a node.

Bad Performance
let list = document.getElementById("kotwList");
let kotw = ["Simon","Alvin","Melvin","Shelman"];
for(let i=0, x=kotw.length; i < x; i++){
  var element=document.createElement("li");
  element.appendChild(document.createTextNode(kotw[i]));
  list.appendChild(element);
}

Good Performance
let list = document.getElementById("kotwList");
let kotw = ["Simon","Alvin","Melvin","Shelman"];
let fragment = document.createDocumentFragment();

for(let i=0, x=kotw.length; i < x; i++){
  var element=document.createElement("li");
  element.appendChild(document.createTextNode(kotw[i]));
  fragment.appendChild(element);
}

list.appendChild(fragment); // Only one DOM touch.

2. Declare variable as few times as possible. 
  • Every var keyword adds a lookup for the JavaScript parses that can be avoided with common extension.

Bad Performance
var name;
var age;
var birthday;

Good Performance
var, name, age, birthday;

Wednesday, January 18, 2017

JavaScript: Measuring Performance

You can test the speed of your code using console.time([label]) and console.timeEnd([label]).

Example:
console.time("SpendTest");
for(let i=0; i<100; i++){
  console.log(i);
};
console.timeEnd("SpendTest");