Sunday, December 20, 2015

Angular variable with HTML containing directives compiled via custom directive

This is a code snippet that allows one to compile a scope variable value who contains both HTML and angular directives.

Simple way to deal with it is through this script...

On html:

<div ng-bind-html-compile="someVariable"></div>

On angular controller:

$scope.personName="Mark";
$scope.someVariable="<b>Hello, </b> {{personName}} !!!";

On angular directive:

app.directive('ngBindHtmlCompile', ['$compile', function ($compile) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            scope.$watch(function () {
                return scope.$eval(attrs.bindHtmlCompile);
            }, function (value) {
                element.html(value && value.toString());
                var compileScope = scope;
                if (attrs.bindHtmlScope) {
                    compileScope = scope.$eval(attrs.bindHtmlScope);
                }
                $compile(element.contents())(compileScope);
            });
        }
    };
}]);

Thursday, October 15, 2015

Java - Finding Frequent Phrases in a Large File Effeciently

October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.

Given a large file that does not fit in memory (say 10GB), find the top 100000 most frequent phrases. The file has 50 phrases per line separated by a pipe (|). Assume that the phrases do not contain pipe.

Example line may look like: 

Foobar Candy | Olympics 2012 | PGA | CNET | Microsoft Bing ….
The above line has 5 phrases in visible region.

Java - Finding K-complementary Pairs in Array of Integers

October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.

Write an efficient algorithm to find K-complementary pairs in a given array of integers. Given Array A, pair (i, j) is K- complementary if K = A[i] + A[j];


Java - Check if a String is a Palindrome

October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.

Write an efficient algorithm to check if a string is a palindrome. A string is a palindrome if the string matches the reverse of string.

Example: 1221 is a palindrome but not 1121.


MySQL - Overlapping Date Range Filter

October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.

I have a table for bugs from a bug tracking software; let’s call the table “bugs”. The table has four columns (id, open_date, close_date, severity). On any given day a bug is open if the open_date is on or before that day and close_date is after that day. For example, a bug is open on “2012-01-01”, if it’s created on or before “2012-01-01” and closed on or after “2012-01-02”. I want a SQL to show number of bugs open for a range of dates.

CREATE TABLE bugs (
  id INT,
  severity INT,
  open_date DATE,
  close_date DATE
);

INSERT INTO bugs VALUES
  (
    1, 1,
    STR_TO_DATE('2011-12-31', '%Y-%m-%d'),
    STR_TO_DATE('2011-12-31', '%Y-%m-%d')
  ),
  (
    2, 1,
    STR_TO_DATE('2012-01-01', '%Y-%m-%d'),
    STR_TO_DATE('2012-01-02', '%Y-%m-%d')
  ),
  (
    3, 1,
    STR_TO_DATE('2012-01-03', '%Y-%m-%d'),
    STR_TO_DATE('2012-01-03', '%Y-%m-%d')
  ),
  (
    4, 1,
    STR_TO_DATE('2012-01-03', '%Y-%m-%d'),
    STR_TO_DATE('2012-01-04', '%Y-%m-%d')
  ),
  (
    5, 1,
    STR_TO_DATE('2012-01-06', '%Y-%m-%d'),
    STR_TO_DATE('2012-01-07', '%Y-%m-%d')

  );


MySQL - Function to Capitalize First Letter of a Word

October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.

Write a function to capitalize the first letter of a word in a given string.

Example: initcap(UNITeD states Of AmERIca ) = United States Of America

CREATE TABLE names (name VARCHAR(250));

INSERT INTO names (name) VALUES

  ("uNited states oF americA");


MySQL - Rank Order by Votes

October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.

Write a query to rank order the following table in MySQL by votes, display the rank as one of the columns.

CREATE TABLE votes ( name CHAR(10), votes INT );

INSERT INTO votes VALUES
  ('Smith',10),
  ('Jones',15),
  ('White',20),
  ('Black',40),
  ('Green',50),
  ('Brown',20);

Wednesday, October 14, 2015

Cagayan de Oro - Software Freedom Day 2015

September 19, 2015 - A community organized event, Software Freedom Day, for the community in Cagayan de Oro City was held at Capitol University Laboratories.

It has been a tradition that ITGx together with Capitol University to organize and celebrate SFD every year along with various walk-in guests and invited guests from other school organization. Farthest was guests from Ozamis City which is approximately 5 hours away from the venue.

The goal of the event is to educate the public about the benefits of using high quality Free and Open Source Software (FOSS), Cagayan de Oro's Software Freedom Day celebration is filled with talks on various technologies from some of the leading developers in CdeO.


I had participated in the event as a resource speaker to talk about Play Framework fundamental and basics. Day after the event, I had a conversation with one of the audience and its good to hear that I am helping people learn to easily solve problems. Feels great.

Bellow was the schedule of events during that day and it was full of session everyone could learn.

8:00AM - 8:45AM
Registration and Sign up
8:45AM - 9:20AM
Opening program
Invocation by CS-SBO President
National Anthem

Dr. Karen Joie Cuenca
IT Supervisor, CHED-REGION 10
Keynote Speech
Morning Sessions
9:30AM - 11:45AM
Virtual Reality
By Geoff Diaz and Edmund Madrid Salcedo Jr.
Edge Interactive
LAB A
Python Fundamentals
By ITG-PyTsada with Arvin Vincent Simon from Innovuze
LAB B
Introduction to Play Framework for other Devs
By Paul Labis
Mangium Software
LAB C
Open Source DevOps Tools
By Romar Mayer Micabalo SysAdmin, Innovuze
LAB D
Lunch Break
Afternoon Sessions
1:30PM - 3:45PM
Introduction to Haskell
By JR Requiroso, RedLemon Digital Media
LAB A
Python Flask
By ITG-PyTsada with Romar Mayer Micabalo from Innovuze
LAB B
The IoT Stack: A Dissection: Arduino, Python, MQTT and everyTHING
By Aryan Limjap and Jay Ginete, Capitol University
LAB C
PHP The Right Way
By Rudenyl Betonio, Innovuze
LAB D
3:45PM - 4:00PM
Closing Ceremonies
Signing of event Plaque
Group picture taking


Hoping for next years Software Freedom Day.

Information Technology Group X - Balingasag Tech Talk

August 25, 2015 - A technology event was held in Misamis Oriental Institute of Science and Technology (MOIST) organized by host school in partnership with Information Technology Group X (ITGx). Supported by Google Developers Group - CDO, DevCon, Google Business Group and other companies locally like Mangium Software, Cleversoft and Innovuze Solutions.

The event concluded successfully that is able to transfer useful knowledge on various technologies commonly used and practiced by developers, system administrators and DevOps. Most of the audience are college students and faculties members. 

It was a fun ride for about 1 hour and 30 minutes going to the venue from city proper. Effort was worth it specially when you hear audience saying they learn so much from the event that they can use for their projects. ITGx organized great and passionate pool of speakers with over 30+ years of total experience in technology industry. 

Below is a picture giving ITGx token of appreciation to MOIST for hosting and organizing the event. Special thanks to  Felixberto S. Sambere and Tahir Aziz for a successful, fun filled out-of-town, first of its kind ITGx version of technology tech talk event






I hope to go back there someday and do a talk on technologies I love to work on. Hopefully next year we do another one. :)

Wednesday, July 15, 2015

Fix Inverted Camera on Ubuntu Linux

I am running Lucid Lynx 64 bit OS version on my Asus i3 K52J Series laptop. Like everyone else, I like using Skype video/chat as well as Cheese camera for taking pictures and videos. Not until then when I had a problem using it.


NOTE: Not advisable to do "export LIBV4LCONTROL_FLAGS=3", LIBV4LCONTROL_FLAGS is for debugging purposes only. - by Hans De Goede(libv4l author and maintainer)

I was so disappointed that my camera display was inverted! I tried reading several blogs and posting comments on Ubuntu forum threads online for days and but none of their solutions helped solved my problem. It could have been easily solved if only there was an option to invert my camera on Video4Linux Device Preference. Sadly, there was not! So, I decided to find a way to flip the camera by looking into export options on gtk-v4l(Video4Linux). 

Friday, July 10, 2015

Backup or Restore PostgreSQL Database

There is an easy way to create backup file and restore your current PostgreSQL database using the Linux terminal. I am not sure though if this is the easiest way.

As of the moment I am writing this article, I used the following command to backup and restore my database. 

Using pg_dump and psql will make your life easier. Below are the terminal command I use to backup and restore my database.
  • Backup : pg_dump -U {user_name} {database_name} -f {backup_file_name}
  • Restore : psql -U {user_name} -d {database_name} -f {backup_file_name}
If you are getting an error:

Saturday, June 13, 2015

Encrypt and decrypt your files in Ubuntu using ccrypt

ccrypt is a utility for encrypting and decrypting files and streams. It was based on Rijndael cipher, which was chosen candidate by U.S. government's for Advance Encryption Standard. This cipher is believed to provide a very strong security.

1. Install CCrypt from repo

sudo apt-get install ccrypt

2. To encrypt a file, use one of the following command,

ccrypt -e file_name or ccencrypt file_name

3. It will prompt you for Encryption Phrase aka Password, enter it. for example,

ccrypt -e sample.text 
Enter encryption key: your_key 
Enter encryption key: (repeat) your_key 

Note: Don't forget the encryption phrase, there is no way to get back the original file without it.

Properties File with Arguments or Pameters

The goal on this tutorial is to be able to format a value on a properties file given its parameter or arguments. It is best describe as passing value as a parameter and inserting those values on the string retrieved from the properties file.

To better understand what I'm doing, read and understand my example code below.

Property File Sample
message.welcome= Welcome {0} to {1}!
message.thank= Thank you for you visit {0}.

Friday, June 5, 2015

Quest for New Challenging Project beyond Social Media

It has been quite a journey working with a social media focused company and learned a lot of interesting frameworks and libraries in developing projects and modules internally and the products for years of work. Its nearly end of my contract and I guess its already time for a change so I started looking for other opportunities just recently.

These days, there are so many job sites and mostly these platforms are free for all. Legit though I think that they seem to skip having to screen job applicants or companies for quality. And quality to me means a lot. Who knows? Company or person posting jobs on those job sites may be fake and could just use applicants email as receivers of spam advertising. Or worse, sell your resume somewhere. I maybe wrong but the point I wanna stress out is how confident you are with your trust.

So I scanned these sites and one of which I think is most formidable and promising is Toptal. Its quite a quality site having employers and resources that are hand-picked and filtered. This is beyond services of any other job sites and first impression is awesomeness. They have installed a screening process to insure they get only the best gets the opportunity.  They claim only 3% elite developers gets in.

That given, I am determined to accept the challenge to become part if their growing family of elite developers.

Tuesday, May 19, 2015

Separate Configuration for Play Framework / Play2 production, testing and development environment

Working on Play Framework configuration is easy. In this article, I'll walk you through simple implementation where you are able to create a generic application.conf and a dedicated application.conf for each environment.


Objective: To be able to easily manage your Play2 application configuration separately for production, testing and development.

Solution: Override GlobalSettings onLoadConfig to point to a commong configuration and a fallback configuration specific for your current environment. Your code should look like below.

Thursday, May 7, 2015

Embedded Jetty in Spring MVC, IoC/DI


I was trying to configure embedded jetty in a 
spring application that implements MVC(Model View Controller). I want to utilize single spring applicationContext xml file for IoC(Inversion of Control) and DI(Dependency Injection) on dispatcher servlets.

The goal is to be able to use or reference beans configured/located on already been loaded spring application context. Read and understand my resolution below.