Skip to content

Instantly share code, notes, and snippets.

@tdoly
tdoly / binary_search_no_repeating_elements.py
Created September 9, 2013 07:53
二分查找法,有相同元素列表,通过指定返回第一个或最后一个元素的索引,得到需要的index(与mysql的InnoDB存储引擎中,指定where条件的>,>=,<,<=比较类似)
#!/usr/bin/env python
# -*- #coding:utf-8
'''
Created on 2013-9-4
@author: mingdong.li
二分查找法,作用于没有重复元素的序列的二分查找法,使用循环(递归的调用存在着压栈、出栈的开销,效率比较低。)
'''
@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):
'''
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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