Use ISO as Apt Repository

1
2
3
4
5
6
7
8
9
ISO_PATH="~/ubuntu_18_04.iso"
UBUNTU_CODE="bionic"

sudo mkdir /media/apt
sudo mount ${ISO_PATH} /media/apt -o loop
sudo echo "deb file:/media/apt/ ${UBUNTU_CODE} main contrib" >> /etc/apt/sources.list

sudo apt-get -o Acquire::AllowInsecureRepositories=true update
# sudo apt-get -o Acquire::AllowInsecureRepositories=true install bcmwl-kernel-source

Reference

How to use a .iso image as a CD-ROM Repository?
How do I bypass/ignore the gpg signature checks of apt?

Assign Static IP for VMware Fusion

1
sudo vi /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

Add the follwing settings outside the “DO NOT MODIFY SECTION”.
Be careful:

  • the “LinuxMint” must match the name of the virtual machine and contain no space.
  • the MAC address must match the MAC address of the net card
  • the fixed-address should be outside the range in the “DO NOT MODIFY SECTION”, e.g. 172.16.214.100 (range 172.16.214.128 172.16.214.254)
1
2
3
4
host LinuxMint {
hardware ethernet 00:0C:29:B6:22:3E;
fixed-address 172.16.214.100;
}

Shutdown the virtual machine and execute the following commands

1
2
sudo /Applications/VMware\ Fusion.app/Contents/Library/services/services.sh --stop
sudo /Applications/VMware\ Fusion.app/Contents/Library/services/services.sh --start

Reference

Set a Static IP Address in VMware Fusion 7

tmux with mosh

  • Terminal emulator supporting OSC52
    • iTerm2, Preference -> General -> Applications in terminal may access clipboard
    • mlterm, –osc52=true
  • latest mosh from git (tagged releases are too old, both client and server)
  • latest tmux
  • Override the OSC 52 sequence generated by tmux by adding the following line to your tmux.conf
    • set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p2%s\\7"

Reference

tmux + mosh OSC 52 clipboard paste hack
tmux in practice: integration with the system clipboard

Git Rebase

1
2
3
4
5
6
7
8
# git pull is always equivalent to git pull --rebase (unless branch.<branchname>.rebase is explicitly set to false)
git config --global pull.rebase true

# Force existing branches to use rebase.
git config branch.<branchname>.rebase true

# Force new branches to use rebase
git config --global branch.autosetuprebase always

Count Lines of Code

1
2
3
4
5
# count lines of code in current directory
grep -c -e "$" -r -h . | python -c "import sys; a = sys.stdin.read().strip().split(); a = [int(x) for x in a]; print(sum(a));"

NAME_PATTERN="*.cc"
find . -type f -name "${NAME_PATTERN}" -print0 |xargs -0 -n1 grep -c -e "$" | python -c "import sys; a = sys.stdin.read().strip().split(); a = [int(x) for x in a]; print(sum(a));"

jQuerify

1
2
3
4
5
6
7
8
9
if (typeof $.fn != 'undefined' && typeof $.fn.jquery != 'undefined') {
console.log("jquery " + $.fn.jquery + " already exist");
} else {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'https://code.jquery.com/jquery-3.3.1.min.js');
document.body.appendChild(script);
console.log("jquerfied");
}

Matlab/Octave Notes

Operators

1
2
eq, ==
ne, ~=

Matrix index

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
a = [1;2;3];
% index starts from 1, including 2, i.e. [1;2]
a(1:2);

b = [1,3,7;
2,5,8;
3,6,9];

% true
b(1) == 1;
b(2) == 2;
b(9) == 9;

% 1 3 7
b(1,:)

% 1
% 2
% 3
% 4
% 5
% 6
% 7
% 8
% 9
b(:)

% unroll
% c = [ 1
% 2
% 3
% 1
% 2
% 3
% 4
% 5
% 6
% 7
% 8
% 9 ]
c = [a(:); b(:)]

b = reshape(c(4:12), 3, 3);

References

Matlab Language Fundamentals
GNU Octave Doc