Archive

Tag Archives: how to

1. Open a terminal window.

2. At the input prompt you will see this structure:
“`
nicholas@computer-name:~$ _
“`

3. So you have to edit the hostname file:
“`
sudo nano /etc/hostname
“`

4. When prompted, enter the administrator password and hit Enter.

5. The hostname file will open, showing the current computer name. Replace the name with the desired new name.

6. Hit Ctrl+X to save and exit.

7. New name will show when you open a new terminal window.

Question

Given a number, find the number of 1 in the number’s binary expression. For example, binary express of 10 is 1010. So the number of 1 in it is 2.

Solution

To solve this, we can check each bit by shifting the bits one by one.

1. 1010 -> check 0
2. 101 -> check 1
3. 10 -> check 0
4. 1 -> check 1

So how to check it? we could use the AND function.

1. 1010 -> check 1010 & 1 = 0
2. 101 -> check 101 & 1 = 1 -> counter + 1
3. 10 -> check 10 & 1 = 0
4. 1 -> check 1 & 1 = 1 -> counter + 1

However, negative number will put this program into infinite loop. For example, shifting -10 (0xFFFFFFF6) several times gives 0xFFFFFFFF. Then shifting 0xFFFFFFFF will give 0xFFFFFFFF and makes infinite loops. Therefore instead of shifting the inputting number, we should shift the comparing number.

1. 1010 -> check 1010 & 1 = 0
2. 1010-> check 1010 & 10 = 1 -> counter + 1
3. 1010 -> check 1010 & 100 = 0
4. 1010 -> check 1010 & 1000 = 1 -> counter + 1

Sample

To capture screen in BlackBerry PlayBook, just hold the volume Up and Down buttons together. After a camera shutter sound, a screen image in the format JPG will be saved in Pictures Camera folder.

blackberry-playbook

This is a very old draft stuck at the bottom of my draft list. lol

var str = "hello world";
str = str.toLowerCase().replace(/b[a-z]/g, function(letter) {
    return letter.toUpperCase();
});
alert(str); //Displays "Hello World"

Making it as a function, we can do this.

function capitalize(str) {
    return str.toLowerCase().replace(/b[a-z]/g, function(letter) {
        return letter.toUpperCase();
    });
}

While you are making a cube in unity which is transparent in gameplay, you would probably want to make it visible only in editor mode with gizmos. However, gizmos doesn’t rotate with the object transform. So you can use the following tricks to rotate the gizmos to fit your object. The code shown is to draw a cube which is totally the same as your object. By setting up the matrix of gizmos, we can transform gizmos to the local position, scale and rotation.

Gizmos.color = Color.green;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero,Vector3.one);

While using hit, it is really usual to have regrets on the commits done, especially the name used. In order to change those information in your repository, open terminal (or cmd in windows), go to the folder of your git repositoy, and run the following commands. Remember, replace “old_name”, “new_name” and “new@email.address” with your own information.

git filter-branch --commit-filter '
  if [ "$GIT_COMMITTER_NAME" = "old_name" ];
  then
    GIT_COMMITTER_NAME="new_name";
    GIT_AUTHOR_NAME="new_name";
    GIT_COMMITTER_EMAIL="new@email.address";
    GIT_AUTHOR_EMAIL="new@email.address";
    git commit-tree "$@";
  else
    git commit-tree "$@";
  fi' HEAD

To merge 2 entirely unrelated branches or projects, we need to specify 0 as first revision in revision range. Turn on terminal (in Mac) or cmd (in Windows) and get to your project folder. Merge with the following shell script. merge -r0..-1 means to merge from revision 0 to the latest revision.

bzr merge [other_branch_location] -r0..-1
%d bloggers like this: