merging two git repos with history

I needed to merge two repos with history so that the target repo has merging repo’s history. This answer at stackoverflow had solved my issue.

So that was to merge project-a into project-b.

One thing I need to note is that project-b and project-a have to be git-cloned already, so prerequisite for the above the order of execution was as follows:

Also, don’t forget to commit your changes after the merge.

build pipeline plugin first pull request

At my work, we have been using build pipeline jenkins plugin. However, there was a bug with it in our use case, which I have filed a bug for it.

There’s reproduce steps in the bug, but the issue is that parameter values from a wrong upstream job are passed to manually triggered downstream job if the downstream job is shared by a few/many different upstream jobs. Auto deploy downstream jobs do not have the same issue. It’s affected by only manual downstream job.

So I made an update to build pipeline plugin and made a pull request for the first time in my github history. This is the actual difference.

Simple way to convert NodeList into Array in javascript

So what is going on with the above statement? Here’s what’s going on:

  1. getElementsByTagName does not return Array object. Instead it returns NodeList (You can easily test it out on the developer tools. i.e. document.getElementsByTagName(‘li’).constructor)
  2. NodeList does not have array methods. Prototype type chain is not connecting to array prototype at all. (NodeList.prototype.__proto__.constructor == Object)
  3. slice returns a new array object so using slice against NodeList converts NodeList into Array

Late inheritance with __proto__ in javascript

In JavaScript there are so many different ways to inherit a super class. For example, Object.create, jQuery.extend, Child.prototype = new Parent(), and so on.

However, it’s not common to use __proto__ to create inheritance chain in javascript. Let me get to it right now.

So that does not look quite impressive. One cool thing about __proto__ is that any instance gets it when created. In javascript pretty much anything can be overwritten, which means after you create a regular object you can still make the instance inherit from a particular Class. Here’s a good example of late inheritance.

It sorta worked, but how about parent Class’ constructor execution? Unfortunately you will have to run one line of code as a late inheritance penalty.

That was a technique used by many old actionscript developers back in the days to create inheritance chain… We were cautious about its usage since it was undocumented feature and it could have been changed without telling anyone. I’m not sure if all browsers support that syntax, but that’s something good to know and understand how javascript works in my opinion anyways.

News Ticker (HTML5 : canvas)

I used to make news ticker in flash very long time ago. Today I wanted to make a very simple javascript news ticker using canvas. It took about 15 mins for me to make this basic structure. If I want to make it dynamic like loading external rss-feed or something like that it can be done too, but for now I’m too lazy to add them… maybe later…

source code

laravel’s database migration and seed

I have not used laravel 4’s migration and seed features much until couple days ago.
Oh boy, it’s a really sexy tool.

It does not matter whether you are in a team or you are all alone doing everything. It’s a feature that every single develop must use if integrating with a database!

Theoretically if you are a disciplined developer and use those features, confidence level of your database changes when deploying will be very high. I promise!

You will end up needing these if you decide to go with it:

*migration* file should be used for any changes that affect db schemas.
*seeding* file should be used to pre-populate data into db.

UPDATE #1:
I thought it’d be beneficial to add some sample codes.

To create migration file, run this at Laravel’s app directory:

The above command line creates a file something like:

And its content looks something like this:

As you can take a guess, up method is where you change db schema. down method is where you rollback the change.

So let's say I want to add column "username" to "users" table.

(If you want to know more about available methods to manipulate db schema, click here.)

Now you want to run against your db? Then don't look further. Just run this:

After you run the command line, Laravel adds that particular code to migrations db table and that's how it keeps track of history.

Now you realize that you made a mistake and want to rollback your last change, run this:

I'll add seeding sample to the blog post later...

Why I am going full JavaScript

Recently I claimed that I would go full FE. Since I’ve been working on couple projects utilizing Backbone/Marionette, I realized that it’s about time for me to go full JavaScript even for BE using nodejs.

To be honest, I did not use nodejs much except running nodejs via forever and some hello world type apps. However, I’m planning to use javascript for everything as much as possible. Reasons are:

  • Community seems to be there to support you
  • One scripting language for FE/BE
  • Data transport over HTTP is done using JSON mostly
  • Many 3rd party Rest APIs support JSON
  • Performance got much much better

So that means, I will dig up build process, deployment process, and CI for Javascript sooner or later, which I’m happy to investigate.

ECMAScript 6 modules

AMD is new standard in my book and I am glad that ECMAScript 6 introduces modules.

This blog has great depth of the new ECMAScript 6 module.

From the spec, importing a module is very flexible in ECMAScript 6, which I like a lot.
Examples are (also found in the blog above):

  • import { square } from ‘lib/calc’;
  • import { square, MY_CONSTANT } from ‘lib/calc’;
  • import ‘lib/calc’ as c;
  • import { square as squ } from ‘lib/calc’;

As you can see there are 4 ways to import.

Aslo it has requirejs like syntax such as:

which is very similar to AMD syntax