This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.dom.minidom import parse, parseString | |
dom1 = parse('c:\\temp\\mydata.xml') # parse an XML file by name | |
datasource = open('c:\\temp\\mydata.xml') | |
dom2 = parse(datasource) # parse an open file | |
dom3 = parseString('<myxml>Some data<empty/> some more data</myxml>') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void recordVideoUsingCamera( | |
Camera camera, String fileName, int durMs, boolean timelapse) throws Exception { | |
// FIXME: | |
// We should add some test case to use Camera.Parameters.getPreviewFpsRange() | |
// to get the supported video frame rate range. | |
Camera.Parameters params = camera.getParameters(); | |
int frameRate = params.getPreviewFrameRate(); | |
camera.unlock(); | |
mMediaRecorder.setCamera(camera); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void doTakePicture(final int cameraId) throws Exception { | |
/* | |
Camera class is not thread-safe, and is meant for use from one event thread. | |
Most long-running operations (preview, focus, photo capture, etc) happen asynchronously | |
and invoke callbacks as necessary. | |
Callbacks will be invoked on the event thread open(int) was called from. | |
This class's methods must never be called from multiple threads at once. | |
*/ | |
/* Important: mCamera object must be alloc in another Thread, othwerwise, callback will NOT be invoked. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.cert.X509Certificate; | |
import javax.net.ssl.HostnameVerifier; | |
import javax.net.ssl.HttpsURLConnection; | |
import javax.net.ssl.SSLContext; | |
import javax.net.ssl.SSLSession; | |
import javax.net.ssl.TrustManager; | |
import javax.net.ssl.X509TrustManager; | |
import javax.net.ssl.SSLSocketFactory; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.media.MediaRecorder; | |
import android.media.AudioFormat; | |
import android.media.AudioRecord; | |
import android.util.Log; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
import java.io.IOException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stolen from python2.7 unittest source | |
class _AssertRaisesContext(object): | |
"""A context manager used to implement TestCase.assertRaises* methods.""" | |
def __init__(self, expected, test_case, expected_regexp=None): | |
self.expected = expected | |
self.failureException = test_case.failureException | |
self.expected_regexp = expected_regexp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# keep quotes in args | |
# http://stackoverflow.com/questions/1668649/how-to-keep-quotes-in-args | |
whitespace="[[:space:]]" | |
for i in "$@" | |
do | |
if [[ $i =~ $whitespace ]] | |
then | |
i=\"$i\" | |
fi | |
cmd="$cmd $i" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stolen from http://code.activestate.com/recipes/146306/ | |
import httplib | |
import mimetypes | |
import urlparse | |
def posturl(url, fields, files): | |
urlparts = urlparse.urlsplit(url) | |
return post_multipart(urlparts[1], urlparts[2], fields, files) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import urllib | |
import json | |
def fetch_route(routeid): | |
''' fetch route detail from iriding.cc by routeid | |
return a list of record consist as below: | |
[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import os | |
import tempfile | |
import sqlite3 | |
class DBExportor(object): | |
def __init__(self, db=None): | |
if not db: | |
db = self.pullDB() |