Skip to content

Instantly share code, notes, and snippets.

@gruzovator
gruzovator / gist:7c6e5e5e63988b26894f
Created July 9, 2014 06:14
primitive logging in c++
// debug.h
#include <iostream>
#define NDEBUG 1
#ifdef NDEBUG
#define debug if(1); else std::cout
#else
#define debug std::cout
#endif
using namespace std;
@gruzovator
gruzovator / gps_track_server.py
Created July 15, 2014 17:10
Async TCP server example (using standard python lib asyncore)
#!/usr/bin/env python
''' Async TCP server to make first tests of newly received GPS trackers '''
import asyncore
import socket
import logging
class Server(asyncore.dispatcher):
def __init__(self, address):
asyncore.dispatcher.__init__(self)
@gruzovator
gruzovator / boost_python_example.cpp
Last active August 29, 2015 14:14
Boost.Python example
//------------------------------------------------------------------------------
// C++ module xxx.h, xxx.cpp
//------------------------------------------------------------------------------
#include <string>
#include <boost/regex.hpp>
#include <boost/locale.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
class PhoneExtractor
@gruzovator
gruzovator / ScopeExit.hpp
Created February 12, 2015 07:24
c++11 scope exit
/** Scope exit */
template<typename Callable>
class ScopeExit
{
Callable m_callable;
public:
explicit ScopeExit(Callable c) : m_callable(c) {}
ScopeExit(const ScopeExit&) = delete;
#include <iostream>
#include <stdexcept>
#include <map>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
using namespace std;
using namespace boost::property_tree;
int main(int argc, char const *argv[])
@gruzovator
gruzovator / futures_queue_test.cpp
Last active August 29, 2015 14:15
testing parallel code execution
// build: g++ -std=c++11 futures_queue_test.cpp -lpthread
// usage (single-threaded variant): ./a.out 10 single
// usage (multi-threaded variant): ./a.out 10 parallel
#include <iostream>
#include <sstream>
#include <functional>
#include <algorithm>
#include <future>
#include <chrono>
@gruzovator
gruzovator / format.sh
Last active August 29, 2015 14:15
clang-format
#!/bin/sh
# style lines can be copied to Qt Creator Beautifier plugin
clang-format-3.5 -style='{
Language: Cpp,
Standard: Cpp11,
UseTab: Never,
IndentWidth: 4,
ColumnLimit: 100,
AllowShortIfStatementsOnASingleLine: false,
@gruzovator
gruzovator / ptree_perfomance.cpp
Last active August 29, 2015 14:17
test xml via boost ptree generation
// cxx="g++" cxxflags="-O2"
/**
Test boost ptree perfomance.
2015-03-27
*/
#include <iostream>
#include <vector>
@gruzovator
gruzovator / pyhdfs_test.py
Created April 21, 2015 06:50
PyHDFS test
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Script to test WebHDFS (pyhdfs python lib)
2015-04-21
"""
import argparse
import sys
import os
import re
@gruzovator
gruzovator / py-logging-config-example.py
Created May 5, 2015 05:27
Python logging configuration exqample
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" source: http://www.lexev.org/en/2013/python-logging-every-day/
Settings for root logger.
Log messages will be printed to console and also to log file (rotated, with
specified size). All log messages from used libraries will be also handled.
Three approaches for defining logging settings are used: