Skip to content

Instantly share code, notes, and snippets.

View cp-shen's full-sized avatar

cp-shen

  • Beijing, China
View GitHub Profile
@cp-shen
cp-shen / Banker_Algo.md
Created January 3, 2018 09:02
simple banker algo in C
#include <stdio.h>

int is_sufficient(const int* cur_avail, const int* cur_req){
    for(int i = 0; i < 3; i++){
        if(cur_avail[i] < cur_req[i]){
            return 0;
        }
    }
    return 1;
@cp-shen
cp-shen / chrome shortcuts
Created December 30, 2017 05:33
chrome shortcuts
chrome:
+t 新 tab
+shit+t 打开最近关闭的 tab
+n 新窗口
+l 地址栏
+o 打开文件
+w 关闭 tab
+r reload
+shift+r force reload
+shift+{ 上一个 tab
@cp-shen
cp-shen / 1
Last active December 23, 2017 04:05
[Java FileWriter 输出 UTF-8 的写法]
原文:http://www.malcolmhardie.com/weblogs/angus/2004/10/23/java-filewriter-xml-and-utf-8/
Java FileWriter 默认是用(ISO-8859-1 or US-ASCII)西方编码的,总之不是UTF-8的,而FileWriter类有getEncoding方法,却没有setEncoding的方法,如下的写法可以使正确输出UTF-8的文件:
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");
或者
Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(this.outputFilename),”UTF-8″));
@cp-shen
cp-shen / 1
Created December 22, 2017 09:20
[Java TreeMap工作原理及实现]
http://yikun.github.io/2015/04/06/Java-TreeMap%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E5%8F%8A%E5%AE%9E%E7%8E%B0/
@cp-shen
cp-shen / 1
Created December 22, 2017 08:57
[how to get the one entry from hashmap without iterating]
https://stackoverflow.com/questions/1509391/how-to-get-the-one-entry-from-hashmap-without-iterating