Skip to content

Instantly share code, notes, and snippets.

@mdauphin
mdauphin / gist:72cde0fe90f987906bdc
Created February 16, 2015 15:50
Rescale with ratio conserve
Size Rescale(Size original)
{
// Figure out the ratio
double ratioX = (double)ThumbmailSize.Width / (double)original.Width;
double ratioY = (double)ThumbmailSize.Height / (double)original.Height;
// use whichever multiplier is smaller
double ratio = ratioX < ratioY ? ratioX : ratioY;
// now we can get the new height and width
int newWidth = Convert.ToInt32(original.Width * ratio);
int newHeight = Convert.ToInt32(original.Height * ratio);
void cvPolyfit( CvMat* src_x, CvMat* src_y, CvMat *dst, int order )
{
CvMat* X = cvCreateMat( src_x->rows, order+1, CV_32FC1 );
for(int i=0;i<=order;i++)
{
CvMat* cpy = cvCloneMat( src_x );
cvPow( cpy, cpy, (double)i );
for (int j=0;j<src_x->rows;j++)
cvmSet( X, j, i, cvmGet( cpy, j, 0 ) );
--- build/qt-everywhere-opensource-src-4.6.2/src/gui/image/qpnghandler.cpp.ori 2015-08-06 21:07:32.907967363 +0200
+++ build/qt-everywhere-opensource-src-4.6.2/src/gui/image/qpnghandler.cpp 2015-08-06 21:47:40.071884019 +0200
@@ -163,8 +163,11 @@
int bit_depth;
int color_type;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
- if (color_type == PNG_COLOR_TYPE_GRAY) {
+ png_colorp palette;
+ int num_palette;
#openssl-0.9.8l man build problem
#Error look like: file.pod around line 000: Expected text after =item, not a number
$ cd openssl-0.9.8l
$ find doc/ -name '*.pod' -print0 | xargs -0 sed -i 's/^=item \([0-9]\)/=item C<\1>/'
import numpy as np
def LocalMaximaFinder( im, kernel = [ 32, 32 ], threshold = 0, min_distance = 0 ):
( h, w ) = im.shape
results = []
for y in range(0,h,kernel[0]):
for x in range(0,w,kernel[1]):
sub = im[y:y+kernel[0],x:x+kernel[1]]
max_pxl_value = np.max(sub)
if max_pxl_value > threshold:
@mdauphin
mdauphin / extract_table.py
Created November 30, 2015 10:09
Extract table from MySQL dump gz compressed file
import sys
import gzip
'''
Extract table from MySQL dump file
use like this:
python extract_table.py filename.gz table_name > extract.txt
'''
with gzip.open(sys.argv[1],'rb') as f:
Function UploadFile( url, file, fileType )
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
Dim boundary
boundary = "12345678"
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Type = 1 ' binary
.Open
.LoadFromFile(file)
End With
@mdauphin
mdauphin / main.cpp
Last active July 19, 2016 15:47
STL Find in object vector with attribute getter name
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std ;
class A
{
@mdauphin
mdauphin / gist:21eb2a09e967862a48fd0d63c6012dbc
Created July 27, 2016 12:48
Build AVRDude from ubuntu for windows
UBUNTU:~/avrdude/avrdude-6.2$ sudo apt-get install bison flex libusb-dev
UBUNTU:~/avrdude/avrdude-6.2$ ./configure --host=i586-w32-mingw32 CC=i586-mingw32msvc-gcc
UBUNTU:~/avrdude/avrdude-6.2$ make
@mdauphin
mdauphin / download.py
Last active August 3, 2016 06:04
Python download RSS podcast
import feedparser
import sys
import urllib2
import os.path
'''
Download all mp3 from rss podcast in current directory
program usage:
python download.py http://url/podcast.rss
'''