Skip to content

Instantly share code, notes, and snippets.

View Foredoomed's full-sized avatar

Foredoomed Foredoomed

  • Shanghai,China
View GitHub Profile
@Foredoomed
Foredoomed / Leiningen.sublime-build
Created November 18, 2012 04:31
Leiningen.sublime-build
# Copy the following and place it a file called Leiningen.sublime-build in the Sublime user packages folder (~/.config/sublime-text-2/Packages/User on Linux).
# Select this as the build system for the project using Tools/Build System/Leiningen.
# You can then bring up the Sublime Command Palette (ctrl+shift+P on Windows/Linux) and issue any of the commands # (build, documentation, clean, run, test, etc). By default, build is bound to ctrl+b and run to ctrl+shift+b.
{
"cmd": ["lein", "compile", ":all"],
"working_dir": "$project_path",
"variants": [
{ "cmd": ["lein", "marg", "-m", "-d", "docs"],
@Foredoomed
Foredoomed / markdown_table
Created October 27, 2012 07:25
Markdown Table
| Sort | Average | Best | Worst | Space | Stability | Remarks |
|----
| Bubble sort | O(n^2) | O(n^2) | O(n^2) | Constant | Stable | Always use a modified bubble sort |
| Modified Bubble sort | O(n^2) | O(n) | O(n^2) | Constant | Stable | Stops after reaching a sorted array |
| Selection Sort | O(n^2) | O(n^2) | O(n^2) | Constant | Stable | Even a perfectly sorted input requires scanning the entire array |
| Insertion Sort | O(n^2) | O(n) | O(n^2) | Constant | Stable | In the best case (already sorted), every insert requires constant time |
| Heap Sort | O(nlog(n)) | O(nlog(n)) | O(nlog(n)) | Constant | Instable | By using input array as storage for the heap, it is possible to achieve constant space |
| Merge Sort | O(nlog(n)) | O(nlog(n)) | O(nlog(n)) | Depends | Stable | On arrays, merge sort requires O(n) space; on linked lists, merge sort requires constant space |
| Quicksort | O(nlog(n)) | O(nlog(n)) | O(n^2) | Constant | Stable | Randomly picking a pivot value (or shuffling the array prior to
@Foredoomed
Foredoomed / System Design.md
Created June 15, 2020 09:14 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@Foredoomed
Foredoomed / gcsettings.sh
Last active May 31, 2019 08:54 — forked from svanoort/gcsettings.sh
Blessed GC settings for big servers
#参考:https://github.com/vipshop/vjtools/blob/master/vjstar/src/main/script/jvm-options/jvm-options.sh
# http://calvin1978.blogcn.com/articles/jvmoption-7.html
# Base settings and GC logging
-server
-XX:+AlwaysPreTouch # First should be default, but we make it explicit, second pre-zeroes memory mapped pages on JVM startup -- improves runtime performance
# -Xloggc:gc-%t.log # CUSTOMIZE LOCATION HERE - $path/gc-%t.log -- the %t in the gc log file path is so we get a new file with each JVM restart
-XX:NumberOfGCLogFiles=5 -XX:+UseGCLogFileRotation -XX:GCLogFileSize=20m # Limits the number of files, logs to folder
-XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCCause

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
http://docs.jboss.org/jbossas/7/plugins/maven/7.4.Final/examples/deployment-example.html
@Foredoomed
Foredoomed / 复习
Last active December 14, 2015 02:08
public class LockTest {
private static final String fileName = "C:/work/LockExample.txt";
private static final String EXIT_FLAG = "BYE";
private static final int NO_OF_LINES = 10;
private static final Lock fileLock = new ReentrantLock();
private static final Condition condition = fileLock.newCondition();
private static final ExecutorService executorPool = Executors.newFixedThreadPool(2);
public static void main(String[] args) {
美国著名图书频道Book Pool集结最权威的62位作者评选出了最近10年计算机专业图书:
1.Design Patterns: Elements of Reusable Object-Oriented Software
By Erich Gamma, et al
2.The Mythical Man-Month: Anniversary Edition
By Frederick P. Brooks Jr.
3.TCP/IP Illustrated, Volume 1: The Protocols
By W. Richard Stevens
方滨兴 230103196007175511