Skip to content

Instantly share code, notes, and snippets.

@yydai
yydai / Calc.java
Last active January 4, 2024 13:23
chapter4 of antlr4---Building a Calculator Using a Visitor
/***
* Excerpted from "The Definitive ANTLR 4 Reference",
* published by The Pragmatic Bookshelf.
* Copyrights apply to this code. It may not be used to create training material,
* courses, books, articles, and the like. Contact us if you are in doubt.
* We make no guarantees that this code is fit for any purpose.
* Visit http://www.pragmaticprogrammer.com/titles/tpantlr2 for more book information.
***/
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
% ==== 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 / 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>

@yydai
yydai / kafka-py.py
Last active September 27, 2018 16:58
python kafka consumer producer
# from: https://github.com/dpkp/kafka-python/blob/master/example.py
import threading, logging, time
import multiprocessing
from kafka import KafkaConsumer, KafkaProducer
class Producer(threading.Thread):
def __init__(self):