Skip to content

Instantly share code, notes, and snippets.

View AtomicVar's full-sized avatar
🇨🇳

AtomicVar AtomicVar

🇨🇳
  • Zhejiang University
  • Hangzhou, China
  • 21:05 (UTC +08:00)
View GitHub Profile
@AtomicVar
AtomicVar / sendmail.py
Created July 14, 2018 12:41
Send email using Python 3.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from_addr = "msn4399@163.com"
to_addr = "httpggg@qq.com"
msg = MIMEMultipart()
msg['From'] = from_addr
msg['To'] = to_addr
#include <windows.h>
#include <stdio.h>
void normal(char* s) {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WORD info_style = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
SetConsoleTextAttribute(hOut, info_style);
printf(s);
}
@AtomicVar
AtomicVar / sslocal.service
Last active November 9, 2018 15:12
Shadowsocks Python (3.0.0) systemd service script
[Unit]
Description=Shadowsocks Python local client
[Service]
Type=forking
ExecStart=/path/to/sslocal -c /path/to/config.json -d start
ExecReload=/path/to/sslocal -c /path/to/config.json -d restart
ExecStop=/path/to/sslocal -c /path/to/config.json -d stop
[Install]
@AtomicVar
AtomicVar / change_windows_highlight_color
Created December 1, 2018 02:45
Change Windows highlight color
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\DefaultColors\Standard
\HKEY_CURRENT_USER\Control Panel\Colors
@AtomicVar
AtomicVar / readFileToStr.cpp
Created April 28, 2018 06:17
C++ small snippets to read a file into a single string.
#include <iostream>
#include <sstream>
#include <fstream>
std::string readFileToStr(std::string file)
{
std::ifstream input(file);
std::stringstream sstr;
while(input >> sstr.rdbuf());
@AtomicVar
AtomicVar / cnblogs.py
Created February 27, 2019 12:50
博客园编程语言文章数量 爬虫
import requests
from bs4 import BeautifulSoup
base_url = 'https://zzk.cnblogs.com/s/blogpost'
cookies = dict(
ZzkNoRobotCookie=
'CfDJ8KlpyPucjmhMuZTmH8oiYTOsZWLqcxSx0sRuNdfc35P334ttmwTqPekgb1OOGtp_JeXby7PZgQla4HC63Y3_nnWwF8kvdklA71DbLOQ2ADfziUqy4BkuXQUgJEB4y2kj6w'
)
languages = [
@AtomicVar
AtomicVar / img_compress.py
Created March 15, 2019 12:53
Python图片压缩:使用奇异值分解
from scipy.misc import imread
from scipy.linalg import svd
import matplotlib.pyplot as plt
import numpy as np
if __name__ == '__main__':
img = imread('mm.jpg')
h, w, c = img.shape
@AtomicVar
AtomicVar / kdtree.py
Created March 17, 2019 12:56
KD-Tree Python 实现(来自维基百科)
from collections import namedtuple
from operator import itemgetter
from pprint import pformat
class Node(namedtuple('Node', 'location left_child right_child')):
def __repr__(self):
return pformat(tuple(self))
@AtomicVar
AtomicVar / 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
@AtomicVar
AtomicVar / 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