Tag Archives: update

Go to this web site: 




Now go to your Fire TV.
Settings > About > Check For System Update




Define a stack structure with “min” function — a function to get the minimum value within the stack. The time complexity of min, push and pop functions must be O(1).


結合鍊錶一起做。首先我做插入以下數字: 10, 7, 3, 3, 8, 5, 2, 6

0: 10 -> NULL (MIN=10, POS=0)
1: 7  -> [0]  (MIN=7,  POS=1) // 用數組表示堆棧,第0個元素表示棧底
2: 3  -> [1]  (MIN=3,  POS=2)
3: 3  -> [2]  (MIN=3,  POS=3)
4: 8  -> NULL (MIN=3,  POS=3) // 技巧在這裡,因為8比當前的MIN大,所以彈出8不會影響當前的MIN
5: 5  -> NULL (MIN=3,  POS=3)
6: 2  -> [2]  (MIN=2,  POS=6) // 如果2出棧了,那麼3就是MIN
7: 6  -> [6]


所以,藉助輔助棧,保存最小值,且隨時更新輔助棧中的元素。push第一個元素進A,也把它push進B,當向Apush的元素比B中的元素小, 則也push進B,即更新B。否則,不動B,保存原值。向棧A push元素時,順序由下至上。輔助棧B中,始終保存著最小的元素。

然後,當pop A中的元素小於B中棧頂元素時,則也要pop B中棧頂元素。


The following is an optimized implementation.  Repeated minimum value will not be stored through comparing values while pushing or popping values.

#include <vector>
#include <cassert>

using namespace std;

 * Class defining a new type of stack supporting any datatype.
template <typename T>
class StackWithMin
    vector<T> dataStack; // stacks to store data
    vector<size_t> minStack; // stack to store position of minimum value


     * Push data to the stack at the same time update the minimum stack if the
     * new data is smaller then the current minimum value. Throw exception if
     *  stack is empty.
    void push(T data) {
        if (minStack.empty() || data < dataStack[minStack.back()])

     * Pop data to the stack at the same time pop from the min stack if it is
     * popping the minimum value. Throw exception if stack is empty.
    void pop() {
        if (dataStack.back() == dataStack[minStack.back()])

     * return the current minimum value.
    T min() {
        assert(!dataStack.empty() && !minStack.empty());
        return dataStack[minStack.back()];

 * Main program
int main()
    StackWithMin<int> stack = StackWithMin<int>();
    printf("Minimum value: %dn", stack.min());
import java.util.Stack;

public class Pactice02 {

    public static void main(String[] args) {
        System.out.println("Hello World!");
        AdvancedStack stack = new AdvancedStack();
        System.out.println("Minimum value: "+ stack.getMinimum());
        System.out.println("Minimum value: "+ stack.getMinimum());
        System.out.println("Minimum value: "+ stack.getMinimum());
        System.out.println("Minimum value: "+ stack.getMinimum());

    public static class AdvancedStack extends Stack {

        private Stack mMinimumStack = new Stack();

        public E push(E item) {
            if (mMinimumStack.empty() || item.doubleValue()  0) {
                return mMinimumStack.peek();
            return null;


What’s happening

One day, when I opened up terminal as usual, it showed [Process completed] and just terminated. I could not type any thing, run any scripts and work on my project. Even worse, this made me unable to install programs into my computer because many installations need to run shell scripts. Okay, I searched over the internet and there was no solution for that. I even peaked many parts in the Mac OSX system to see if there were any mis-configuration, of course nothing helps. After all, I though if there is nothing wrong, it must be  something done with my /bin/bash. And after I upgraded my bash, my lovely terminal came back!

[expand title=”Let’s fix it” tag=”h5″ trigclass=”arrowright”]

Change shell’s default execution

The truth is, when you open terminal, it execute /bin/bash. As it is not working now, we need another environment for us to execute stuff. Open “Terminal->Preference”, and change “Shells open with” manually to “/bin/sh”.

Change What Shell Opens

Update /bin/bash

Now we are going to download the latest version of bash and replace the old one. Open up a new terminal and now you are able to execute commands. Copy and paste the following codes into the terminal, they will automatically handle everything for you.

	curl -LO
	tar zxvf bash-4.2.tar.gz
	cd bash-4.2
	./configure &amp;&amp; make &amp;&amp; sudo make install
	chsh -s /usr/local/bin/bash {user_name}
	sudo bash -c &quot;echo /usr/local/bin/bash &gt;&gt; /private/etc/shells&quot;
	cd /bin
	sudo mv bash bash-old
	sudo ln -s /usr/local/bin/bash bash
Once done

Go to “Terminal->Preference” again and change :Shells open with: back to “Default login shell”. Enjoy!


[expand title=”Detailed explanations” tag=”h5″ trigclass=”arrowright”]

What I did?

Okay, I admit that I did something to the system sometimes ago. I was doing some experiments on “sandboxing” and played with “chroot jail” stuff before. That is, I need to create an environment with restricted support to the program I run. So I wrote a sandbox, configured it’s root to a ‘secure’ place (anywhere not the actual root), and copy essential executables to that new root. Well, so far I think I didn’t do anything harm to the system, but I might corrupt the /bin/bash when I copied it to the sandbox root.


Shell will run the following files before letting user to do anything. Check everyone to see if there are any misconfigurations.

  • ~/.bash_profile (for /bin/bash)
  • ~/.profile (for /bin/sh)
  • /etc/profile (for /bin/sh)
  • /etc/bashrc (for /bin/bash)
  • (google for more)

To play with, add some echoes to see if they works. Btw, I love nano more than vi, so try out “sudo nano /etc/bashrc”.

Playing with Shell
Another thing

The code above updates your bash to version 4.2. To check if there is any new version, go to the ftp.



Hi there, its been a long time that InstaMusic haven’t been updated. Sorry for that because I had been so busy in working on a game project in my company. Anyway, I am quitting for the sake of pursuing a master degree. And finally I have time to implement what I thought up and designed!

An new application “InstaMusic Beta Channel” will show up in Android Play Store soon. This application aims to provide a cutting-edge version of InstaMusic. This app could be unstable, lots of force closes, however this helps me kill bugs in the program. For those who only wants a stable music playback, please download the original “InstaMusic”.

As a new version is coming out, I have created a feature list presenting the main improvements done or working on.

  1. Stability
    InstaMusic has been unstable for a long time. Music stops suddenly without telling. After a deep diagnosis, the core reason leading this bug is found, and a fix is patched! Music never stops now!
  2. Loading Speed
    Media loading speed has been a big concern for me while generating the music list. Long loading time affects user experience and might hinder other operations. Anyway, I have designed a new architecture specially for the list generation. This assured an optimised, low memory usage, synchronised and dynamic list generation.
  3. Jelly Bean Support (Working in Progress) 
    There are lots of new features and supports from platforms beginning from Android 4.0 such as notification controls and new theme styles. I am working on making use of those new features and to create a whole new user experience for users!
  4. Editable Playlists integrating with Favourite List (Working in Progress)
    In the next version of InstaMusic, Favorite List will be integrated into Playlist. The reason is… actually there is no reason to separate them lol.

Thank you for your supporting so far. Please comment below and tell me what you think on InstaMusic!

Thank you for checking out this tutorial. Reading the discussions in this post, seems like there is quite a number of people having troubles to take screenshots with Galaxy S2. To clear any confusions, I summarized some information and added as followings. Hope you could make it too. Fingers crossed.

First, make sure your Galaxy S2 is running Android version 4 or above.

Volume Down + Power Key will work fine.
Press both keys at the same time gently. In about 1 second, screen capture would be done. A notification and an animation would be shown too.

Edited on 12 July.

Press and hold power and volume down button together. This is the way to take screenshot in the new Android system 4.0 Ice Cream Sandwich. After the Samsung Galaxy S2 updated to this new version, it uses this method instead of the way mentioned in my old post.

Happy lunar new year to all.

I am flattered. In less than a month since I put the InstaMusic to the Android Market on 27 Dec 2011, today it has already more than 10,000 downloads. To be honest, I never expected this.

If you are uninitialized, InstaMusic is a music player android application with simple and stylish outlook.

There are all kinda music player in the world, in my opinion, a player with style and an pleasant appearance would always become the famous one. Here I would like to thank you for downloading and trying InstaMusic. Especially those fans of minimalism who supported me and AndroidStatic who gave InstaMusic a pleasant review in the post “Instamusic Is A Minimal, Slick Music Player That You Should Download Now“.

Looking back the day that I began my developmement, the reason for me to kick started is that I was really unstatisfied with the music players on the Android Market. Admittedly, I am a perfectionist and I want every part of a music player to meet user’s ways of thinking. So, I hate album artworks to be scratched and unable to tell what album is it. I also hate a song sung by different artists will be will be isolated from the album. And millions of things to list.

Okay, let’s get back to talk about the my next build of InstaMusic. I am sorry for the long waited update. In code level, I really did an upside down on InstaMusic. And as expected, lock screen player is implemented already, but there are just some bug and pressure testing work to do before it can really come out to meet its users.

Caffeine has been a very useful app to instantly disable or enable the screensaver on mac. At least for me, I am using multiple computers in office and all of them except the one I am using will usually get idle. Getting into screensaver, however, is bad sometimes especially I was reading from that screen and type things on another screen, and not to mention the password input after the screen lock. Well anyway, I highly recommend it.


On mac, we can install it easily with the app store.


But in ubuntu, it is not available on the software center. But you can still get it through command line. Turn on terminal and input the following one by one.

sudo add-apt-repository ppa:caffeine-developers/ppa
sudo apt-get update
sudo apt-get install caffeine

%d bloggers like this: