View simpleHttpServer.py
#!/usr/bin/env python
import SimpleHTTPServer, BaseHTTPServer, SocketServer, socket, time, sys
class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer) :
"""
New features w/r to BaseHTTPServer.HTTPServer:
- serves multiple requests simultaneously
- catches socket.timeout and socket.error exceptions (raised from
View hamming_distance_hard_way.py
def Denary2Binary(list):
'''convert denary integer n to binary string bStr'''
result = []
bStr = ''
for n in list:
print "n is %s" %n
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
View convert_decimal.py
# convert a decimal (denary, base 10) integer to a binary string (base 2)
# tested with Python24 vegaseat 6/1/2005
def Denary2Binary(n):
'''convert denary integer n to binary string bStr'''
bStr = ''
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
n = n >> 1
View compare_pytho_json_libs.py
import time
import pickle
import yajl
try:
import cjson
except ImportError:
cjson = None
try:
import simplejson
View InstallCert.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
View getPrivateProperty.php
private function getProtectedProperty($class, $propertyName)
{
$reflectObj = new \ReflectionObject($class);
$extensions = $reflectObj->getProperty($propertyName);
$extensions->setAccessible(true);
return $extensions->getValue($class);
}
View setPrivateProperty.php
private function setProtectedProperty($class, $propertyName, $setValue)
{
$reflectObj = new \ReflectionObject($class);
$extensions = $reflectObj->getProperty($propertyName);
$extensions->setAccessible(true);
$extensions->setValue($class, $setValue);
}
View runProtectedMethod.php
protected function runProtectedFunction($class, $methodName, $args = null)
{
$reflectMethod = new \ReflectionMethod($class,$methodName);
$reflectMethod->setAccessible(true);
if ($args == null)
{
return $reflectMethod->invoke($class);
} else
{
return $reflectMethod->invokeArgs($class, $args);
View RandomInt.java
/**
* Random generator in range
*
* @param minimum Number
* @param maximum Number
* @return randomNumber
*/
public int randomGenerator(int minimum, int maximum) {
Random rn = new Random();
int range = maximum - minimum + 1;
View IgnorePhpUnitTest.php
$this->markTestSkipped('This test is scipped ');