A place to breathe

Tuesday, December 16, 2014

How to install Facebook SDK the hard way

In case if you get an error installing Facebook SDK, try the following "forceful" command:

sudo CM_BUILD=CM_BUILD COMMAND_LINE_INSTALL=1 installer -verbose -pkg facebook-ios-3.1.16..pkg -target /



Then check your ~/Document folder.

The FacebookSDK folder and Bolt.framework should magically appear there!

Saturday, September 20, 2014

Why KL future MRT won't solve traffic issue, but eventually may find success

MRT is a successor of LRT. Did LRT solve KL traffic? No.

The idea of building MRT, if I understand this correctly, is actually to boost local economy through multiplier effect. It would solve public transport, but not for long. So it is correct that the traffic would be solved. But it is just a short term thing.

Why? Because when you have MRT, all people got so excited, they want to board MRT. Now, traffic at popular Klang Valley Highways such as LDP would become better. Less traffic, people enjoy.

Now, because the idea is to boost the economy, it is now the best time to prop up auto demand. Automakers would have some crazy deals and people would by more cars and drive car again. As car grow on the road, probably for a few years, the traffic will be built up. Ah.. now, we need another transport again. Maybe MRT phase 2. And we come back to where we were.

Efficient public transport is not enough. We need car control policies. I hate to say this but Singapore has done it well with their colorful number plates. If we don't want to be seen copying them, we can do something else.. like maybe, bumper stickers for weekend cars, etc.

Auto control policy. That's the key to success in controlling traffic. Less cars, less traffic. Simple as that.

But would that conflict with auto industry? That's why we still have traffic jams. Car makers. Yes. They're the one who make us buy cars and finally end up in traffic.

How to avoid ? Ask carmakers to expand overseas. Beat the Japanese, Germany, etc.

But then, when you ask, does that mean that we drive less in the future? Yes. Would you trade car control policies, which will ease traffic... but at the same time, lost your freedom to driving?

Yes? No?

Pick your choice. If you like to drive around, but at the same time can control your emotions during traffic jams, then you don't want to be controlled when or when not to drive. Means, you don't like car control policies.

If you are OK boarding public transport like most Singaporeans (I think), then, this is the time we ask for car control policies.

I seriously doubt that Malaysians like car control policies. They like to drive. They like to "Chilok". We love Touch and Go. We love cursing in traffic. It's our way of life. It defines our characters. It is also the time when we flash our new sport rims. Traffic jam rocks.

Which the reason why I think MRT project would be a success.



Wednesday, September 10, 2014

Development cycle for Middleman and Heroku

Just a few key steps for development cycle:

1. SSH to your VM:

cd /your/vagrant/vm
vagrant ssh

2. Develop in "source" directory

cd /yourapp/source

Edit index.html.erb, CSS, javascripts, etc.

3. Preview your changes locally

middleman build
middleman server -p 3000

4. Add your changes to git and commit to heroku

git add .
git commit -m "my awesome changes"
git push heroku master.

5. Rejoice and watch HBO !


Monday, September 8, 2014

Publishing your Static site on Heroku using Rails with Git, on top of Vagrant + VM

Why i use Heroku? Well, because it's said in the Middleman page that you can. (see my previous post on setting up Middleman),

No i am serious. I tried to run Rails by myself using Phusion Passanger and it is just .... horror.

So rather than doing it myself, i would trust heroku for now. For Now!

Ok enough. let's get working.

First, go signup at heroku.com, and after that, download Heroku toolbelt. Instead of downloading into your machine, go to ssh and install heroku there:

cd /your/vagrant/dir
vagrant ssh 
bash  (yes, do this please) 
wget -qO- http://toolbelt.heroku.com/install-ubuntu.sh | sh 

Heroku toolbelt is just a fancy words for some executables for Heroku. like installing some binaries somewhere in your directories. Now, you should have "heroku" executable so that you can login:

before your do anything, add the ssh key to your vm:
ssh-keygen -t rsa 

There are few steps that need to be done in order to run middleman page on heroku. One key thing is, you can use "puma" web server:

Heroku wants you to specify the "ruby" version so that it can grab the correct dependencies. If you fail to specify, most likely you fail to run middleman.

Now, let's push our middleman page to heroku:
git push heroku master 

Now when you push it, it will run your puma config that you specify in Procfile
web: bundle exec puma -p $PORT -e $RACK_ENV 

You should now see your middleman page at the specified URL given by heroku. if it returns error, use the following command and check why:

heroku logs



Saturday, September 6, 2014

Enter Middleman

Now that we have our Rails box setup, we can try a few simple static page deployment. Without complicating my life, I opted to run my static files on "Rackspace" server. You can think of "rack" as just makefiles for Rails. Rack can "compile" your static page and auto-publish for you. More on this later. An example of Rackspace server is Heroku.

So a brief overview of some latest web philosophy: Static page.

Because the traditional website queries database while loading, this is just bad. It makes the loading slower and you can loose out your audience attention. So some smart people came up with a smart solution: use static page with front end javascript to load things faster and interact up front with your audience, and at the same time, the static page go calls API of some remote server (that is, our Rails server in this context), to fetch some data.

The javascript front-end plays important role. It does some magical stuff like auto-update (as if the data exists, before even getting some data), do some animation or whatever. Up to you. The point is, don't wait for data to come before interacting with users. You can think of javascript as a receptionist who entertains you with a glass of lemon juice and giving you newspaper to read while waiting for her boss to come over to meet you to give you information on whatever you need from the boss.

Now that your know why we need static page with javascript front-end, we can turn our attention a slightly advance mechanism to "compile" our static page. The app is called "Middleman". Middleman enable us to generate static files and doing some cool stuff on static data and mark ups.

Now go to your vagrant box:

vagrant ssh 
cd /vagrant 

Install middleman

gem install middleman 
middleman init my_project
cd my_project

Check your gemfile inside my_project. don't forget to check your gem files to have :

'therubyracer'
'execjs'
'rb-inotify'

Actually, you can depend on your big Rails Gemfile but I just got errors this way. Run:

bundle exec middleman build 
bundle exec middleman server -p 3000 

Now, you need to run it with port 3000. This is because we have configured our box to display the port 3000.

After executing these commands, go to your browser:

http://localhost:3000. 

See something? Rejoice !










Sunday, August 31, 2014

A new kind of animal: VM, Vagrant and Rails

Now, I manage to run a Vagrant provided by Discourse team. Next, I want to serve static page on Rails. 

All I want to do is to serve a static page. And now let's see what kind of mess I am getting into!
 
Once I plunged into Rails development, I realize that it is hard to develop on my local machine. I don't want to mess up my Mac environment with silly Rails gems dependencies, I am willing to invest a bit more time to understand all kind of Ruby tools. For all its worth, you better be good, Ruby on Rails!!!
  
My idea is to install a Virtual box using Vagrant so that I can ssh into a virtual box. Plus, I will run a Ruby environment within the Vagrant and install all the "germs" (yeah, pun intended) into that vagrant (read: it's not a misspelled of Viagra).
Now that's clean.

First, get the Vagrant image. Create a project folder, say "myapp" and make the source code development "into" a virtual box: 

mkdir myapp
cd myapp 
vagrant init precise32 http://files.vagrantup.com/precise32.box 

This will download a Vagrant config file called "Vagrantfile". Now, I want to host my Rails on port 3000 (following convention), so that, I edit the file here:

config.vm.network :forwarded_port, guest: 3000, host: 3000

Now, we're ready to configure the machines. Issue the following command:

vagrant up

Now, what it does is to do some magic of creating a default VM environment for your "myapp" folder so that you can build an isolated environment within that folder. To access that isolated environment, you need to remote login using ssh :

vagrant ssh
cd /vagrant

You now see your "Vagrantfile". Basically your "myapp" folder has been mounted into "/vagrant" folder in the VM. Cool so far? Run everything to get Rails started:

sudo apt-get update
sudo apt-get install curl 
\curl -sSL https://get.rvm.io | bash -s stable --rails 

Try check your rails:

vagrant@precise32:~$ which rails
/home/vagrant/.rvm/gems/ruby-2.1.3/bin/rails

I feel so safe that all these commands live within the Ubuntu VM on my Mac. At least if things screws up, I can just forget about this VM and starts over.

vagrant@precise32:~$ rvm -v
rvm 1.25.29 (stable) by Wayne E. Seguin , Michal Papis [https://rvm.io/]


A note of caution here: make sure you are running rails version from your home's RVM!.

which rvm 
/home/vagrant/.rvm/bin/rvm 

Now, install Rails. Because you need Rails to create projects.

gem install rails
rails new /vagrant 

make sure you have 'therubyracer' and 'execjs' inside your Gemfile.

bundle install 
rails server 


Go to "http://localhost:3000" . See something? Rejoice !!









Saturday, August 23, 2014

Helpful Unix command to check the biggest files in the server

Often, we suddenly realize that we are running out of space in the server. Here's a command that you can use to check the top files that is consuming your disk space:

du . | sort -nr | head -n10

Tuesday, August 12, 2014

Discourse on Docker

The Discourse team is solving the Rails complicated installation using Docker install. But docker itself is not easy to work with ! (at least for now).

I've spend around 3 hours fiddling with Docker to get the right installation ready. I spent another 2 hours demistify SMTP relay in Discourse. Fortunately i manage to sort out the email sending and my install works like breeze.

Part of the reason why is that docker daemon doesn't seem to be stable. And if you pull non-standard docker library, it may not work.

But honestly, i would rather work with docker than messing up my vps install. Kudos to Discourse team!

Now I'm having a blast. 

Monday, August 11, 2014

Fixing ReCom's forum

Recently, I've decided to fix ReCom's forum (www.recom.org) once and for all. I've enough of VB and I don't want to be adding custom codes and all variety of silly markups just to be broken on the next upgrade.

The last (hasty) upgrade that we did, we broke so many functions that the site is really unusable. I am very disappointed and I don't want to spend anymore time on VB. I blame it on myself for trusting VB.

OK enough ranting.

After a few days of searching, I've decided to migrate ReCom's VB forum. I figured that the work is so much that I quit my full time to work on it full time (of course, I have other things to work on as part time to support myself for a few months). In addition, I am turning it into startup for obvious reason that if i don't do it, the Forum will find its death thanks to the VB 4.x upgrade.

We're going to migrate to Discourse.

After a few days reading and trying out, I manage to install Discourse development on the VPS. But the really bad problem that I have is we have so much dependencies on Rails and I really don't like to way I need to install so many packages on the VPS.

Fortunately, the Discourse team is recommending to use Docker. I decided to then just follow their setups and so far so good.

When installing, I realize that I didn't configure "smtp.example.com" to be ReCom's email.
That would be my next move: to configure email



Monday, July 7, 2014

Swift Syntax overview - more switch

Swift has powerful switch statement construct. Switch statement can compare multiple values, range, as well as tuples. The case statement can also do logic comparison. The following code demonstrates its capability

let myCar = "Ford Focus"
let yourCar = "Ford Fiesta"



switch car {

  case “BMW” :

      let myComment = “Need more cash”


   case let x where x.hasSuffix(“Ford”)   // put the content into   temp variable "x" and compare 


      let myComment = “your car now is \(x) ? “    // interpret the var x inside the bracket with slashes


  default:

     myComment = “Any car will do for me as long as it is cheap”

}
 


Swift Syntax overview - Control

Control Structure 

With the exception of the bracket (for whatever reason) when  we try to iterate in for loop or at the if-else statement, the control in Swift can be considered normal: 

let gameScorePerLevel =  [ 20, 25, 30 ]

var totalBonus = 0 

for score in gameScorePerLevel {
    if score > 30 { 
        totalBonus += 5 
    } else if score > 40 {
        totalBonus += 6 
     } 
 } 


Fallthrough in switch statements

By default, Swift doesn't have the "break" statement because at the end of the "case" statement, it will break. But because C-style programming is avoiding "break" to let the cases fallthrough, so the opposite is introduced in Swift with the 'fallthrough" statement:

let currentLevel = 2
let levelScore = 50 
var currentLife : Int = 1

var levelDescription = "Your score for \(currentLevel) is \(levelScore) " 

switch levelScore { 
      case 10,20 : 
         // update description and break out of the switch stmt
          levelDescription +=  "but you did not get any additional life"
      case 30,40,50 : 
         currentLife += 1    
         levelDescription +=  "and you get extra life"
         fallthrough     // fall to the default stmt
      default: 
         currentLife += 1    //extra bonus life
         levelDescription += "and another bonus life"
}




Labeled Statement


Cool things added to swift is you can label your control statement. For example, if you have a simple arcade shootout game that ask you to fire a target ball with limited attempt, you can just simply do the following loop, and

let attempt = 5 
var totalBall = 10

ballGameLoop : while totalBall > 0 { 

   if attempt == 0 { break ballGameLoop }  // we can go out of the label loop here. Game Over.
 
   switch  ballHit {  

       case targetBall : 
              break ballGameLoop     // we win so go out of labelled loop to finish the game
 
    default : 
           --attempt    
           -- totalBall
       }
         
}





Swift Syntax overview - Array and Dictionary

We declare arrays in Swift as follows:

var myJobs = String()[]    //empty array
var myBooks = ["bus ride", "computer", "cars", "road to success"]    //initialize Array with values

Accessing it using array:

var bestSeller = myBooks[1]

Dictionary:

var bestBoss = Dictionary < String,Float > ()     //empty dictionary
var bestEmployee = [
       "Kyle" : "computer engineer",
       "Jason" : "web developer", 
       "Azeez" : "designer",


Sunday, July 6, 2014

Swift syntax overview - Part 1

I've reviewed a bit of Swift syntax, here's a highlight to save your time:

1. Type inference
Swift switch type declaration to facilitate "type-inference".

Int swiftVar ;   // old c-style
var swiftVar : Int    = 1    // type "Int" is now declared at the front 

var swiftVar   = 1           // type of swiftVar has been inferred as "Int"

It also means that Swift is a type-safe language i.e it needs to be specifically typed. Not like scripting language like JavaScript where you can just define any variable and not care about the type.

2. Typealias
Just like typedef, we can define it as

typealias myType = Uint16 
var yourType = myType.min

3. Constant v Variables
Constant is declared as "let" (C++  is "const").

let x = "Hello"  

x = "World"    //compile error ! changing const value


3. Integer conversion
Swift has a few built-in integer classes that is important for us to know:

Uint8, Uint16, Uint32, Uint64

If you define Uint, it'll be defined based on the platform (Uint32 on 32-bit platform, Uint64 on  64-bit platform).

Conversion between these  integer type variables must be done explicitly (Yawn).

let myInt : Uint8  = 1 
let myBigInt: Uint16 = 2000 

let newInt = myBigInt + Uint16(myInt) 

4. Tuple

I like this Tuple stuff. I am longing to have this in C-style language  (despite the fact that it is so easy to have tuples in scripting language)  .

let myBook = ( 1181818 , "Riding Bus for Dummies")  // declare the tuple 
let (code, title ) = myBook     // extract the tuples and place it nicely into the variable "code" and "title"
println ("The book code is \(code) and the title is \(title) ")

This reminds me of php "explode" function

5. Optionals

I was thinking hard about Swift syntax called "optionals", and I realized that this is probably coming from C-style conditional check:

(testValue) ? "this value " : "another value" ;

If I write this logic based on Swift's "Optional" , it is more like this:

(testValue) ?  "this value" : nil

But in swift, it is more than you think.

Int?   //  yes, this is what we call optional.it means, this value is either of type Int, or nil
var myInt:Int? = 2 
println(myInt!)
Int!  // implicitly unwrapped the optional when you try accessing it
var myInt:Int! = 2
println(myInt)  // no exclamation  mark.  I wonder why they do this.  


Enough for now.













Thursday, July 3, 2014

Swift and Objective-C ... and Cocos2D-Swift and Cocos2D.X

For a year since Nusantara Software released Tumeriq SDK on github,  we didn't really actively work on it anymore. Mostly because we're a bit confused on the direction of the language and platform in the mobile world. But it's time to reflect since we'll be going full force this year with our gaming platform.
As a developer of iOS back in 2011, we made decision to go all in with Apple platform. We bought Macs, iPhone, iPad, learn Objective-C, we made significant investments. We released a few games and we are really excited. And then Android came in with its own set of toolchains. I gave a few tries on Android tools and I didn't like it. So I just ignore Android.

Come to a point where Android users are now so significant,  that many requested our games to be ported to Android. The problem is, with customization of all the screen sizes that come with various forms, it was almost impossible for us to cater with very limited resources. Fortunately, Apportable is there so we can port the work onto Android.

I know there are many who are having this dilemma. Should I go all in with Cocos2D swift? Or should I go with cross platform Cocos2D.X? There's a danger of not using Swift, and there's a danger of not creating your game cross platform.

If we don't take the Swift path, we'll probably loose the power of the language itself. The demo shows that we can do rapid prototyping with Swift.  But the danger of getting into Swift is that, we'll probably get stuck with SpriteKit somehow, which I don't want.

Cocos2D.X is here to stay,  cocos2d-swift depends on Apple's direction. Should we go with Cocos2D.X or should we go full force with swift? To make matters worse, Swift is closed source (unlike Objective-C) and integrates heavily with XCode. To appreciate using Swift, we should also use XCode.

We'll probably have to make a tradeoff between Cocos2D.X and Swift for next Tumeriq release.
In the meantime, I'll learn Swift and enjoy the videos.


Wednesday, June 25, 2014

How to fix outlook issue on corrupted ".ost" file

Windows 8 introduced another interface to read emails, which for is kind of useless because it is too slow.
anyway, if you have a Microsoft account on the cloud and try to hook your Outlook, chances are you'll get an OST issue when you start your Outlook.

This is how I fix it:
1. Delete the original .ost created by Outlook (usually at C:\Users\User\AppData
Local\Microsoft\Outlook\yourmail.ost.

2. Go to Control Panel -> Mail -> Remove the account.

3. Create a new data point inside a user space (somewhere in C:\). Set as default

4. add back the account. You'll see the original location in Step 1 OST populated with the data.

5. Point back the data point from Step 3 to the original data point in Step 1.

Restart the outlook and it will read off from the original data point.


Sunday, June 22, 2014

Installing packages on Debian Wheezy

If you done fresh install of Debian, and this is the first time you try to download some packages, don't worry about getting error. This is because, before you issue "apt-get", you should first update your package database. Having a root account, you just need to issue:

apt-get update
apt-get dist-upgrade 
 
 
 

Wednesday, June 18, 2014

Javascript for Cats

I stumbled upon this website, i think it's a cool way to learn Javascript:
Javascript for Cats 

Tuesday, June 17, 2014

Horrible traffic at LDP

Yesterday was very harsh for bus travellers.
I am currently taking a bus from Putrajaya to Kelana Jaya,  and going back every day. The travel time takes 3 hours.  It turns out that there's an accident along LDP.

I pity the bus drivers, the bus passangers, and myself. I have to stand up close to about 1 hour, sit downs, fell asleep, woke up, and everything in between. I even  finish a book about how to write Cerpen (Cerita Pendek), which is nice. Maybe I will write some cerpen shortly while waiting for these buses to arrive!

Tuesday, June 10, 2014

Meteor Template

You can think of a template as a "app block" that you are going to implement. For example, I want to define a "leaderboard" app block in my website. The cool thing is you can even have app block within an app block.

In a typical meteor example, let's say you want to create a leaderboard for a game. You have a name, score, and a simple button that can increase the score of each an individual person in the list:


name1    score 
name2    score 
… 
button 

In a non-meteor app, you need to first create a form, and post a "request" to the server. Sounds familiar?

In meteor, what we do is we lump both client and server code in one leaderboard.js, and use the "Template" class to make changes to our app.

In our html code, we put the following:

{{> leaderboard}}

This means that there's a template called "leaderboard" that has been created and accessible by the client.

You create the template by defining the following in the HTML:



 

    {{#each players}}
      {{> player}}
    {{/each}}
 

  {{#if selected_name}}
 

   
{{selected_name}}

   
 
  {{else}}
 
Click a player to select

  {{/if}}



In our leaderboard.js. we access the leaderboard template like the following:

  Template.leaderboard.selected_name = function () {
    var player = Players.findOne(Session.get("selected_player"));
    return player && player.name;
  };

"Players" is a class that is instantiated using the MongoDB package like this:

Players = new Meteor.Collection("players");

We initialize all the names in the server code:

if (Meteor.isServer) {
  Meteor.startup(function () {
    if (Players.find().count() === 0) {
      var names = ["Ada Lovelace",
                   "Grace Hopper",
                   "Marie Curie",
                   "Carl Friedrich Gauss",
                   "Nikola Tesla",
                   "Claude Shannon"];
      for (var i = 0; i < names.length; i++)
        Players.insert({name: names[i], score: Math.floor(Random.fraction()*10)*5});
    }
  });

Installing meteor

Meteor is a new JavaScript framework.
To install Meteor, run the following command:

1. curl http://install.meteor.com | /bin/sh

This command will do two main things:
1. it install a .meteor directory that includes:
    a. "meteor" script
    b. packages
    c. releases
    d. tools

2. it install the script in /usr/local/bin/meteor.

When you run the command above, /bin/sh will runs the /usr/local/bin/meteor once.

Inside the "tools" it installs "mongodb" that will be primarily used for the database. Currently, it only supports mongodb.

To uninstall meteor, remove the following:

1. script located at /usr/local/bin/meteor
2. directory in your home at ~/.meteor

Note that you need to be a "sudoer".


Saturday, February 1, 2014

The case of silly orator in a democracy

The problem with democracy is to avoid silly people pretending to be an eligible representative.

Currently we have loose control over the qualification of the people's representative in the government.

The problem with "Orator"

"Orator" is an essential part of a functioning republic-style democracy. "Orator" is a person who get to represent its people into the house.

What if an "Orator" is a silly person pretending to be smart, who will eventually abuse democractic process? It's going to be a downfall of a particular republic.

Public must safeguard itself from silly orator. Silly orator is a disease in any functioning democracy.

Monday, January 27, 2014

Code Sign error: Certificate identity

This is a silly iPhone apps certificate error that gets into my nerve.

But the fix is really simple.

When you compile your iphone / ipad apps, and you get the following errors:
"Code Sign error: Certificate identity 'iPhone Developer"

All you need to do is to :

1. Open the Keychain application at "Utilities->KeyChain Access"
2. When you compile your application, you'll see sometimes there are multiple Certificates are being added. Keep the keychain and xcode open. Delete the duplicate certificates.
3. Recompile
4. If you see code sign error, it just means that you have to download the certificate again. Go to the 
https://developer.apple.com/, and retrieve the certificate. Double click on it, and it should be added.
5. Recompile.

Done!!!

Blog Archive

About Me

I'm currently a software engineer. My specific interest is games and networking. I'm running software company called Nusantara Software.