Skip to content

Instantly share code, notes, and snippets.

View ztlevi's full-sized avatar
🎯
Focusing

Ting Zhou ztlevi

🎯
Focusing
View GitHub Profile
static public List<Integer> common_divisor(int n) {
List<Integer> result = new ArrayList();
for (int i=2; i<=Math.sqrt(n); i++)
{
// if 'i' is factor of n
if (n%i==0)
{
// check if divisors are equal
if (n/i == i)
result.add(i);
@ztlevi
ztlevi / euclid.java
Last active September 30, 2017 01:32
Euclid
// recursive implementation
public static int gcd(int p, int q) {
if (q == 0) return p;
else return gcd(q, p % q);
}
// non-recursive implementation
public static int gcd2(int p, int q) {
while (q != 0) {
int temp = q;
@ztlevi
ztlevi / dp_pre_set.py
Last active September 30, 2017 01:14
level = {-1:0}
level[l] = level[l-1] + len(lentry) + 1
// an example to create a new mapping `ctrl-y`
mapkey('<Ctrl-y>', 'Show me the money', function() {
Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).');
});
// an example to replace `u` with `?`, click `Default mappings` to see how `u` works.
map('?', 'u');
map('u', 'e');
@ztlevi
ztlevi / cvim
Last active September 15, 2017 02:42
cvim
" Emacs Keybindings
imap <C-n> forwardLine
imap <C-p> backwardLine
imap <C-f> forwardChar
imap <C-b> backwardChar
imap <M-f> forwardWord
imap <M-b> backwardWord
imap <C-a> beginningOfLine
imap <C-e> endOfLine
imap <C-k> deleteToEnd
@ztlevi
ztlevi / 0_reuse_code.js
Created May 9, 2017 05:01
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
[ 19.349]
X.Org X Server 1.19.3
Release Date: 2017-03-15
[ 19.349] X Protocol Version 11, Revision 0
[ 19.349] Build Operating System: Linux 4.9.11-1-ARCH x86_64
[ 19.349] Current Operating System: Linux ZT-alienware 4.9.25-1-lts #1 SMP Thu Apr 27 16:42:36 CEST 2017 x86_64
[ 19.349] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux-lts root=UUID=38cca7ab-2d9e-4503-87fd-d8f1ea4e02ce rw quiet resume=UUID=a365d2e5-57af-472d-b39e-e52da5e88de4
[ 19.349] Build Date: 07 April 2017 05:42:48PM
[ 19.349]
[ 19.349] Current version of pixman: 0.34.0