Skip to content

Instantly share code, notes, and snippets.

View xiaohk's full-sized avatar
🐐
Mr. King Chivo

Jay Wang xiaohk

🐐
Mr. King Chivo
View GitHub Profile
@xiaohk
xiaohk / download.py
Last active March 7, 2017 02:04
Download all avaliable data files of the book "Linear Regression by Example"(5th edition)
"""
If you want to download the data of 4th edition, change all the '5' in the string
below to '4' (i.e. '/data5' -> '/data4'). Although two editions almost have the same
data sets, the data format for 4th edition is kinda sloppy. Thus 5th edition is recommended.
"""
import urllib.request
import requests
import regex as re
@xiaohk
xiaohk / uni.py
Created February 21, 2017 01:43
How Python3 deals with unicode character and code point
zh = 'U+5EB8'
print(zh) # U+5EB8
zh = '\u5EB8'
print(zh) # 庸
zh = '\\u5EB8'
print(zh) # \\u5EB8
print(zh.decode('unicode-escape')) # AttributeError: 'str' object has no attribute 'decode'
print(zh.encode('ascii').decode('unicode-escape')) # 庸
@xiaohk
xiaohk / .vimrc
Created April 5, 2017 19:09
My .vimrc file
"The default color theme of vim" :colo obsidian2
:colo obsidian2
"set background=dark
"colo solarized
"Execute the python scrip by clicking control + B"
:nnoremap <C-B> :w<CR>:!python3 %<CR>
"Change the current working directory to dropbox"
":cd ~/Dropbox/Vim_programming
@xiaohk
xiaohk / auto_activate_virtualenv.sh
Last active April 11, 2017 01:09
Automatically activate virtualenv when cd into project directory
# Automatically activate virtualenv when using 'cd' (rewrite builtin cd function)
# Assuming current working directory is in a sub-directory of virtualenv directory
function cd {
builtin cd "$@"
# Check upper 4 directories
if [-d "../bin" -a -d "../lib" -a -d "../include" -a -e "../.Python" \
-a -e "../pip-selfcheck.json" ] ; then
source ../bin/activate
elif [ -d "../../bin" -a -d "../../lib" -a -d "../../include" -a -e \
"../../.Python" -a -e "../../pip-selfcheck.json" ] ; then
@xiaohk
xiaohk / plot_map.R
Created April 25, 2017 16:21
Matching continuous data to the United States map, and Wisconsin county map
library('ggplot2')
library('maps')
# Plot the United State map with AQL data
head(state_aql)
# name AQL state
# 1 Alabama 34.83090 alabama
# 2 Alaska 21.12207 alaska
# 3 Arizona 28.49161 arizona
@xiaohk
xiaohk / prepare_for_guide.R
Last active September 20, 2017 02:35
A simple function to generate both data file and description file for the regression tree software GUIDE
# We want to create clean data file and description file for GUIDE
prepare_for_guide = function(df, y_name, output_name, desc_name){
# Find the index of response variable y
y_index = which(colnames(df)==y_name)
# Data file
write.table(df, output_name, row.names=FALSE, col.names=FALSE, quote=FALSE)
# Description file
desc_file = file(desc_name)
@xiaohk
xiaohk / gadfly_demo.ipynb
Created February 5, 2018 23:14
A demo of how to plot lines and polygons using Gadfly.jl
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xiaohk
xiaohk / keybase.md
Created February 18, 2018 02:45
Keybase Github Identity

Keybase proof

I hereby claim:

  • I am xiaohk on github.
  • I am xiaohk (https://keybase.io/xiaohk) on keybase.
  • I have a public key ASAaaTf0leOMgJkNe95qixaiDCkgSEHryJ5dPNmbp1UC5Qo

To claim this, I am signing this object:

@xiaohk
xiaohk / china.geojson
Created August 8, 2018 21:19
GeoJSON file for China
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.