OhMyZsh Configuration

Install zsh

sudo apt-get install zsh

Install ohmyzsh

sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Install autojump

sudo apt-get install autojump

Enable Plugins

Modify .zshrc
plugins=(git ssh-agent autojump jump)

Use Ctrl+Shift to Turn on/off IME for Windows 8/10

Open Control Panel, input the path Control Panel\Clock, Language, and Region\Language\Advanced settings
Click “Change language bar hot key”
“Advanced Key Settings” Tab
“Between Input Language”
“Switch input language”, change the hot key to ctrl + shift.
This is suitable when there is only one IME. Otherwise, use alt+shift to switch language(turn on/off IME).

Sublime Text Good Plugins

  • SideBarEnhancements
  • SyncedSideBar
  • MarkdownEditing
  • Compare Side-By-Side
  • JSON Reindent
  • orgmode
  • Emacs Pro Essentials
  • Prevent Duplicate Windows
  • GotoWindow
  • Open in Relevant Window
  • ConvertToUTF8 (+Codecs33)
  • LLVM (llvm syntax highlighting)
  • TrailingSpaces
  • ActualVim

Fix Hexo Display Errors

Page Button Becomes « __('prev') and __('next') »

Repalce the following content in themes/landscape/layout/_partial/archive.ejs

1
2
3
4
<%- paginator({
prev_text: "&laquo; __('prev')",
next_text: "__('next') &raquo;"
}) %>

with

1
2
3
4
<%- paginator({
prev_text: "&laquo; " + __('prev'),
next_text: __('next') + " &raquo;"
}) %>

The Language Becomes Spanish While the Configuration is English

1
2
3
hexo clean
hexo generate
hexo deploy

ADB Notes

Miscellaneous

1
2
3
4
5
6
7
8
adb reboot
adb reboot download
# uninstall package
adb uninstall com.my.firstapp
# power off
adb reboot -p
# erase user data, then reboot
adb shell recovery --wipe_data

Remove System App

1
2
3
adb root
adb remount
adb shell rm /system/priv-app/GoogleLoginService.apk

Root/Unroot

1
2
adb root
adb unroot

List Package

1
2
3
4
5
6
7
8
9
10
11
adb shell pm list packages
# list the package names as well as the path to the installed APK files
adb shell pm list packages -f
# list only the system packages
adb shell pm list packages -s
# list only 3rd party (or non-system) packages
adb shell pm list packages -3
# list all the disabled package names
adb shell pm list packages -d
# list all the enabled package names
adb shell pm list packages -e

Simulate Keyboard Input

1
2
3
adb shell input keyevent <event_code>
adb shell input text <string>
# KEYCODE_ENTER 66

UID Lookup

1
2
3
4
5
6
7
# package_name to uid
adb shell dumpsys package <package_name> |grep userId

# uid to package_name
adb shell dumpsys package | grep -A1 'userId=<uid>'
# or
adb shell cat /data/system/packages.list | grep <uid>

References

Android: ADB – List Installed Package Names
KeyEvent

Cannot Open File in Assets Error

The following error happens when trying to open a file in assets.
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

There is a limitations on opening compressed files in the assets folder. This is because uncompressed files can be directly memory mapped into the processes virtual address space, therefore avoiding needing the same amount of memory again for decompression.

Fix

  1. Change the file extension. aapt by default will not compress files with such extensions.

    1
    2
    3
    4
    5
    6
    ".jpg", ".jpeg", ".png", ".gif",
    ".wav", ".mp2", ".mp3", ".ogg", ".aac",
    ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
    ".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
    ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
    ".amr", ".awb", ".wma", ".wmv"
  2. Alternatively, you can disable compression for a specific extension. Add the configuration to build.gradle (Module: app)

    1
    2
    3
    4
    5
    android {
    aaptOptions {
    noCompress "pdf"
    }
    }

References

java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

Generate Public/Private Key Pairs

Become a Certificate Authority (CA)

1
2
3
4
5
$ cp /usr/lib/ssl/openssl.cnf ./
$ mkdir -p ./demoCA/certs ./demoCA/crl ./demoCA/newcerts
$ touch ./demoCA/index.txt
$ echo "1000" > ./demoCA/serial
$ openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf

Open openssl.cnf and change “policy = policy_match” to “policy = policy_anything”

Create a Certificate

1
2
3
4
5
6
7
8
$ # Generate public/private key pair
$ openssl genrsa -aes128 -out server.key 1024
$ # show content
$ openssl rsa -in server.key -text
$ # Generate a Certificate Signing Request (CSR)
$ openssl req -new -key server.key -out server.csr -config openssl.cnf
$ # Generating Certificates
$ openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

Create Digital Signature

1
2
3
4
5
6
7
8
$ # prepare the file to sign
$ echo "Hello, world!" > in.txt
$ # extract public key
$ openssl rsa -in server.key -pubout > server.pub
$ # generate signature with private key
$ openssl dgst -sha256 -sign server.key -out in.txt.sha256 in.txt
$ # verify the signature with public key
$ openssl dgst -sha256 -verify server.pub -signature in.txt.sha256 in.txt

References

Crypto Lab – Public-Key Cryptography and PKI

Using Android KeyChain

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
44
45
46
47
48
49
50
51
52
/**
* This method will launch an intent to install the key chain
*/
public static final String PKCS12_FILENAME = "keychain.p12";
private static final String DEFAULT_ALIAS = "My Key Chain";
private static final int INSTALL_KEYCHAIN_CODE = 1;
private void installPkcs12() {
try {
// prepare a PKCS12 format file with filename *.p12 or *.pfx
BufferedInputStream bis = new BufferedInputStream(getAssets().open(
PKCS12_FILENAME));
byte[] keychain = new byte[bis.available()];
bis.read(keychain);

Intent installIntent = KeyChain.createInstallIntent();
installIntent.putExtra(KeyChain.EXTRA_PKCS12, keychain);
installIntent.putExtra(KeyChain.EXTRA_NAME, DEFAULT_ALIAS);
startActivityForResult(installIntent, INSTALL_KEYCHAIN_CODE);
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == INSTALL_KEYCHAIN_CODE) {
switch (resultCode) {
case Activity.RESULT_OK:
chooseCert();
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
}

private void chooseCert() {
KeyChain.choosePrivateKeyAlias(this, this, // Callback
new String[] {}, // Any key types.
null, // Any issuers.
"localhost", // Any host
-1, // Any port
DEFAULT_ALIAS);
}

/**
* This implements the KeyChainAliasCallback
*/
@Override
public void alias(String alias) {
// callback to get the alias set by the user
}

References

Android SDK KeyChainDemo
Android KeyChain