Skip to content

Instantly share code, notes, and snippets.

View balintfodor's full-sized avatar

Bálint Fodor balintfodor

View GitHub Profile
@balintfodor
balintfodor / TurnTableCameraController.cpp
Created August 19, 2018 08:24
exposing camera class in qt for qml
#include "TurnTableCameraController.h"
#include <QtMath>
#include <algorithm>
using namespace std;
TurnTableCameraController::TurnTableCameraController(Qt3DCore::QNode *parent)
: m_mouseDevice(new Qt3DInput::QMouseDevice()),
m_mouseHandler(new Qt3DInput::QMouseHandler()),
m_camera(nullptr),
@balintfodor
balintfodor / TurnTableCameraController.h
Created August 19, 2018 08:23
exposing camera class in qt for qml
#ifndef _TurnTableCameraController_h_
#define _TurnTableCameraController_h_
// TODO: forward declare
#include <Qt3DRender/QCamera>
#include <Qt3DInput/QMouseDevice>
#include <Qt3DInput/QMouseHandler>
#include <Qt3DInput/QMouseEvent>
#include <Qt3DLogic/QFrameAction>
@balintfodor
balintfodor / generate_qrc_records.sh
Created August 19, 2018 08:21
generate qt resource file (.qrc) records by scanning the current directory recursively
find . -type f \( -name "*.qml" -o -name "qmldir" -o -name "*.vert" -o -name "*.frag" -o -name "*.geom" \) | sed -e "s/\(.*\)/<file>\1<\/file>/" | pbcopy
void writePGM(const Image& image, std::string fname)
{
ofstream ofile;
ofile.open(fname + ".pgm");
ofile << "P2\n" << image.dim(0) << " " << image.dim(1) << "\n255\n";
int c = 0;
for (int i = 0; i < image.dim(0); ++i) {
for (int j = 0; j < image.dim(1); ++j) {
ofile << (int)(image.data[c++]) << " ";
@balintfodor
balintfodor / try-catch-function-decorator.cpp
Created April 19, 2018 08:14
member function decoration with try-catch and fallback return value
#include <iostream>
#include <string>
#include <stdexcept>
template <typename T, typename R, typename... Args, typename... Args2>
R decorateTryCatch(R(T::*f)(Args...), T& inst, R&& returnValueOnError, Args2&&... args)
{
try {
return (inst.*f)(std::forward<Args2>(args)...);
} catch (std::exception& e) {
@balintfodor
balintfodor / touchcpp
Created January 9, 2018 10:20
creates a .cpp .h pair and defines the header guard
#!/bin/bash
echo "The script that creates the header file (*.h) and source (*.cpp)."
if [ "$1" = "" ]; then
echo "Paramaters not exist!!!";
exit 1;
fi
@balintfodor
balintfodor / hackerrank_image_from_stdin.py
Created June 22, 2017 09:53
hackerrank image from stdin
import numpy as np
import sys
def image_from_stdin():
row_list = []
for line in sys.stdin:
row = line.split()
col_list = []
for r in row:
col_list += [r.split(',')]
@balintfodor
balintfodor / console-colors.sh
Created January 7, 2017 18:15
terminal colors
#!/usr/bin/python
def set_rgb(r, g, b):
i = (r * 6 + g) * 6 + b + 16
return "\x1b[38;5;%dm" % i
def set_reset():
return "\x1b[0m"
r, g, b = [0, 2, 0]
@balintfodor
balintfodor / lwgetopts.hpp
Created April 20, 2016 11:40
lightweight getopts-like argument parser
#ifndef __lwgetopts_hpp__
#define __lwgetopts_hpp__
#include <string>
#include <exception>
#include <vector>
#include <map>
#include <iostream>
namespace lwgetopts {
@balintfodor
balintfodor / parse-interval.cpp
Created January 4, 2016 10:50
Parse strings representing intervals
#include <iostream>
#include <regex>
#include <set>
#include <limits>
#include <boost/icl/interval_set.hpp>
// We want to parse strings that represents a list of intervals like:
// 1,8-17,5,31-,
// to get the intervals [1,2],[5,6],[8,17],[31,inf]
// Ensure that the last character is a ',' at end of the string