Skip to content

Instantly share code, notes, and snippets.

View zhouhoo's full-sized avatar

hilo zhouhoo

  • ISCAS
  • Beijing
View GitHub Profile
@zhouhoo
zhouhoo / max_heap
Created October 30, 2017 12:27
build max heap to find kth largest num
class Solution {
public:
inline int left(int idx) {
return (idx << 1) + 1;
}
inline int right(int idx) {
return (idx << 1) + 2;
}
void max_heapify(vector<int>& nums, int idx) {
int largest = idx;
@zhouhoo
zhouhoo / numpy_code_tricks
Created May 16, 2017 12:55
cool and efficient code in numpy.
1. sort an array by the nth column
Z = np.random.randint(0,10,(3,3))
print(Z)
print(Z[Z[:,1].argsort()])
2. Find the nearest value from a given value in an array
m = Z.flat[np.abs(Z - z).argmin()]
3. accumulate elements of a vector (X) to an array (F) based on an index list (I)
X = [1,2,3,4,5,6]
1. go to letsencrypt homepage to download and use some client tool like certbot to auto manage CA from letsencrypt.
2. get and renew CA:
2.1 certbot certonly --webroot -w /var/www/example -d example.com
2.2 certbot renew --dry-run
if you have already configure before,you need to delete entry in jks:(eg $keystoredir=MyDSKeyStore.jks)
keytool -delete -alias root -storepass changeit -keystore $keystoredir
keytool -delete -alias tomcat -storepass changeit -keystore $keystoredir
@zhouhoo
zhouhoo / pandas_sinppets.py
Created January 12, 2017 12:21
Useful pandas snippets
# Next few examples show how to work with text data in Pandas.
# Full list of .str functions: http://pandas.pydata.org/pandas-docs/stable/text.html
# Slice values in a DataFrame column (aka Series)
df.column.str[0:2]
# Lower-case everything in a DataFrame column
df.column_name = df.column_name.str.lower()
@zhouhoo
zhouhoo / pdf-to-txt.java
Created January 6, 2017 07:09
use tika to convert pdf file to txt.
//although it is hard job to convert pdf to text, tika tool is cool for this. it can auto detect pdf format and choose parser to parse the pdf.
package june;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@zhouhoo
zhouhoo / use_custom_font.py
Created December 29, 2016 09:31
add new ttf to matplotlib to display/show non-assic characters
# 1. before use this script, you need to get a customed ttf font file, maybe you have only ttc file ,you can convert it to ttf in
# this awesome web: http://www.zhuan-huan.com/file-convert/
# 2. then edit the matplotlibrc file(for env most in envs/py3/lib/python3.5/site-packages/matplotlib/mpl-data ), uncomment two lines:
# font.family : sans-serif
# font.sans-serif :WenQuanYi Zen Hei,Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid...
# if your ttf font is sans-serif,you need only to add your new font name to the head of font.sans-serif.
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
@zhouhoo
zhouhoo / min-char-rnn.py
Created September 29, 2016 13:01 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)