Posts by Chang Park

Useful Git tips


Apply .gitignore on already pushed repository

$ git rm -r --cached .
$ git add .
$ git commit -m '.gitignore applied'

Disconnect local repository from remote

$ git remote rm origin


vi Find & Replace





  • [%]
    • All lines in the file.
  • [1,30]
    • line 1 to 30
  • [5,$]
    • line 5 to last line


  • This can be plain text and also regular expression. Combining regular expression and this command, replacing words in vi, will be powerful.
  • \<pattern\>
    • This will get the exact match, not all contained word.
This is his bag

: %s/his/her/g
=> Ther is her bag

Above command changes This also because it contains “his”.

This is his bag

: %s/\<his\>/her/g
=> This is her bag



  • [C]
    • Confirm each substitution
  • [g]
    • Replace all occurrence in the line
    • If you don’t put, default is just replacing first occurrence.
  • [i]
    • Ignore case for the pattern


  • Do substitution in N lines from the current position of the cursor
 :s/hi/hello/g 4 

This means change all hi to hello in 4 lines from current line.


malloc( ) and free( )


malloc() and free()

  • allocates the requested memory and returns a pointer to it. (Dynamic memory allocation)
  • should #include<stdlib.h>
  • void *malloc(# of bytes): the function returns address of the memory.
  • void free(current_storage_pointer): de-allocate it to prevent memory leakage.




int main(){
   int *p;
   p =(int *) malloc(sizeof(int));
      puts("Failed to allocate memory!");
      *p = 20;

Example (Array)

int main(){
   int size;
   printf("Enter the size of the array: ");
   scanf("%d", &size);
   int *a;
   a = (int *)malloc(size * sizeof(int));
   printf("\nEnter the values of the array: ");
   int i;
   for(i = 0; i < size; i++){
      scanf("%d", &a[i]);
   printf("\nThe values in the array are: \n");
   for(i = 0; i < size; i++){
      printf("%d\t", a[i]);




  • most popular custom ROM for Android devices
  • Android Mobile Operating system-based Open Source Firmware for smartphones and tablet devices.

Why you should install CyanogenMod

  1. CyanogenMod provides you with an up-to-date version of Android. It’s also a pure, stock Android experience. If it supports your device, it will provide you with a pure, up-to-date Android experience. It’s a way to revitalize old Android devices that manufacturers are no longer updating.
  2. Privacy Guard lets you control which permissions installed apps can use, and which permissions new apps will get by default. This gives you an iOS-style permission experience on Android, so you can decide whether that app should be allowed to access your location, contacts, and other private data while still using the app.
  3. The Superuser screen integrates root permissions into Android’s Settings screen. This interface functions as a traditional way to allow and disallow superuser requests from apps, but it also allows you to enable root or disable it for your entire device.screen-shot-2016-10-02-at-6-45-38-pm
  4. The Themes panel allows you to install and choose theme packs, styles, icons, fonts, sound packs, and even boot animations to customize your device.screen-shot-2016-10-02-at-6-45-20-pm
  5. The Interface settings screen is packed with options. You can tweak the status bar, quick settings panel, notification drawer, and navigation bar. For example, you could reorder the buttons on the navigation bar at the bottom of your screen, or rearrange the order of the tiles in the quick settings panel.
  6. The DSP Manager app provides system-wide equalizer controls you can use to adjust the sound coming from your device, enabling bass boost, activating an equalizer, and selecting presets that match the music you listen to.
  7. Use the Buttons screen to control what your device’s buttons do. For example, you could long-press the volume buttons to switch music tracks. This is a great solution for skipping between songs without pulling your phone out of your pocket if you don’t have a headphone cable with an integrated remote.
  8. CyanogenMod includes profiles, which you can find under Settings > Profiles or by long-pressing the power button and tapping the Profile option. Profiles are groups of settings.



  • Read Only Memory. It usually describes a piece of hardware, a memory chip that you normally can’t write to. Device manufacturers will typically use ROM to store the OS to help ensure the devices maintains a known state and is thus more reliable and easier to support.
  • pre-packaged OS with certain features added or removed, compared to the stock OS

os.system() vs.



  • executed in a subshell, usually bash on linux and OSX, and cmd.exe on windows.
  • The shell will take the string given and interpret the escape characters.
    • ex)  os.system(“python –version”)

  • default does not use a shell – it simply tries to run an executable with a name given by string a. You actually can’t pass any arguments in the string a – only the literal name of the executable.
  • To run a command with arguments, I need to give this to as a list
    • ex)[“python”, “–version”]) can be used same as os.system() by setting shell to true.

  • ex)“python –version”, shell=True)

Hard Link vs. Soft Link


Hard Link

Hard links are just different names for the same file.

  • One file can have many different names or hard links.
  • Both original file and link file have same Inode number(Index Number).
  • If one is modified, the other one is also modified automatically.
  • Both files’ link number increases to 2.
  • Even though original is deleted, link file works properly.
  • Form: ln originalFile linkFile

Screen Shot 2016-08-24 at 10

Soft Link (Symbolic Link)

Soft links are similar to MS windows shortcut.

  • One file can have many shortcuts pointing to it.
  • Original file and link file have Different Inode number(Index Number).
  • If one is modified, the other one is also modified automatically.
  • Link number doesn’t change.
  • If original is deleted, link file doesn’t work.
  • Form: ln -s originalFile linkFile

Screen Shot 2016-08-24 at 11


Linux Hierarchy Structure


/ (Root directory)

The Root Directory is the starting point of the file system hierarchy. Everything in the system, including the other directories and files of the system, are stored in the root directory.

Screen Shot 2016-08-24 at 4.37.12 PM


The /bin directory contains the binaries and other executable programs. Most of the common Linux commands that you may utilize as a user of the system are stored here. Similar to the /bin directory is the /sbin directory, which contains the essential system administration binaries.

Screen Shot 2016-08-24 at 4.38.26 PM


The /boot directory contains the static boot loader files needed to boot the operating system. It contains the GRUB boot loader files along with the Linux kernels.

Screen Shot 2016-08-24 at 4.41.05 PM


The /dev directory contains device files which are typically under the control of the operating system and the system administrators. The terminal devices, disk drives, USB’s etc. are all included in the /dev directory and are exposed as files in Linux, instead of being represented as devices.

Screen Shot 2016-08-24 at 4.43.09 PM


The /etc directory contains the system configuration files. All files in the /etc directory should be text files and cannot be executable binary files. It contains the /etc/passwd and the /etc/shadow files which contain essential user identification and authentication data.

Screen Shot 2016-08-24 at 4.45.05 PM


The /home directory contains a home directory for each user. Each user’s personal files and user-specific configuration files are stored in their respective home directories. Each user has write access only to their own home directory. One can not modify the files in the home directory of the other user unless they have acquired the permissions to do so.

Screen Shot 2016-08-24 at 4.46.00 PM


The /lib directory contains the essential system libraries and kernel modules which would be required by the binaries located under the /bin or /sbin directories. Similarly, the /lib64 directory contains libraries required for 64-bit support in systems.

Screen Shot 2016-08-24 at 4.46.32 PM


The /media directory is used to temporary mount removable media like external hard disks, CD-ROM’s etc. Once you attach a removable media to a system, a subdirectory will automatically be created inside the /media directory. You shall be able to access the contents of the device from that subdirectory.

Screen Shot 2016-08-24 at 4.47.45 PM


The /opt directory contains sub-directories for optional or third-party software. Most proprietary software keep their files here in the /opt directory.

Screen Shot 2016-08-24 at 4.48.41 PM


The /proc directory contains information about the processes running on your system in directories named /proc/PID where PID is the process id. It also contains information about system resources.

Screen Shot 2016-08-24 at 4.49.35 PM


The /tmp directory is used by the system and its applications to store their temporary files. All these files are typically cleared on system reboot.

Screen Shot 2016-08-24 at 4.50.19 PM


The /usr directory is used to contain the applications and file pertaining to a particular user as compared to the files and applications of the system. For example, the essential binaries and essential system administration binaries are stored in the /bin & /sbin directories while the non-essential ones are stored in /usr/bin & /usr/sbin directories respectively.

Screen Shot 2016-08-24 at 4.50.58 PM


The /var directory is an important part of the Linux Directory Structure & contains variable system files whose data that may grow over time. Log files, packages and database files can be found in the /var directory.

Screen Shot 2016-08-24 at 4.51.36 PM



Serialization #2



JavaBeans are classes that encapsulate many objects into a single object (the bean), and  they are serializable.

  • It provides a default, no-argument constructor.
  • It should be serializable and implement the Serializable interface.
  • It may have a number of properties which can be read or written.
  • It may have a number of “getter” and “setter” methods for the properties.


package com.chang;

public class StudentsBean implements Serializable{
   private String firstName = null;
   private String lastName = null;
   private int age = 0;

   public StudentsBean(){

   public String getFirstName(){
      return firstName;

   public String getLastName(){
      return lastName;

   public int getAge(){
      return age;

   public void setFirstName(String firstName){
      this.firstName = firstName;
   public void setLastName(String lastName){
      this.lastName = lastName;

   public void setAge(Integer age){
      this.age = age;

Serialization #1


Serialization is a process in which current state of Object will be saved in stream of bytes. As byte stream create is platform neutral hence once objects created in one system can be deserialized in other platform.

This Byte stream can be used for different purpose.

  • Write to Disk
  • Store in Memory
  • Sent byte stream to other platform over network
  • Save byte stream in DB(As BLOB)

Java has already provided out of the box way(  Interface) to serialize an Object. If you want any class to be serialized then that class needs to implement this interface.

* Serializable interface is just a marker interface. There is no methods in it.


Example. Serializable Class

The serialVersionUID is used as a version control in a Serializable class. If you do not explicitly declare a serialVersionUID, JVM will do it for you automatically, based on various aspects of your Serializable class.

package com.chang;

public class Employee implements Serializable{
   public String firstName;
   public String lastName;

   // serialVersionUID
   private static final long serialVersionUID=1L;

Serializable class usually makes files variables as private and interact with them using setter and getter.

Example. Serialization Class

package com.chang;

public class SerializationClass{
   public static void main(String[] args){
      Employee emp = new Employee();
      emp.firstName = "Chang";
      emp.lastName = "Park";

         FileOutputStream fileOut = new FileOutputStream("./employee.txt");
         ObjectOutputStream out = new ObjectOutputStream(fileOut);
         System.out.println("Serialized data is saved in  ./employee.txt file");
      } catch (IOException i){

Example. Deserialization Class

package com.chang;

public class DeserializationClass{

   public static void main(String[] args){
      Employee emp = null;
         FileInputStream fileIn = new FileInputStream("./employee.txt");
         ObjectInputStream in = new ObjectInputStream(fileIn);
         emp = (Employee) in.readObject();
      } catch (IOException i){
      } catch (ClassNotFoundException c){
         System.out.println("Employee class not found");
      System.out.println("First Name of Employee: " + emp.firstName);
      System.out.println("Last Name of Employee: " + emp.lastName);




A chmod is used to change permission of files and directories.

  • form:     chmod  [options]  permissions  filename


can be represented in two ways.

  • Alphabetic combination
  • Numeric combination


Alphabetic combination

  • User
    • a: All people
    • u: owner
    • g: group
    • o: others
  • Permission
    • r: read
    • w: write
    • x: execute
  • Example:
    • chmod u=rwx practice.txt : Owner gets all permissions on practice.txt.
    • chmod g-w practice.txt : Group’s write permission on practice.txt is removed.
    • chmod o+rx practice.txt : Others get additional read and execute permissions.
    • chmod a=rwx practice.txt : All people get all permissions.


Numeric Combination


  • Permission
    • 4: read
    • 2: write
    • 1: execute
  • Example:
    • chmod 755 practice.txt : owner gets all permission. Group and others get read and execute permission.
    • chmod 777 practice.txt : All people get all the permissions.



Screen Shot 2016-08-22 at 2.12.06 PM