Skip to content

Instantly share code, notes, and snippets.

yydai /
Last active Jul 14, 2021
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 for more book information.
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
yydai / ArrayInit.g4
Created Feb 5, 2017
Chapter3 of antlr4----convert initialized Java short arrays to strings(like {1,2,3} to "\u0001\u0002\u0003")
View ArrayInit.g4
/** Grammars always start with a grammar header. This grammar is called
* ArrayInit and must match the filename: ArrayInit.g4
grammar ArrayInit;
/** A rule called init that matches comma-separated values between {...}. */
init : '{' value (',' value)* '}' ; // must match at least one value
/** A value can be either a nested array/struct or a simple integer (INT) */
value : init
yydai / get().js
Last active May 30, 2017
Javascript HTTP GET response
View get().js
<script src="//"></script>
type: 'GET',
url: '',
success: function(data){
//marker = JSON.stringify(data);
View static-comments.js
var base_url = '';
var title = document.title;
var owner = 'yydai';
var repo = '';
var search_issues = base_url + '/search/issues?q=' + title + '+user:' + owner;
function test() {
type: 'GET',
View blog-makefile
pub_date = `date +'%y.%m.%d %H:%M:%S'`
messages = "Auto published by yydai at $(pub_date)"
@echo "======================================"
@echo "Begin publish the site, please wait..."
@echo "======================================"
@git add .
@-git commit -m $(messages)
import re
import requests
from bs4 import BeautifulSoup
def join_str(contents):
strings = []
for content in contents:
if isinstance(content, basestring):
yydai /
Last active Sep 27, 2018
python kafka consumer producer
# from:
import threading, logging, time
import multiprocessing
from kafka import KafkaConsumer, KafkaProducer
class Producer(threading.Thread):
def __init__(self):
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))
yydai / trie-spellcheck-autocomplete.cpp
Created Jun 4, 2018
View trie-spellcheck-autocomplete.cpp
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#define N 256
using namespace std;
struct TreeNode {
bool isEnd;