Skip to content

Instantly share code, notes, and snippets.

View ZJUGuoShuai's full-sized avatar

Guo Shuai ZJUGuoShuai

  • ByteDance
  • Hangzhou, China
  • 14:28 (UTC +08:00)
View GitHub Profile
@ZJUGuoShuai
ZJUGuoShuai / beamer-template.tex
Last active May 26, 2020 09:07
My Beamer template
\documentclass[8pt, t, aspectratio=169, compress]{beamer}
\usetheme{Berlin}
\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK SC}
\usefonttheme[onlymath]{serif}
\usepackage{txfonts}
\usepackage[T1]{fontenc}
"""
获取最新 IP 地址
运行需要 requests 库:
$ pip install requests
"""
import requests
  1. 从压缩包恢复镜像 执行下面的命令将镜像读入本地:
$ docker load < chatbot_image.tar.gz
  1. 从镜像运行容器 执行下面的命令,从镜像运行一个容器示例:
$ docker run -it --rm --name chatbot -p 8080:8080 -p 5000:5000 chatbot:v0.3 /run.sh
  1. 打开本机浏览器开始使用 打开浏览器,输入地址 127.0.0.1:8080 开始使用聊天界面。
@ZJUGuoShuai
ZJUGuoShuai / wechat_friends_avatars.py
Created June 13, 2019 15:03
将微信好友头像拼成一个图片
import itchat
import os
import math
from PIL import Image
itchat.auto_login(hotReload=True) # 扫码登录微信
if not os.path.exists('img'): # 如果同目录没有img目录
os.mkdir('img') # 创建img目录
@ZJUGuoShuai
ZJUGuoShuai / mouse.sh
Created June 13, 2019 12:58
保持鼠标光标移动
#!/bin/bash
LENGTH=1
DELAY=5
while true
do
for ANGLE in 0 90 180 270
do
xdotool mousemove_relative --polar $ANGLE $LENGTH
sleep $DELAY
done
@ZJUGuoShuai
ZJUGuoShuai / Simplest_TF_LinearRegression.py
Created May 29, 2019 07:42
用 Tensorflow low API 实现最简单的线性回归模型训练
x = tf.constant([[1], [2], [3], [4]], dtype=tf.float32)
y_true = tf.constant([[0], [-1], [-2], [-3]], dtype=tf.float32)
linear_model = tf.layers.Dense(units=1)
y_pred = linear_model(x)
loss = tf.losses.mean_squared_error(labels=y_true, predictions=y_pred)
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
<pseudocode>
<pre style="display:none;">
\begin{algorithm}
\caption{Quicksort}
\begin{algorithmic}
\PROCEDURE{Quicksort}{$A, p, r$}
\end{algorithmic}
\end{algorithm}
</pre>
</pseudocode>
@ZJUGuoShuai
ZJUGuoShuai / KDTree.py
Created March 20, 2019 08:45
自己实现的 KD-Tree 类,包含求最近邻的方法。
from collections import namedtuple
from operator import itemgetter
from pprint import pformat
import numpy as np
class Node(namedtuple('Node', 'location left_child right_child')):
def __repr__(self):
return pformat(tuple(self))
@ZJUGuoShuai
ZJUGuoShuai / CBOW.py
Created March 19, 2019 10:47
使用 PyTorch 训练 CBOW 模型
import torch
import torch.nn as nn
import numpy as np
def make_context_vector(context, word_to_ix):
idxs = [word_to_ix[w] for w in context]
return torch.tensor(idxs, dtype=torch.long)
def get_index_of_max(input):
index = 0
@ZJUGuoShuai
ZJUGuoShuai / NGram.py
Created March 19, 2019 01:14
使用 PyTorch 训练 NGram 模型
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
torch.manual_seed(1)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
CONTEXT_SIZE = 2
EMBEDDING_DIM = 10