Skip to content

Instantly share code, notes, and snippets.

@yydai
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
yydai / get().js
Last active May 30, 2017
Javascript HTTP GET response
View get().js
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
jQuery.ajax({
type: 'GET',
dataType:'json',
url: 'https://api.github.com/repos/yydai/yydai.github.io/issues/1/comments',
success: function(data){
//marker = JSON.stringify(data);
//alert(marker);
View static-comments.js
var base_url = 'https://api.github.com';
var title = document.title;
var owner = 'yydai';
var repo = 'yydai.github.io';
var search_issues = base_url + '/search/issues?q=' + title + '+user:' + owner;
function test() {
jQuery.ajax({
type: 'GET',
View blog-makefile
pub_date = `date +'%y.%m.%d %H:%M:%S'`
messages = "Auto published by yydai at $(pub_date)"
publish:
@echo "======================================"
@echo "Begin publish the site, please wait..."
@echo "======================================"
@git add .
@-git commit -m $(messages)
View crawler-baidu.py
#coding:utf-8
import re
import requests
from bs4 import BeautifulSoup
def join_str(contents):
strings = []
for content in contents:
if isinstance(content, basestring):
strings.append(content)
View plot1.py
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)
@yydai
yydai / trie-spellcheck-autocomplete.cpp
Created Jun 4, 2018
使用trie进行补全和检查错误。
View trie-spellcheck-autocomplete.cpp
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#define N 256
using namespace std;
struct TreeNode {
bool isEnd;
@yydai
yydai / kafka-py.py
Last active Sep 27, 2018
python kafka consumer producer
View kafka-py.py
# 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):
View python-tools.md
@yydai
yydai / linux_disk.org
Created Aug 7, 2019
Linux disk 相关
View linux_disk.org

查看文件大小

du -sh * / du -sh <filename>

查看目录中的文件大小

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