2015/10/02

octave on MAC OS X

About

octave is a GNU project which is a kind of alternative for MatLab. Below covers how I install this stuff in my MBA.

Tutorials

Since I am using port, I follow guides from the official wiki here. Below are the actual commands I have typed.
sudo port selfupdate
sudo port upgrade outdated

sudo port install octave
sudo port install octave +gui

sudo port install arpack -accelerate+atlas
If you can run below commands successfully, congratulation. This post is end. However, if you have gotchas like me, checkout below notes.

Gotcha

  • There are errors like missing fortran compiler
      port install gcc49
    
Gcc other than 49 may work too. But I test with this one.
  • There are errors like missing tex
     port install texlive-basic
     port install texlive-latex
    
After running above calls, run again
   port install octave
It should fix all the problems.

Open octave

You can simply type octave in your spotlight and octave will be there.

2015/07/17

How to use git to do development #2

Recall

Last time I have shown you my configurations. This time I am going to share my visions about git merge and git rebase.

What is merge and what is rebase?

If you are confused about these 2 operations, I suggest you to go through slides here.
For merge, it adds a node (commit) in order to join two parallel branches (with a parent node some where).
For rebase, it moves one of the parallel branches onto another one. “NO” new nodes will be added during this operation.

Workflow?

By workflows, I mean how you tactic and regulate branches in your project. For example, master is a production branch while hotfix are branches that branched off from master. Those hotfix branches must be merged or rebased eventually etc.
The concept of workflow is a kind of regulations or agreements between developers.
IMHO, you do not need this if you are one man band :) Do whatever you like.
If you are not sure which one to start, I suggest you to go through this one first. Even you do not agree with the writer, he gives you hints for modeling your workflow with git.

So, which workflow I have adopted?

Actually, I am a fans of terminal. I would like to keep all my history as linear as possible which is easier for me to read. Therefore, I will embrace git rebase instead of git merge.
However, this does not means I do not git merge at all. Since result of git merge and git rebase are the same eventually, I will use git merge if I am running out of time.
Alternatively, if you are good at using GUI tools like SourceTree, go for git merge instead of git rebase since those GUI is able to tell you commits coming from which branch.

2015/06/21

How to install Mongodb via macport

Warning

This blog post is useless for guys using Homebrew. Actually, according to the official document, you should use homebrew for installing mongodb.
However, if you are the fans of macport, it should be useful for you :).

Steps

  • Follow instructions from here
Congratulation. You have successfully installed Mongodb.

Gotcha

  • Missing some binaries same as issue here
    $> sudo port install mongo-tools
    

2015/06/03

How to setup LuCI web framework with Apache on Ubuntu 12.04

While developing LuCI web services, I found this is quite annoying for moving codes back and forth from my machine to the router.

So, I decided to setup a LuCI development environment on my own machine. Below are steps for doing so.

Prerequisites

  • Ubuntu 12.04

OS I have tested

  • LuCI

If you havn’t installed, please refer to my another blog post

  • Apache2 (Version: 2.2.22-1ubuntu1)

Version of Apache2 is not important if you can take care the PATH issues. For example, the HTML root directory.

Command to install apache2


apt-get install apache2

How it work

Below is a simplified diagram. I have not drawn all the components involved.


           CGI

|APACHE| <-----> |         LuCI           |

# Inside LuCI

|cgi-bin/luci| <--> |luci.sgi.cgi| <--> |luci core|

According to above diagram, we only need to setup a CGI script for briding up apache and luci

Steps

1. Checkout cgi directory location

We need to put luci (a cgi script) in there such that Apache can run.


$> cat /etc/apache2/sites-enabled/000-default

...

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

...

ScriptAlias means apaches will run a corresponding script in /usr/lib/cgi-bin when there are requests to URL http://HOST/cgi-bin/ANY_CGI_SCRIPT

Therefore, we should put luci in /usr/lib/cgi-bin

2. Get a LuCI repository

I am using version LuCI.0.12 from the github here

3. Get luci from the luci repository

Define <LUCI> to be the path for luci repository


# Get CGI script

$> sudo cp <LUCI>/host/www/cgi-bin/luci /usr/lib/cgi-bin/

# Get CSS html template etc

$> sudo cp -r <LUCI>/host/www/luci-static /var/www

# Change permission

$> sudo chown -R www-data:www-data /var/www/luci-static

$> sudo chmod 755 /usr/lib/cgi-bin/luci

4. Edit Apache configuration /etc/apache2/sites-enabled/000-default

Make sure you have been replaced LUA_PATHLUA_CPATHLUCI_SYSROOT and LD_LIBRARY_PATH with your own path.


....

<Directory "/usr/lib/cgi-bin">

        SetEnvIf \

                Request_URI ".*luci.*" \

                LUA_PATH=/home/mondwan/Documents/git/luci/host//usr/lib/lua/?.lua;/home/mondwan/Documents/git/luci/host//usr/lib/lua/?/init.lua;$LUA_PATH; \

                LUA_CPATH=/home/mondwan/Documents/git/luci/host//usr/lib/lua/?.so;$LUA_CPATH; \

                LUCI_SYSROOT=/home/mondwan/Documents/git/luci/host \

                LD_LIBRARY_PATH=/home/mondwan/Documents/git/luci/host/usr/lib:

        AllowOverride None

        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

        Order allow,deny

        Allow from all

</Directory>

....

5. Restart apache


$> sudo service apache2 restart

6. Create a directory for LuCI

The directory /etc/config simulates a config system in OpenWRT which LuCI relies on.


$> mkdir -p /etc/config

7. Write following default contents into /etc/config/luci


config core 'main'

    option lang 'auto'

    option mediaurlbase '/luci-static/openwrt.org'

    option resourcebase '/luci-static/resources'

config extern 'flash_keep'

    option uci '/etc/config/'

    option dropbear '/etc/dropbear/'

    option openvpn '/etc/openvpn/'

    option passwd '/etc/passwd'

    option opkg '/etc/opkg.conf'

    option firewall '/etc/firewall.user'

    option uploads '/lib/uci/upload/'

config internal 'languages'

    option en 'English'

config internal 'sauth'

    option sessionpath '/tmp/luci-sessions'

    option sessiontime '3600'

config internal 'ccache'

    option enable '1'

config internal 'themes'

    option Bootstrap '/luci-static/bootstrap'

8. View on browser

Errors are expected :)

Ubuntu and Openwrt are 2 different OS. They build up with different set of commands for managing computational resources.

In other words, most of the application from official repository cannot be reused here unless you have ported all the internal details from Openwrt to Ubuntu.

NOTE: Some of them have been port to Ubuntu in this PPA

9. Remove incompatitable components so that we can run admin interface


$> cd <LUCI>/host/usr/lib/lua/luci/controller

$> mv admin/ ..

$> rm -fr *

$> mv ../admin/ .

# Clean up cache

$> sudo rm -fr /tmp/luci-indexcache /tmp/luci-modulecache/

10. Try again

If you can see above picture, you can start developing your own LuCI application under folder <LUCI>/host/usr/lib/lua/luci/controller

NOTES

  • ADMIN interface will not work as expected

As stated above, most commands from openwrt are not ported to Ubuntu (eg: ubus). The admin interface will not work as expected.

  • Missing folders I mentioned above

Make sure you are using luci-0.12 since the latest luci alters the build process somehow.

If you are using GIT for downloading source codes, here are commands for checking out luci-0.12


$> cd PROJECT_ROOT

$> git checkout luci-0.12

Then follow my blog post for installation

  • Apache CGI does not work as expected

Please take a look here and make sure cgi module has been enabled.

  • Unable to run /cgi-bin/luci due to permission problem

Try to replace these lines


Order allow,deny

Allow from all

to this


Require all granted

Extras

  • Disable cache mechanism by comment 2 lines

By default, LuCI caches Lua files as binaries. Modification in your applications will be ignored if binaries had been created. Here is a way for disabling such mechanism.


$> vi /usr/lib/cgi-bin/luci

-- require "luci.cacheloader"

require "luci.sgi.cgi"

-- luci.dispatcher.indexcache = "/tmp/luci-indexcache"

luci.sgi.cgi.run()

References

Updates

  • 2015/6/26

    • Update notes contents about missing folder
  • 2017/3/5

    • Fix a typo in the script

    • Add a link about enable Apache CGI

    • Add how to fix permission problems from Apache (Thanks +Anton Key )

    • Rewrite certain sentances and unify the style

  • 2020/01/05
    • Add a note on ubutnu PPA (from stokito)

2015/04/26

How to use git to do development #1

Recall

As mention in previous blog, I will show you my git configuration in this blog.

Notes for reading

  • Comments inside the file
Beside showing reasons why we need to write such config, I strongly recommend you to setup configuration marked with MUST. Otherwise, you may messy up your repository’s history.

For example, if you omit user configuration, personal information will not be attached to commits you created.
  • Feel free to extend the configuration
To be honest, my configuration sourced from here. You can further edit my configurations as what I do on the source.

What’s next

Views about two major workflows (merge vs rebase)

2015/04/21

How to delete specific chrome browsing history

To be honest, I have not expected this need a tutorial for a modern browser like chrome.
However, this task is not naive in Chrome. I would like to document down for future reference.
The official usage which is meaningless since it required you to press item one by one.
This is the correct solution. By clicking with shift button, you can select multiple items at the same time.

2015/03/29

Unity notes #1: Rigidbody VS Collider

While I am going through the tutorial roll a ball, I found that Rigibody and Collider confuse me a lot. I have to do a bit searching so that I can tell the differences between them.
To be honest, official document states the differences clearly. What I am writing below is a kind of rewording so that I know what is going on.

Definition from unity document

Rigibody enables your game object to act under control of the physics.
Collider defines the shape of an object for the purposes of physical collisions.

Similarity between Rigidbody and Collider

  • They are both components that can attach to game objects.
  • They both belong to the physics system in Unity.

Differences

Rigidbody

  • Usually, there is one rigidbody for a game object
  • Where physics take effect (Force, torque)
  • Variation of Rigidbody: isKinematic

Colliders

  • It is common for a game object to have more than one collider to form a compound collider
  • Where collision take effect (2 colliders crashes. Note that at least one Rigidbody must be attached to one of them)
  • Variation of Collider: isTrigger

Pitfalls

Game object falls through the floor plane

Reason
  1. IsTrigger, property of a collider, has been switched on for that game object. No collision occurs between that game object and the floor. Or
  2. There is no colliders attached.
Solution
For 1,
  1. Turn off IsTrigger or
  2. Turn off Use gravity for the rigidbody or
  3. Turn on Is kinematic for the rigidbody
For 2,
  1. Attach a collider

Move static colliders

Reason
A static collider means there is at least one collider attached and NO any Rigidbody attached. Unity assumes this kind of colliders won’t move so that they can make optimisations.
If you moving them during game play, it degrades your game performance a lot.
Solution
  1. Do not move those colliders. Or
  2. Attach a kinematic Rigidbody to that game object

Puzzles

  • For colliders, turn on IsTrigger or not?
In term of behaviours, other objects cannot pass through colliders without turning on IsTrigger. Therefore, whether or not turning on IsTrigger depends on your situations.
  • For Rigidbody, turn on IsKinematic or not?
(Rigidbody + kinematic + Collider + trigger) behaves similar to a static collider. However, moving this kind of game objects won’t degrade our game performance as the static does.

2015/03/13

How to use git to do development #0

Preface

As git becomes popular, more and more developers are trying to make use of it in order to manage their project’s revisions.

However, they may not know where to start and how to do better.

For sharing and showing benefits of using git on development, I am going to write several blogs for documenting how and why some approaches are better to follow.

Hopes you will enjoy this series.

Feel free to point out mistakes I have made :).

Learning resources

Newbie

An online tutorial which go through typical usages of git.

Advanced

An open source book explains git, including introduction, workflows and demonstrations. I strongly recommend you to go through this book if you would like to master Git.

If above links cannot help you, checkout this one which provided by github.

What’s next

To be honest, this blog just suggest you links so that you know where to start and get help.
In next blog, I will show you my git configurations and explain why I wrote like that.

Ways to navigate directories in Linux

Generally speaking, there are 2 types of commands for navigating directories in Linux system.
They are listed in the following.
  • cd
  • pushd and popd

cd

$> cd <PATH>
Besides jumping to <PATH>, command cd will also remember the last directory you have visited. It means that you can jump back and forth between the current location and the previous location.
# For demonstration, assuming we are staying at dir1 first
$ ~/dir1>

# Go to dir2 
$ ~/dir1> cd ../dir2

$ ~/dir2> 

# Jump back to dir1
$ ~/dir2> cd -

$ ~/dir1>

# Jump back to dir2
$ ~/dir1> cd -

$ ~/dir2>  

pushd and popd

Since command cd is able to remember only one directory, you need to use pushd and popd if you would records more.
# Assume we are staying at dir1
$ ~/dir1>

# Go to directory dir2 and records down
# NOTE:
# There are 2 records. The left one represents current directory while the right 
# one represents the directory you have pushed.
$ ~/dir1> pushd ../dir2
~/dir2 ~/dir1

$ ~/dir2>

# Go to directory dir3 and records down
$ ~/dir2> pushd ../dir3
~/dir3 ~/dir2 ~/dir1

$ ~/dir3>

# Checkout current directory stack
$ ~/dir3> dirs
~/dir3 ~/dir2 ~/dir1

# Go back dir2
$ ~/dir3> popd

$ ~/dir2>

# Go back dir1
$ ~/dir2> popd

$ ~/dir1>

# Errors
$ ~/dir1> popd
bash: popd: directory stack empty

2015/02/15

Tips for using android studio

About android studio

As you may not know, android studio is a new IDE for developing android application.
Although it seems that this is a kind of introduction, below sharing will not convince you to use this tool. Instead, i am going to talk about how to use this studio wisely.

Recommend websites

Better than nothing. It guides you how to setup the android studio on your machine.
If you get errors like missing JVM on MAC OS because of missing STUDIO_JDK environment variable, try putting below scripts in folder ~/Library/LaunchAgents.
$> cat ~/Library/LaunchAgents/android.studio.jdk.setting.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>android.studio.jdk.setting</string>
    <key>ProgramArguments</key>
    <array>
        <string>sh</string>
        <string>-c</string>
        <string>launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
Someday, when you are getting annoyed by typing dummy codes again and again, you must check out this website. It shows you shortcuts for doing Tasks like generating getter or setter, moving codes around etc. To be honest, it saves my life.