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 / 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
@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
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 / 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 / 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;

Modern Linux desktop environments (Gnome 3, Ubuntu Unity, Docky) use the WMClass property to associate windows with the owning application. Many Java-based applications have the problem where the windows created by the application are not associated with the shortcut used to start the application (so the dock contains multiple copies of the same icon).

So the field called StartupWMClass is a string that defines in which class the application is grouped in the Unity Launcher at startup.

You can find out which WM_CLASS your window has got when you type in a terminal:

xprop WM_CLASS and then click at the window. In case of the gnome terminal the output is as follows:

WM_CLASS(STRING) = "gnome-terminal", "Gnome-terminal"

@cp-shen
cp-shen / swapkey.ps1
Created June 14, 2019 08:33
Swap Control and Caps Lock on Windows
# https://www.mavjs.org/post/swap-ctrl-and-capslock-on-windows/
$hexified = "00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00".Split(",") | % { "0x$_"};
$kbLayout = 'HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout';
New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified)
@cp-shen
cp-shen / check_file_exists.zsh
Created November 19, 2019 12:30 — forked from fhuitelec/check_file_exists.zsh
[Check file exists] Cheatsheet to check if file exists #zsh #shell #cheatsheet
#!/usr/bin/env zsh
#
# Check file exists
#
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!" >&2
exit 1
fi
@cp-shen
cp-shen / gist.md
Created January 6, 2020 04:14 — forked from honza/gist.md
Clojure vs Haskell

Haskell vs Clojure

The JSON data is in the following format

{
    "Genesis": {
        "1": {
            "1": "In the beginning..." ,
            "2": "..."