Skip to content

Instantly share code, notes, and snippets.

View shotamatsuda's full-sized avatar

Shota Matsuda shotamatsuda

  • Takram
  • Tokyo, Japan
View GitHub Profile
@shotamatsuda
shotamatsuda / gist:597fa656808accf840a2
Created November 8, 2014 05:13
A script to bundle OpenCV in your applications
# (1) Add OpenCV's dynamic libraries you need to the pre-created "Link Binary
# With Libraries" build phase.
# (2) Make a "Copy Files" build phase, configure the destination to
# "Frameworks", then add all of the OpenCV's libraries you linked.
# (3) Make a "Run Script" build phase and copy and paste the script below.
pushd "$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH"
ls -F | grep -v "@$" | grep "libopencv" | while read; do
FILE=$REPLY
# Change the linked libraries to the copied ones
@shotamatsuda
shotamatsuda / gist:bbab93e6cc41716534fb
Created November 8, 2014 05:27
A class to make singletons in a fairly safe manner
//
// sgss/singleton_holder.h
//
// MIT License
//
// Copyright (C) 2014 Shota Matsuda
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
@shotamatsuda
shotamatsuda / gist:43015c9d02f7cab1c828
Last active August 29, 2015 14:08
Recursively bundle every linked library
readonly DESTINATION_DIR="@executable_path/../Frameworks"
follow_symlink() {
local file=$1
local target
target=$(readlink "${file}")
if [[ "${target}" ]]; then
local directory
directory=$(dirname "${file}")
file=$(follow_symlink "${directory}/${target}")
@shotamatsuda
shotamatsuda / thread_name.h
Last active August 29, 2015 14:13
Name the worker threads of boost’s threadpool
#include <cassert>
#include <condition_variable>
#include <cstddef>
#include <mutex>
#include <string>
#include "boost/threadpool.hpp"
void NameThisThread(const std::string& name);
takram::Line2d clip(const boost::polygon::voronoi_diagram<double>::edge_type& edge) {
const auto& cell1 = *edge.cell();
const auto& cell2 = *edge.twin()->cell();
takram::Vec2d origin, direction;
if (cell1.contains_point() && cell2.contains_point()) {
assert(cell1.source_category() == SOURCE_CATEGORY_SINGLE_POINT &&
cell2.source_category() == SOURCE_CATEGORY_SINGLE_POINT);
const auto& p1 = points_.at(cell1.source_index());
const auto& p2 = points_.at(cell2.source_index());
origin.x = (p1.x + p2.x) / 2.0;
#!/bin/sh
#
# boost.sh
#
# MIT License
#
# Copyright (C) 2015 Shota Matsuda
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@shotamatsuda
shotamatsuda / main.cpp
Created July 4, 2016 14:03
Concurrent partition
// Given
const auto size = ...;
auto begin = ...;
std::list<std::future<void>> futures;
const auto concurrency = std::thread::hardware_concurrency();
const auto partition = std::imaxdiv(size, concurrency);
for (int i{}; i < concurrency; ++i) {
const auto end = begin + partition.quot + (i < partition.rem);
futures.emplace_back(std::async([this, begin, end]() {
#include <ratio>
namespace detail {
template <class... Args>
struct RatioAdd;
template <class R1, class R2>
struct RatioAdd<R1, R2> {
using Type = std::ratio_add<R1, R2>;
#include <array>
#include "ratio.h"
template <
class A_, class B_, class C_,
class D_, class E_, class F_,
class G_, class H_, class I_
>
struct RatioMatrix {
import Namespace from '../core/Namespace'
const self = undefined
const internal = Namespace()
class Task {
constructor(semaphore, callback) {
const promises = [
new Promise((resolve, reject) => {
this.resolve = resolve