Problem: Insufficient permission for adding an object to repository database

Solution:
git config core.sharedRepository group

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

Reference:
https://stackoverflow.com/questions/6448242/git-push-error-insufficient-permission-for-adding-an-object-to-repository-datab

Stop /var/log/cron to be rotated

1. vim /etc/logrotate.d/syslog
2. Comment the line /var/log/cron

Set shortcut to create new file in finder

1. Open Automator and create a Service;
2. Set the input to no input, and the application to Finder.app;
3. Drag and Drop the Run AppleScript workflow element onto the grey space;
4. Put the contents of this AppleScript in the textbox;
5. Save the workflow with a reasonable name (like New File);
6. Go to Settings -> Keyboard -> Shortcuts -> Services and assign a shortcut to it.

set file_name to "untitled"
set file_ext to ".txt"
set is_desktop to false

-- get folder path and if we are in desktop (no folder opened)
try
    tell application "Finder"
        set this_folder to (folder of the front Finder window) as alias
    end tell
on error
    -- no open folder windows
    set this_folder to path to desktop folder as alias
    set is_desktop to true
end try

-- get the new file name (do not override an already existing file)
tell application "System Events"
    set file_list to get the name of every disk item of this_folder
end tell
set new_file to file_name & file_ext
set x to 1
repeat
    if new_file is in file_list then
        set new_file to file_name & " " & x & file_ext
        set x to x + 1
    else
        exit repeat
    end if
end repeat

-- create and select the new file
tell application "Finder"

    activate
    set the_file to make new file at folder this_folder with properties {name:new_file}
    if is_desktop is false then
        reveal the_file
    else
        select window of desktop
        set selection to the_file
        delay 0.1
    end if
end tell

-- press enter (rename)
tell application "System Events"
    tell process "Finder"
        keystroke return
    end tell
end tell

Reference: https://apple.stackexchange.com/questions/129699/create-a-new-txt-file-in-finder-keyboard-shortcut

Unlock Windows Account

Net user loginid /ACTIVE:YES /domain

Change wget Timeout

wget -t 1 --timeout=900 xxxxx

Reference:
https://stackoverflow.com/questions/2291524/does-wget-timeout

Read Chinese in vim

:set encoding=utf-8

Linux Users Management

Show user list
cat /etc/passwd

Show user's group
id USER_NAME

Add user
adduser USER_NAME

Add group
groupadd GROUP_NAME

Assign user to a primary group (Require re-login to apply the new group)
usermod -g GROUP_NAME USER_NAME

Assign user to a secondary group
usermod -a -G GROUP_NAME USER_NAME

Turn on setgid bit (all new files and subdirectories created within the current directory inherit the group ID of the directory, rather than the primary group ID of the user who created the file)
chmod g+s .

Turn off setgid bit
chmod g-s .

Check if setgid is on
ls .
(If it is on, the group permission will become rws instead of rwx)

Install Phantom on CentOS

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar xvf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin

Reference:
http://sameerhalai.com/blog/how-to-install-phantomjs-on-a-centos-server/

GoAccess Usage

Installation
https://goaccess.io/download

Config File
sudo vim /usr/local/etc/goaccess.conf
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h [%d:%t %^] \"%r\" %>s %b %D %T \"%{Referer}i\" \"%{User-Agent}i\"

Generate HTML Report
goaccess -f /.../logs/access.log > /.../reports.html

Change Apache Log Format

vim /etc/httpd/conf/extra/httpd-vhosts.conf
CustomLog "...../logs/access.log" vhost_combined
LogFormat "%h %t \"%r\" %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

Reference:
https://blog.elijaa.org/2010/09/07/how-to-make-apache-log-real-scriptname-and-execution-time-with-mod_rewrite-and-logformat/

Flag Counter