Skip to content

Instantly share code, notes, and snippets.

import pyejdb
from datetime import datetime
#Open database
ejdb = pyejdb.EJDB("zoo", pyejdb.DEFAULT_OPEN_MODE | pyejdb.JBOTRUNC)
parrot1 = {
"name": "Grenny",
"type": "African Grey",
"male": True,
from pyPdf import PdfFileWriter, PdfFileReader
import os, sys
output = PdfFileWriter()
input1 = PdfFileReader(file("hello_pypdf.test.pdf", "rb"))
# print the title of document1.pdf
# May fail for non-English
# print "title = %s" % (input1.getDocumentInfo().title)
#sudo pip install bottle
#sudo pip install requests
from multiprocessing import Process
from bottle import route, run # http://bottlepy.org/docs/dev/
import requests # http://docs.python-requests.org/en/latest/index.html
@route('/hello/:name')
def hello(name='World'):
return "Hello, %s!" % name
# http://hi.baidu.com/ruclin/item/8f78b786be2f672a110ef369
#
#**************************************************************************
#* *
#* General Purpose Hash Function Algorithms Library *
#* *
#* Author: Arash Partow - 2002 *
#* URL: http://www.partow.net *
#* URL: http://www.partow.net/programming/hashfunctions/index.html *
@baojie
baojie / hello_execnet.py
Created March 24, 2013 07:52
Embed Java in Python .Example from: Integrating Jython with Java by Jim Baker and Shashank Bharadwaj by PyCon 2013 https://speakerdeck.com/pyconslides/integrating-jython-with-java-by-jim-baker-and-shashank-bharadwaj
import execnet
gw = execnet.makegateway("popen//python=jython")
channel = gw.remote_exec("""
from java.util import Vector
v = Vector()
v.add('aaa')
v.add('bbb')
for val in v:
channel.send(val)
""")
import execnet
group = execnet.Group()
for i in range(4): # 4 CPUs
group.makegateway()
def process_item(channel):
# task processor, sits on each CPU
import time, random
channel.send("ready")
@baojie
baojie / merge_pdfbox.py
Created March 25, 2013 05:04
Jython: merge two pdfs using pdfbox
import sys
from java.io import *
import java.io.InputStream
import java.io.FileInputStream
import java.lang.String # blah....converting String types between Java/Python is tedious
sys.path.append("/usr/share/java/pdfbox.jar") # or wherever you stashed it
sys.path.append("/usr/share/java/commons-logging.jar")
import org.apache.pdfbox
"""
import execnet
# this function will be run in jython, calling from cpython
def do_merge(channel):
import sys
#from java.io import *
import java.io.InputStream
import java.io.FileInputStream
import java.lang.String
@baojie
baojie / mediawiki.xsd
Created March 30, 2013 20:31
MediaWiki XML Schema
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
This is an XML Schema description of the format
output by MediaWiki's Special:Export system.
Version 0.2 adds optional basic file upload info support,
which is used by our OAI export/import submodule.
Version 0.3 adds some site configuration information such
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# =============================================================================
# Version: 2.4 (April 2, 2013)
# Author: Giuseppe Attardi (attardi@di.unipi.it), University of Pisa
# Antonio Fuschetto (fuschett@di.unipi.it), University of Pisa
#
# Contributors:
# Leonardo Souza (lsouza@amtera.com.br)