Skip to content

Instantly share code, notes, and snippets.

@tdoly
tdoly / test_go.go
Last active March 2, 2018 13:14
python/go/swift vs
package main
import "fmt"
var sum = 0
func main() {
for e := 0; e < 30; e++ {
sum = 0
var x[]int
for i := 0; i < 1000000; i++ {
x = append(x, i)
@tdoly
tdoly / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tdoly
tdoly / v2ex_auto_login.py
Last active May 24, 2019 13:28
v2ex 自动登录,领取金币脚本
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
import logging
import datetime
import requests
import BeautifulSoup
from requests.adapters import HTTPAdapter
@tdoly
tdoly / checksql.java
Last active January 2, 2016 19:09
检查sql是否在指定权限内
package com.dong.java.test;
import java.util.HashMap;
import java.util.Map;
public class CheckSQL {
private static String[] DBNAMES={""};
private static String[] keywords={"alter ","create ", "delete ", "do ", "drop ", "handler ", "insert ", "load data infile ", "rename ",
@tdoly
tdoly / SAXParserXmlUtil.java
Created December 27, 2013 09:02
java using sax get xml node and nodeValue
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserXmlUtil extends DefaultHandler {
private StringBuffer node=new StringBuffer();
private StringBuffer nodeValue=new StringBuffer();
@tdoly
tdoly / TestJavaToJson.java
Created December 3, 2013 07:37
json-lib的使用:可以将beans,maps,collections,java arrays,和XML转换为JSON。同样也可以将JSON转换为beans和DynaBeans。 jackson:很快的JSON解析
package com.tdoly.java.test.jsonlib;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.tdoly.java.test.beans.User;
import com.tdoly.java.test.beans.User.Gender;
@tdoly
tdoly / KnuthMorrisPratt.py
Created November 20, 2013 09:10
KMP算法
def failTable(pattern):
# Create the resulting table, which for length zero is None.
result = [None]
# Iterate across the rest of the characters, filling in the values for the
# rest of the table.
for i in range(0, len(pattern)):
# Keep track of the size of the subproblem we're dealing with, which
# starts off using the first i characters of the string.
j = i
@tdoly
tdoly / downloadFile.jsp
Created October 8, 2013 07:47
很早之前写了个用jsp显示主机上文件的程序。输入路径,显示文件和文件夹的名称,修改时间,大小。如果是文件,可以下载
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*" import="java.lang.*" import=" javax.servlet.ServletOutputStream" errorPage="" %>
<%
request.setCharacterEncoding("gb2312");
String filename=request.getParameter("filename");
String filepath=request.getParameter("filepath");
filename=java.net.URLDecoder.decode(filename);
filepath=java.net.URLDecoder.decode(filepath);
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment;filename=\"" + new String(filename.getBytes("gb2312"),"iso8859-1") + "\"");
@tdoly
tdoly / grab_web_page.py
Created September 11, 2013 08:20
python线程
#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Created on 2013-8-1
@author: mingdong.li
use thread
@tdoly
tdoly / quick_sort.py
Last active December 22, 2015 17:19
快速排序
#!/usr/bin/env python
# -*- #coding:utf-8
'''
Created on 2013-9-10
@author: mingdong.li
'''
def sort(arr, left, right):
'''