Skip to content

Instantly share code, notes, and snippets.

View psycharo-zz's full-sized avatar

Timur psycharo-zz

  • EPFL
  • Lausanne, Switzerland
View GitHub Profile
@psycharo-zz
psycharo-zz / median.hpp
Last active August 29, 2015 13:55
streaming median
template <typename Iterator>
typename std::iterator_traits<Iterator>::value_type
median(Iterator _start, Iterator _end)
{
typedef typename std::iterator_traits<Iterator>::value_type value_t;
std::vector<value_t> low;
std::vector<value_t> high;
high.push_back(*_start);
@psycharo-zz
psycharo-zz / ls.hpp
Last active August 29, 2015 13:58
get a list of directories in (posix) c++
#include <dirent.h>
vector<string> list_dir(const string &path)
{
vector<string> result;
dirent *pdir;
DIR *dir = opendir(path.c_str()); // open current directory
while (pdir = readdir(dir))
result.push_back(pdir->d_name);
closedir(dir);
@psycharo-zz
psycharo-zz / date2string.hpp
Created April 23, 2014 08:00
get a (date) timestamp in c++
#include <ctime>
using namespace std;
inline std::string date_string()
{
time_t rawtime;
std::time(&rawtime);
struct tm *tinfo = std::localtime(&rawtime);
char buffer[12];
string string_format(const string fmt, ...)
{
int size = 512;
std::string str;
va_list ap;
while (1) {
str.resize(size);
va_start(ap, fmt);
int n = vsnprintf((char *)str.c_str(), size, fmt.c_str(), ap);
@psycharo-zz
psycharo-zz / loadmat.py
Created May 15, 2014 17:05
loading matlab matrices
def loadmat(filename):
'''
this function should be called instead of direct spio.loadmat
as it cures the problem of not properly recovering python dictionaries
from mat files. It calls the function check keys to cure all entries
which are still mat-objects
'''
data = sio.loadmat(filename, struct_as_record=False, squeeze_me=True)
return _check_keys(data)
@psycharo-zz
psycharo-zz / heap.cpp
Last active August 29, 2015 14:02
simple c++11ish heap
map<double, size_t> top;
size_t max_size = 100;
auto top_add = [&top,max_size](double value, size_t id)
{
if (top.size() < max_size)
top.insert(make_pair(value, id));
else
{
if (top.begin()->first < value)
@psycharo-zz
psycharo-zz / channels.hpp
Created January 27, 2015 17:18
simple channel feature computation
vector<cv::Mat> gradient_histogram(const cv::Mat &M, const cv::Mat &O, int num_channels)
{
vector<cv::Mat> channels;
double step = 2 * M_PI / num_channels;
for (int t = 0; t < num_channels; ++t)
{
cv::Mat C;
cv::inRange(O, t*step, t*step+1, C);
C.convertTo(C, CV_64F);
C /= 255.0;
@psycharo-zz
psycharo-zz / integral_image.hpp
Last active September 23, 2015 14:36
simplistic integral image in armadillo
inline arma::mat integral_image(const arma::mat &a)
{
using namespace arma;
mat a_ii = zeros(a.n_rows+1, a.n_cols+1);
for (size_t j = 0; j < a.n_rows; ++j)
{
double sum = 0.0;
for (size_t i = 0; i < a.n_cols; ++i)
{
sum += a(j,i);
function addressToCoordinates($address) {
$BASE_URL = 'http://maps.googleapis.com/maps/api/geocode/json';
$socket = new HttpSocket();
$args = array('address' => $address,
'sensor' => 'false');
$results = json_decode($socket->get($BASE_URL, $args));
<?php
/**
* Application level Controller
*
* This file is application-wide controller file. You can put all
* application-wide controller-related methods here.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)