Skip to content

Instantly share code, notes, and snippets.

View JobsDong's full-sized avatar

JobsDong JobsDong

  • Alibaba
  • HangZhou, China
View GitHub Profile
@JobsDong
JobsDong / AES.java
Created August 12, 2016 10:06
aes java encrypt
class AES {
public static void main(String[] args) throws NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, IOException, InvalidKeyException, Base64DecodingException, InvalidAlgorithmParameterException {
String content = "this is a test";
String password = "1234567812345678";
System.out.println("before:" + content);
// encrypt
String encrypt = encode(content, "1234567812345678", password);
System.out.println("encrypt:" + encrypt);
@JobsDong
JobsDong / aes.py
Created August 12, 2016 10:06
aes python encrypt
import base64
from Crypto.Cipher import AES
PADDING = '\0'
pad_it = lambda s: s+(16 - len(s) % 16) * PADDING
def encrypt(content, iv, key):
cipher = AES.new(key, AES.MODE_CBC, iv)
package com.shenbian.test;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
@JobsDong
JobsDong / singleton.py
Created December 4, 2015 03:42
python singleton
#!/usr/bin/python
# -*- coding: utf-8 -*-
import threading
class KbTerms(object):
"""singleton
"""
_instance_lock = threading.Lock()
@JobsDong
JobsDong / TrieTree.java
Last active November 28, 2015 08:22
TrieTree
package com.shenbian.service.personchange.impl.utils;
import java.util.*;
/**
* Trie Tree
* @author JobsDong
*/
public class TrieTree {
@JobsDong
JobsDong / HttpUtils.java
Last active August 29, 2015 14:03
charset detect in web crawling
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@JobsDong
JobsDong / dict2xml.py
Last active August 29, 2015 13:57
dict to xml and xml to dict
from xml.dom import minidom
from collections import Mapping
from petl.io import RowContainer
from lxml import etree
def fromxml(source, rowmatch, *args, **kwargs):
return XmlView(source, rowmatch, *args, **kwargs)
@JobsDong
JobsDong / redis-server
Created February 24, 2014 05:37
redis-server in init.d
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@JobsDong
JobsDong / api.py
Created February 21, 2014 11:56
python 另类包装器 __call__的用法
class api_route(object):
"""api的包装器
Attributes:
_api_methods: 字典,key是路径名,value是函数对象
"""
_api_methods = {}
def __init__(self, uri):
@JobsDong
JobsDong / item.py
Last active August 29, 2015 13:56
python metaclass的使用
"""
Scrapy Item
See documentation in docs/topics/item.rst
"""
from pprint import pformat
from UserDict import DictMixin
from scrapy.utils.trackref import object_ref