Docker Cheatsheet

Container vs Image Image is immutable, container is a box running starting from an image. docker ps -as # list all containers with sizes docker images # list all images docker run [options] <image> # best to use image id or image:tag # -p hostPort:containerPort expose port, -P publish all exposed ports. 8888 for jupyter notebook # -t terminal pseudo-TTY # -i Keep STDIN open even if not attached # -v /host/dir:/<container-path> # –name Assign a name to the container docker start -ai <container> # can user container id or name # -a Attach STDOUT/STDERR and forward signals # -i Attach container’s STDIN jupyter notebook –ip 0.


Internet FAQ

Internet Protocol (IP) IPV4 vs IPv6 IPV4 uses 32 bits, 4 8 bit numbers, 2^32 distinct IP addresses. Example 202.2.1.10. IPV6 uses 128 bits, 8 16 bit numbers, 2^128 distinct IP addresses. Actual number is slightly smaller since multiple ranges are reserved for special use or completely excluded from use. Example 3ffe:1900:4545:3:200:f8ff:fe21:67cf. Refs: webopedia article IPV6 wikipedia


Mac Cheatsheet

Keboard Shortcuts Switching tabs: Safari, [shift]+ctrl+tab, cmd+number, shift+cmd+left/right. Chrome, [shift]+ctrl+tab, cmd+number, alt+cmd+left/right. macvim, shift+cmd+{/}. Editing: Delete to end of line, ctrl+k, same as on command line Delete to beginning of line, cmd+shift+left, then delete


Algorithm Question Substring Search KMP

Question LeetCode has this question Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Tags: Two Pointers, String. Let’s denote haystack length N, needle length M, character table size R (256 for extended ASCII). Java’s String class method indexOf() uses brute force algorithm O(MN). Examples: haystacsflksdjflkshhaystackneeneeneedle needle naslkfjskjlhhhh needle Method 1 2D DFA KMP Knuth Morris Pratt O(N) time complexity.


Sorting Algorithm Summary

The following table summarizes common characteristics of popular sorting algorithms, not including string sort algorithms (I may add those later here or write another separate post). algorithm In Place? Stable? parallel? worst average best remarks selection y n n N2/2 N2/2 N2/2 N exchanges insertion y y n N2/2 N2/4 N use for small N or partially ordered shell y n n ?


Git Cheatsheet

Basic Snapshotting git-mv - Move or rename a file, a directory, or a symlink git mv [-v] [-f] [-n] [-k] <source> <destination> rename git mv [-v] [-f] [-n] [-k] <source> … <destination directory> move into existing directory git mv <source> <destination> # rename a directory Branch Related git branch [options] <branchname> git branch # show all branches with current marked with * git branch -vv # show all local and tracked remote branches git checkout dev git branch jesse # creates branch named "jesse" off from "dev" branch git checkout -b jesse # creates and switch to branch "jesse" Merge git merge [options] [<commit>.


Virtualbox Tips for Ubuntu Guest in Windows Host

For Ubuntu tips, see http://jessezhuang.github.io/ article/ubuntu/. How to Get Shared Folder Write Access When used as a virtual machine guest (Ubuntu 14.04LTS in Windows 10 host with Oracle VirtualBox), to get access to shared folder, run the following command in shell, replace username with your ubuntu username.

replace username with your actual ubuntu username $ sudo usermod -a -G vboxsf username After that, reboot the VM and you should have write access to the shared folder.


Vim Cheatsheet

For Ubuntu Linux, Terms: C-x stands for ctrl-x. Generally, use :help <cmd>" for quick ref, e.g.:help undo`. Configuration Configuration file default ~/.vimrc. Can use source <another file> and put the actual vimrc in cloud like dropbox.

to reload an edited vimrc :so $MYVIMRC File operations # to rename a file :E or :Explorer :Te or :Texplorer to open explorer in new tab then :bd to close the new tab R # rename at bottom :bp # go back previous buffer # save the current session including buffers, tabs, and settings :mksession ~/vimSessions/session1.


How to Install Latest Version Vim in Ubuntu 14.04 LTS

Ubuntu comes with Vim-Tiny First of all, Ubuntu 14.04 LTS comes with Vim.Tiny with the version 2:7.4.052-1ubuntu3 which is Vim 7.4.052, already fairly new. Unfortunately I was looking specifically for markdown editing and syntax highlighting and I found that starting from 7.4.480 vim can pick up *.md files as markdown files by default. So I wanted to find a newer version of Vim to install. Install Vim with PPA I have tried to install Vim with debian packages listed on Vim.


Mongodb Tutorial 6 - Application Engineering

Durability of Writes Write Concern How to make sure the writes persistent? Assume application talking to a database server in the scheme below. The settings of two parameters affect the write concern: w(wait for acknowledgement) j(journal) effect comment 1 false fast, small window of vulnerability default setting 1 true slow, no vulnerability can be done inside driver at collection, database, or client level 0 - unacknowledged write do not recommend 2 - wait for 2 nodes in replica set to acknowledge write w can be 0-3 for a set with 3 nodes majority - wait for majority to acknowledge, avoid rollback on failover - tag values - set tags on nodes - If the journal has been written to disk and the server crashes, on recovery the server can look in the journal and recreate all the writes that were not yet persisted to the pages.


Mongodb Tutorial 1 - Introduction

To run mongo commands from the source of a JavaScript file, cat source.js | mongo # or mongo < source.js # or just mongo source.js To import/export data, $ mongoimport -d <database> -c <collection> -f <file> $ mongoimport -d <dababase> -c <collection> < file.json $ mongoexport -d <dababase> -c <collection> –out file.json $ mongorestore -d <database> -c <collection> file.bson # by default writes BSON file to dump/ in current directory $ mongodump -d <database> -c <collection [–out <path>] What is MongoDB?


MongoDB Tutorial 5 - Aggregation Framework

The aggregation framework has its roots in SQL’s world of groupby clause. Introduction Example used: imagine a SQL table of products. name category manufacture price ipad tablet Apple 499 nexus s cellphone Samsung 350 To get number of products from each manufacture with SQL, select manufacture, count(*) from products group by manufacture; with mongodb, > use agg > db.


Ubuntu Tips and Tricks

Ubuntu version is 14.04 LTS running as a guest OS in Oracle VirtualBox 5. For VirtualBox related issues, see http://jessezhuang.github.io/ article/virtualbox-tips/. Performance Monitoring top from command line System Monitor application installed by default. Screen Capture Application Screenshot installed by default. Can take screenshot of whole screen, current window, or selected area. Similar to “Snipping Tool” in Windows. To run this tool from the shell, use gnome-screeshot -i for interactive window specified with mouse, gnome-screenshot -help for other options.


Linux Cheatsheets

Linux Commands Cheatsheet Files Related ls - list directory contents SYNOPSIS ls [OPTION]… [FILE]… -a, –all do not ignore entries starting with . examples effects ls -la list all file/directories including hidden in long list form ls -ld list directory only in list form du - estimate file space usage SYNOPSIS du [OPTION]… [FILE]… -c, –total produce a grand total -h, –human-readable print sizes in human readable format (e.


MongoDB Tutorial 4 - Performance

Storage engine Storage engine sits between mongodb server and the file storage. Use db.serverStatus().storageEngine; to check. WiredTiger for many applications, this is faster - document level concurrency, lock free implementation. optimistic concurrency model which assumes two writes not gonna be on same document. if on same, one write unwound and try again. - compression of data and indexes. WiredTiger manages memory. - append only, no in place updates MMAP V1 Uses mmap system call undercovers.


Using Java's Reflection for Testing

Writing Boilerplate Test Code is Boring Repeatedly writing boilerplate for loops for testing is not fun. We can use Java reflection API (java.lang.reflect package) to maximize code reuse and help testing. Frameworks like JUnit uses reflection for testing. I will introduce a single method today on how reflection can be used for testing. The code examples below are available at my github repository. Get an Instance of Class Being Tested First we will declare a message to print out if all tests passed.


A Tutorial for using Hugo and Github Pages as a Blog Site

Hugo, a Static Site Generator Hugo is one of the static site generators. Currently it is ranked 4th by StaticGen. Of the top competitors, Hugo is the only one written in a compiled language (Go), which builds the site much faster. So I decided to give it a spin. Most of them were written in JavaScript. Jekyll was the good old player in this field, which was used in Obama’s campaigns to raise $250M.