Skip to content

Instantly share code, notes, and snippets.

View mlashcorp's full-sized avatar

José Côrte-Real mlashcorp

View GitHub Profile
@mlashcorp
mlashcorp / md5folder.py
Created March 23, 2011 15:20
Creates a md5 hash using every file in a given folder
#Returns the md5 hash for every file in folder 'folder', except if the
#file is named 'md5' (because that means the folder already contains a md5
#hash)
def md5_for_folder(self,folder, block_size=128):
md5 = hashlib.md5()
for root, dirs, files in os.walk(os.path.join(folder)):
for f in files:
if f!="md5":
fp = open(os.path.join(folder,f),'r')
@mlashcorp
mlashcorp / burn_data.py
Created March 24, 2011 14:06
Method to interact with cdrecord
import subprocess
def burn_data(self,PATH):
dir,file = (os.path.split(PATH))
#unmount disc just in case (shouldn't be necessary for a blank disk)
p0 = Popen(["umount","/media/CDROM"],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#wait for unmount
p0.wait()
#create the isofs raw image to write to cd
p1 = Popen(["mkisofs","-R","-o","image.raw",PATH],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@mlashcorp
mlashcorp / generate_barcode.sh
Created April 14, 2011 09:57
Basic example of how to generate a code 128 barcode
barcode -b 0401001702201100 -e 128 -u mm -g 50x20 -o teste
@mlashcorp
mlashcorp / svn-propset
Created August 29, 2011 10:22
svn propset
svn propset svn:keywords 'Id Revision' target-source-file
@mlashcorp
mlashcorp / version-string
Created August 29, 2011 10:24
Implements a version string with svn revision preprocessor macro
#define VERSION "1.2.0 - development - COMMIT: $Revision: 17 $"
@mlashcorp
mlashcorp / unsharp_mask.cpp
Created January 19, 2012 16:52
opencv documentation description of unsharp mask algorithm
// sharpen image using "unsharp mask" algorithm
Mat blurred; double sigma = 1, threshold = 5, amount = 1;
GaussianBlur(img, blurred, Size(), sigma, sigma);
Mat lowConstrastMask = abs(img - blurred) < threshold;
Mat sharpened = img*(1+amount) + blurred*(-amount);
img.copyTo(sharpened, lowContrastMask);
@mlashcorp
mlashcorp / eq_hist.cpp
Created January 19, 2012 19:06
equalize color image histogram
std::vector<cv::Mat> planes;
cv::cvtColor(mat, sharp_mat, CV_BGR2HSV);
cv::split(sharp_mat, planes);
cv::equalizeHist(planes[2], planes[2]);
cv::merge(planes, sharp_mat);
cv::cvtColor(sharp_mat, mat, CV_HSV2BGR);
@mlashcorp
mlashcorp / gist:4462330
Created January 5, 2013 16:24
Android accelerometer polling, just the creation and update portions. Updated the class to implement SensorEventListener, since SensorListener is deprecated
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
accell = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
setContentView(R.layout.activity_main);
xacc = (TextView) findViewById(R.id.xvalue);
yacc = (TextView) findViewById(R.id.yvalue);
zacc = (TextView) findViewById(R.id.zvalue);
@mlashcorp
mlashcorp / gist:6234668
Created August 14, 2013 19:30
Python: discover ip address of interface that has internet accessibility (in case there are many)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("gmail.com",80))
print(s.getsockname()[0])
s.close()
######################################################################
##
## Feature Broker
##
######################################################################
class FeatureBroker:
def __init__(self, allowReplace=False):
self.providers = {}
self.allowReplace = allowReplace