Skip to content

Instantly share code, notes, and snippets.

@donaldmunro
donaldmunro / copyFile
Created Jun 20, 2012 — forked from mrenouf/copyFile
Efficient file copy in Java (pre-JDK7)
View copyFile
public static void copyFile(File sourceFile, File destFile, final boolean isOverwrite) throws IOException {
if (destFile.isDirectory())
destFile = new File(destFile, sourceFile.getName());
if (destFile.exists())
{
if (isOverwrite)
destFile.delete();
else
throw new IOException(destFile.getAbsolutePath() + " exists");
}
@donaldmunro
donaldmunro / ExampleClassRoot.java
Created Jul 18, 2012
MyBatis Generator plugin to give query Example classes a common root class.
View ExampleClassRoot.java
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@donaldmunro
donaldmunro / features.cc
Last active Jan 10, 2016
Benchmark OpenCV Feature/Descriptor Extractors.
View features.cc
/*
Copyright (c) 2016, Donald Munro
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@donaldmunro
donaldmunro / gist:beb7f226adf9c585c67f2599384e43ab
Created Feb 24, 2017
Map OpenCv Mat to Eigen Matrix and calculate Eigenvectors
View gist:beb7f226adf9c585c67f2599384e43ab
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Eigenvalues>
..
..
using RowMatrixXf = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
Eigen::Map<RowMatrixXf> mapped(extended_homograpy.ptr<float>(), homography.rows, homography.cols);
Eigen::EigenSolver<Eigen::MatrixXf> eigen_solve(mapped, true);
auto ev = eigen_solve.eigenvectors();
std::cout << "No of EigenVectors = " << ev.cols() << std::endl;
for (auto i=0; i<ev.cols(); i++)
View gist:afa2f57bd4e52aa3cc0e3bbe422c889e
size_t split(std::string s, std::vector<std::string>& tokens,
std::string delim ="\t\n ")
{
tokens.clear();
size_t pos = s.find_first_not_of(delim);
while (pos != std::string::npos)
{
size_t next = s.find_first_of(delim, pos);
if (pos == std::string::npos)
tokens.emplace_back(s.substr(pos));
View gist:38841d72c65a1c32f2bf83a4a00a2c9a
#include <glm/gtx/string_cast.hpp>
..
..
glm::mat4 mat;
..
..
std::cout << glm::to_string(mat) << std::endl;
@donaldmunro
donaldmunro / gist:a2a0a061de498b9dc0ec10be309de2b7
Created Mar 5, 2017
Access/dereference glm::mat4 contents
View gist:a2a0a061de498b9dc0ec10be309de2b7
#include <glm/gtc/type_ptr.hpp>
..
glm::mat4 m = glm::mat4(1.0f);
..
auto p = glm::value_ptr(m);
std::cout << sizeof(p) << std::endl;
glUniformMatrix4fv(shader_uniform_m, 1, GL_FALSE, p);
@donaldmunro
donaldmunro / boost-android.md
Last active Nov 9, 2021
Compile Boost for Android
View boost-android.md

Compiling Boost for Android

  1. Download Boost and cd to base directory.

  2. Create Android toolchains for desired architectures by running a script as below:

    NDK=/opt/android-sdk/ndk-bundle/
    TOOLCHAINS="$PWD/toolchains/"

rm -rf $TOOLCHAINS

View kotlin-jni-javah.sh
# Using javah to generate .h files for Kotlin
# Assuming JNI function calls are in MainActivity.companion
STUDIO=/opt/android-studio
PACKAGE=my.package
$STUDIO/jre/bin/javah -jni -cp "$STUDIO/lib/kotlin-runtime.jar:build/tmp/kotlin-classes/debug" $PACKAGE.MainActivity.Companion
@donaldmunro
donaldmunro / bounded_map.h
Created Jan 26, 2019
A wrapped std::multimap which limits size by removing the smallest keys first. Useful for timestamped data where the oldest items (smallest timestamps) can be removed.
View bounded_map.h
#ifndef _BOUNDED_MAP_H
#define _BOUNDED_MAP_H
#include <iostream>
#include <map>
#include <vector>
#include <utility>
/**
* A wrapped std::multimap which limits size by removing the smallest keys first.