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
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)
#include <map>
#include <set>
#include <cfloat>
#include <vector>
#include <algorithm>
using namespace std;
typedef long poiid_t;
//! Earth radius
static const double EARTH_RADIUS = 6371400;
//! convert degrees to radians
double toRad(double degrees)
{
return M_PI / 180 * degrees;
}
static const double EARTH_RADIUS = 6371400;
//! WGS84 ellipsoid params (c) JCoord
static const double WGS84_MAJ = 6378137.000;
static const double WGS84_MIN = 6356752.3141;
static const double WGS84_ECC = ((WGS84_MAJ * WGS84_MAJ) - (WGS84_MIN * WGS84_MIN)) / (WGS84_MAJ * WGS84_MAJ);
inline void toUTM(double lat, double lon, double &east, double &north)
@psycharo-zz
psycharo-zz / get_random_item.py
Created February 6, 2013 13:00
gets a randomly weighted item from list
def get_random_item(weights):
num = random.uniform(0, 1)
for i, w in enumerate(weights):
if w > num:
return i
num -= w
@psycharo-zz
psycharo-zz / xargsstdout.sh
Created February 7, 2013 11:23
example of using xargs to manage stdout redirections
ls 2012-12-{}.log | xargs -I file sh -c 'head -n 1000000 file > file.1m'
@psycharo-zz
psycharo-zz / map_insert.hpp
Last active December 18, 2015 04:49
insert and replace in the map if an entry already exists
/**
* insert and replace if an entry already exists
*/
template <class TKey, class TVal>
void map_insert(std::map<TKey, TVal> &values, const std::pair<TKey, TVal> &val)
{
std::pair<typename std::map<TKey,TVal>::iterator, bool> res = values.insert(val);
if (!res.second)
res.first->second = val.second;
}
@psycharo-zz
psycharo-zz / notimplemented.hpp
Created June 13, 2013 16:25
simple macros for not implemented exception
// TODO: __PRETTY_FUNCTION__ only works for the GCC
#define NotImplementedException std::runtime_error(__PRETTY_FUNCTION__ + std::string(": not implemented "))
@psycharo-zz
psycharo-zz / time.cpp
Created June 19, 2013 17:59
get the execution time in seconds
#include <ctime>
clock_t startTime = clock();
// funciton here
cout << double(clock() - startTime) / CLOCKS_PER_SEC << endl;