Skip to content

Instantly share code, notes, and snippets.

Andrew Zakordonets azakordonets

Block or report user

Report or block azakordonets

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@azakordonets
azakordonets / simpleHttpServer.py
Created Sep 1, 2013
Python simple HTTP Server that get's two variables for launch - port and time delay( time after which server will return response) . If we do not specify this two values, then server starts on 8000 port with delay = 0
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
@azakordonets
azakordonets / hamming_distance_hard_way.py
Created Sep 1, 2013
I faced with one task while learning python where i had to work with bytes and get total number of differences between this two numbers
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
@azakordonets
azakordonets / convert_decimal.py
Created Sep 1, 2013
convert a decimal (denary, base 10) integer to a binary string (base 2)
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
@azakordonets
azakordonets / compare_pytho_json_libs.py
Created Sep 17, 2013
This script shows which lib is faster in encoding and decoding
View compare_pytho_json_libs.py
import time
import pickle
import yajl
try:
import cjson
except ImportError:
cjson = None
try:
import simplejson
@azakordonets
azakordonets / InstallCert.java
Created Jan 7, 2014
java class for ssl keys installation
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;
@azakordonets
azakordonets / getPrivateProperty.php
Created Feb 11, 2014
Get private property from instance of the class
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);
@azakordonets
azakordonets / RandomInt.java
Created Mar 14, 2014
Generate random int number in Java
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;
@azakordonets
azakordonets / IgnorePhpUnitTest.php
Created Apr 15, 2014
This call makes phpunit to mute specific test
View IgnorePhpUnitTest.php
$this->markTestSkipped('This test is scipped ');
You can’t perform that action at this time.