Skip to content

Instantly share code, notes, and snippets.

@yydai
yydai / dawg.py
Created September 2, 2019 03:41 — forked from smhanov/dawg.py
Use a DAWG as a map
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Please see http://stevehanov.ca/blog/index.php?id=115 for the accompanying article.
#
# Based on Daciuk, Jan, et al. "Incremental construction of minimal acyclic finite-state automata."
# Computational linguistics 26.1 (2000): 3-16.
#
# Updated 2014 to use DAWG as a mapping; see
# Kowaltowski, T.; CL. Lucchesi (1993), "Applications of finite automata representing large vocabularies",
# Software-Practice and Experience 1993
@yydai
yydai / hive-udf-adjacent-chars-checker.java
Created August 30, 2019 10:28
adjacent single char exchange
import org.apache.hadoop.hive.ql.exec.UDF;
public class CheckSwapCharsUDF extends UDF {
public Integer evaluate(String str1, String str2) throws Exception {
if (str1 == null || str2 == null)
return -1;
int s1_len = str1.length();
int s2_len = str2.length();
if (s1_len != s2_len)
return -1;
@yydai
yydai / java01.java
Created August 22, 2019 03:53
java snippets
// drop the duplicate values
Set<String> set = new HashSet<>(fullMatch);
fullMatch.clear();
fullMatch.addAll(set);
@yydai
yydai / install.sh
Last active August 18, 2019 03:33
linux env setup
# install emacs
sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt update
sudo apt install emacs-snapshot emacs-snapshot-el
# install gnome-tweak-tool
sudo apt-get install gnome-tweak-tool
# install pip3
sudo apt install python3-pip
@yydai
yydai / linux_backup.org
Created August 7, 2019 06:02
ubuntu 系统备份

https://zhuanlan.zhihu.com/p/51827233

tar -cvpzf /media/ubuntu_backup@`date +%Y-%m+%d`.tar.gz –exclude=/proc –exclude=/tmp –exclude=/home/yingdai/Workspace/Qunar/Gitlab/h_xsearch –exclude=/lost+found –exclude=/media –exclude=/mnt –exclude=/run /

tar -xvpzf /media/ubuntu_backup@2016-6-6.tar.gz -C /

@yydai
yydai / linux_disk.org
Created August 7, 2019 05:49
Linux disk 相关

查看文件大小

du -sh * / du -sh <filename>

查看目录中的文件大小

du -h –max-depth=1 <folder>

% ==== Document Class & Packages =====
\documentclass[12pt,hidelinks]{article}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}
\usepackage{charter}
\usepackage[many]{tcolorbox}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{xcolor}
@yydai
yydai / trie-spellcheck-autocomplete.cpp
Created June 4, 2018 04:26
使用trie进行补全和检查错误。
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#define N 256
using namespace std;
struct TreeNode {
bool isEnd;
@yydai
yydai / plot1.py
Last active May 17, 2018 08:02
Plot
import matplotlib.pyplot as plt
x = np.linspace(-5, 5, 200) # x data, shape=(100, 1)
y1 = 2 * x #...
y2 = x ** 2 + 2
y3 = sin(x)
plt.figure(1, figsize=(8, 6))
plt.subplot(221)