Im Starting Mindfulness Meditation

I have a problem. Too much baggage of my life is taking a toll on me. Responsibilities, surviving in a fast paced tokyo life with little Japanese skill, mortgage etc. keeps nagging in my head. I need something to clear my mind.

Recently I have been going to the gym and is feeling better so far. But it is not enough, now I decided to buy this book. Let see what will happen.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with: , ,
Posted in Javascript

How Fast is a Bullet Train?

Japan’s bullet trains usually runs at a maximum of 320 km/h. But how fast is 320 km/h really? A view from google map might help your imagination.

On our way back from Kyoto, we decided to check our location while onboard a speeding Bullet Train. To our surprise, this is what we saw.

As a software engineer I find the speed of Google Map also very amazing, I imagine that very fast refresh must have been very stressful to Google’s server

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Posted in Javascript

My Son Playing with Dust

OLYMPUS DIGITAL CAMERA

My son started going to Elementary school here in Tokyo. He can play there every Saturday. But throwing dust is his new found interest.

OLYMPUS DIGITAL CAMERA

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with: , ,
Posted in Javascript

Ongoing National Traffic Safety Campaign

Zenkoku koutsu anzen undou jishichuu. I can read it now? Im surprised. Ive been staring at this since many years ago!

My friend said this actually means “Ongoing national traffic safety campaign”.

20130408-072349.jpg

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with:
Posted in Javascript

Clearing a Form with AngularJs

The current stable version of AngularJs(1.0.6 at the time of this writing) doesn’t support this feature yet, but starting from 1.1.x this will be available.

I decided to explore this new feature in this post because I find it useful in an application I am currently writing.

How it works

Just clearing the content of the form using JQuery is not enough for AngularJs to cleanup the state of many variables related to the form. So they provided the $setPristine() method to do this. But this will only clean the state, not the form,. So we also need to clear the form by setting clear values into the model.

    //make the record pristine
    $scope.commentForm.$setPristine();
    $scope.comment = {..};

Demonstration

As a demonstration, I pulled together a sample form. I am going to use AngularJS 1.1.3 from a CDN then use bootstrap for a simple styling. Below is the boilerplate.

 
<html ng-app>
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.min.js"></script>
    <body>
      <div class="container">
        <div class="row">
          <div ng-controller="CommentController">
              <form name="commentForm" method="post">
                  <div class="field">
                      <label>Name:</label>
                      <input type="text" class="text" ng-model="comment.author" />
                  </div>
 
                  <div class="field">
                      <label>Email:</label>
                      <input type="email" class="text" name="email" ng-model="comment.email" required/>
                  </div>
 
                  <div class="field">
                      <label>Message:</label>
                      <textarea class="text textarea"  name="message" ng-model="comment.comment" required></textarea>
                  </div>
 
                  <div class="field">
                      <input type="button" id="sendComment" value="Add Comment" ng-click="postComments(comment)"/>
                  </div>
              </form>
          </div>
        </div>
      </div>
  </script>
    </body>
</html>

That html boilerplate is going to display an form shown below. I named it as a CommentForm. myWPEdit Image

Now, if you read through the html code above, you will notice the CommentController in the form.

...
<div ng-controller="CommentController">
...

This means we have to add the following script to the page.

<script type="text/javascript">
      function CommentController($scope) {
          var defaultForm = {
              author : "",
              email : "",
              comment: ""
          };
          $scope.postComments = function(comment){
              //make the record pristine
              $scope.commentForm.$setPristine();
              $scope.comment = defaultForm;
          };
      }
    </script>

Thats it. It should work now.

See the demo here. View the page source for the complete code.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with: ,
Posted in Javascript

Easily open your file in VIM in Mac

This is a simple way to open your current file in VIM.

Do the following inside VIM



:! open %


If my file is an html file, Boom! It opens my html file in the browser.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with:
Posted in Javascript

Remove a Global Package in NodeJs NPM

I wanted to remove compound which I installed using



sudo npm install compound -g



➜ ~ compound --version

1.1.3

➜ ~ npm -g ls | grep compound

├─┬ compound@1.1.3


because I wanted to replace it with a live build from github. But even if I do:



➜ ~ npm uninstall compound

npm WARN uninstall not installed in /huge/aim/node_modules: "compound"


Maybe I am just a beginner, but this was not obvious to me.

Using some trial and error and some googling, this is how I did it.



➜ ~ npm -g rm compound


Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with:
Posted in Javascript

Enrile’s Counter-argument

There is a recent word war in Philippine Senate a few days ago.

If you bothered to watch that video, you will notice that Enrile’s first response to Cayetano’s issue of fund misuse is by talking about his late father’s 37 million debt.

Is that counter-argument answering the point? Unfortunately this is not the first time that Enrile did that.

See this other one.

Notice that the first thing he mentioned after the privilege speech is about Trillanes’ previous day headline about meddling with Philippine-China negotiation.

Miriam Santiago pointed the same when Enrile mentioned that she almost flunked the bar as a response to the funds misuse.

Miriam being a college debater must understand this more than anybody else.

Anong kinalaman nun?

Anybody uninitiated can understand it too by reading the book Understanding Arguments: An Introduction to Informal Logic

Or taking a free course online about arguments in Coursera.com

So how do we spot a correct counter argument?

Harvard is a good source.

  • refute it, showing why it is mistaken—an apparent but not real problem;
  • acknowledge its validity or plausibility, but suggest why on balance it’s relatively less important or less likely than what you propose, and thus doesn’t overturn it;
  • concede its force and complicate your idea accordingly—restate your thesis in a more exact, qualified, or nuanced way that takes account of the objection, or start a new section in which you consider your topic in light of it. This will work if the counter-argument concerns only an aspect of your argument; if it undermines your whole case, you need a new thesis.

Bottomline, don’t sidetrack it Mr. Senate President. We, Filipino people deserve to know the truth. We don’t care about your personal squabbles.Di po kami interesado sa kahoy.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with: ,
Posted in Javascript

Quickway to Merge 2 Maps in NodeJs

This is not only useful for server-side javascript (NodeJs), but the client-side usually have all the powerful Javascript libraries such as Underscore.js that they don’t really need this script anymore.

I thought about this while processing a form posted to my NodeJs controller.

This is my form.

 
<form action= '/posts/create' method= 'post' id= 'create'>
 
    <input id="title" name="post[title]" type="text" placeholder="Title">
 
    <textarea rows="3" name="post[content]" id="post"></textarea>
 
</form>

In my ExpressJs controller, I have the following

 
...
 
create:function(req,res){
 
            var post = req.param('post');
 
}
 
...

But my MongoDB need more attributes than “title” and “content”, so I have to set them up one by one.

 
...
 
create:function(req,res){
 
  post.author="Huge";
 
  post.authorId="aim";
 
  post.postedAt=new Date();
 
  post.lastModified=new Date();
 
}
 
...

This can be better. So I created a utility



mkdir app/utils/

touch app/utils/utils.js


I then add the following there

 
module.exports = {
 
    merge:function(left,right){
 
        for(var key in right){
 
            if(!left.hasOwnProperty(key) && right.hasOwnProperty(key)){
 
                left[key] = right[key];
 
            }
 
        }
 
        return left;
 
    }
 
}

What this does is set the property to left map if it doesn’t exist yet from right.

I can then modify the content of my ExpressJs controller to

 
...
 
create:function(req,res){
 
  //post.author="Huge";
 
  //post.authorId="aim";
 
  //post.postedAt=new Date();
 
  //post.lastModified=new Date();
 
  utils.merge(post,{
 
    author:"Eugene",
 
    authorId:"eugs51",
 
    postedAt:new Date(),
 
    lastModified:new Date()
 
  });
 
}
 
...

I don’t know others, but I like this one better.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with:
Posted in Javascript

Using layouts in EJS using express-ejs-layouts

I like using EJS than Jade when writing NodeJs apps. But one feature of Jade which I really like is the layout.

For example, in Jade having the layout.jade

 
    !!! 5
 
    html
 
        head
 
                title
 
                link(rel='stylesheet', href='/stylesheets/style.css')
 
        body
 
            block content

And a view index.jade

 
    extends layout.jade
 
    block content
 
        h1 contenthere

should generates

 
    <!DOCTYPE html>
 
        <html>
 
            <head>
 
                    <title><%= title %></title>
 
                    <link rel='stylesheet' href='/stylesheets/style.css' />
 
            </head>
 
            <body>
 
                <h1>contenthere</h1>
 
            </body>
 
    </html>

For me, this is way more convenient than EJS’ #include feature.

Thankfully, I found the express-ejs-layouts which helps achieve the same somewhat.

What I have to do is add the expressLayouts in my settings

 
    …
 
    var expressLayouts = require('express-ejs-layouts');
 
    …
 
    app.use(expressLayouts)

This then allows me to start the layouting I desire.

 
    //layout.jade
 
    <!DOCTYPE html>
 
        <html>
 
        <head>
 
            <title><%= title %></title>
 
            <link rel='stylesheet' href='/stylesheets/style.css' />
 
        </head>
 
        <body>
 
            <%-body%>
 
        </body>
 
    </html>
 
 
 
 
 
    //index.jade
 
        <%- contentFor('body') %>
 
        <h1><%= title %></h1>
 
        <p>Welcome to <%= title %></p>

Should render

 
    <!DOCTYPE html>
 
        <html>
 
            <head>
 
                <title>Express</title>
 
                <link rel='stylesheet' href='/stylesheets/style.css' />
 
            </head>
 
        <body>
 
            <h1>Express</h1>
 
            <p>Welcome to Express body here</p>
 
        </body>
 
    </html>

Great! Now I can continue with my pet project.

Though English is my country's official language it is not my native tongue. If you find anything wrong with my phrases, or any incorrect information, write it out loud in the comments section. The world will be a bit better that way.
Tagged with:
Posted in Javascript