Skip to content

Instantly share code, notes, and snippets.

View qqpann's full-sized avatar
🍊

Qiushi Pan qqpann

🍊
View GitHub Profile
@qqpann
qqpann / index.md
Created June 16, 2019 14:51
Reinitialize unique item index
item_ids, data[ITEM_IDX_KEY] = np.unique(data[item_id_col], return_inverse=True)
@qqpann
qqpann / index.md
Last active June 14, 2019 06:57
[Amazing GIF emoji for slack] funny gif emojis chosen for slack #gif #slack
@qqpann
qqpann / xonshrc
Last active March 25, 2019 09:01
[Xonsh Awesome Prompt] #xonsh #shell #prompt
# final edit for xonsh 0.8.12
# Author: Qiushi Pan (@qqhann)
def _git_prefix():
import xonsh.tools as xt
prefix = $(git rev-parse --show-prefix).strip()
sep = xt.get_sep()
if len(prefix) == 0:
@qqpann
qqpann / sample.py
Created March 19, 2019 01:49
[Django image upload_to uuid filename snipet] #django
import uuid, os, base64
def uuid32():
return base64.b32encode(uuid.uuid4().bytes).decode('ASCII').rstrip('=')
def get_filefield_ascii_uuid(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
prefix = 'image'
name = uuid32()
@qqpann
qqpann / sample.py
Created March 16, 2019 11:26
[Matplotlib on server] #python #matplotlib
# https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server
# do this before importing pylab or pyplot
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
fig.savefig('test.png')
@qqpann
qqpann / terminal.sh
Created March 16, 2019 08:27
[Without root] #linux
# Ubuntu
# ====================
# dpkg
# https://askubuntu.com/a/350
dpkg -x package.deb dir
@qqpann
qqpann / nginx.conf
Created February 28, 2019 13:25
[Django deploy with uWSGI & Nginx] #django #uwsgi #nginx
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/user/api/master.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
@qqpann
qqpann / env.py
Created February 19, 2019 06:02
[Dotenv snippet] python dotenv snippet #python #dotenv #env
import os
from pathlib import Path
from dotenv import load_dotenv
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
@qqpann
qqpann / init.md
Created February 14, 2019 04:58
[Vim Cheat Sheet] vim cheat sheet #vim

Go Uppercase in current word

gUiw

~ will reverse the case of the selected characters it takes a count e.g. 5~ will reverse the case of 5 characters. g~w to change case of a whole word.

~
@qqpann
qqpann / awesome.py
Created February 11, 2019 04:12
[前処理大全 Awesome Python] 前処理大全でAwesomeとされたPythonコード #Python
# Thanks: https://github.com/ghmagazine/awesomebook
# Filter
df.query('"2016-10-13" <= checkout_date <= "2016-10-14"')
# Sampling
df.sample(frac=0.5) # Random sample 50%
df.sample(n=100) # Specify by N
# 集約ID単位のサンプリング