Skip to content

Instantly share code, notes, and snippets.

@socantre
socantre / CMakeLists.txt
Created August 24, 2015 03:45
Example of using add_custom_command and add_custom_target together in CMake to handle custom build steps with minimal rebuilding: This example untars library headers for an INTERFACE library target
set(LIBFOO_TAR_HEADERS
"${CMAKE_CURRENT_BINARY_DIR}/include/foo/foo.h"
"${CMAKE_CURRENT_BINARY_DIR}/include/foo/foo_utils.h"
)
add_custom_command(OUTPUT ${LIBFOO_TAR_HEADERS}
COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/libfoo/foo.tar"
COMMAND ${CMAKE_COMMAND} -E touch ${LIBFOO_TAR_HEADERS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/foo"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libfoo/foo.tar"
@socantre
socantre / CMakeLists.txt
Last active November 7, 2022 19:44
CMake; download file with specific hash. Probably better to use ExternalProject module to do this instead of doing it manually
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/download.cmake
"set(downloaded_file \"${CMAKE_CURRENT_BINARY_DIR}/pg44800.txt\")\n"
"set(url \"https://www.gutenberg.org/cache/epub/44800/pg44800.txt\")\n"
"set(expected_hash \"5a837b40a0f90211ff2883651f33a865\")\n"
"if (EXISTS \${downloaded_file})\n"
" file(MD5 \${downloaded_file} filehash)\n"
" message(\"\${downloaded_file} exists with hash: \" \${filehash})\n"
" if (\${expected_hash} STREQUAL \${filehash})\n"
" message(\"Hash matches expected hash.\")\n"
@socantre
socantre / main.js
Created March 24, 2017 00:24
screeps room distance transform
function distanceTransform(roomName) {
let vis = new RoomVisual(roomName);
let topDownPass = new PathFinder.CostMatrix();
for (let y = 0; y < 50; ++y) {
for (let x = 0; x < 50; ++x) {
if (Game.map.getTerrainAt(x, y, roomName) == 'wall') {
topDownPass.set(x, y, 0);
}
else {
@socantre
socantre / deploy-iOS-app.md
Last active February 28, 2021 23:58
Over the air iOS app deployment notes

Steps to prepare over the air app deployment without paid apple developer account using Xcode 7:

@socantre
socantre / gist:3472964
Created August 26, 2012 01:26
bit_cast
#include <cstring> // memcpy
#include <type_traits> // is_trivially_copyable
// http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h?view=markup
// bit_cast<Dest,Source> is a template function that implements the
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in
// very low-level functions like the protobuf library and fast math
// support.
//
@socantre
socantre / foil_optimizer.cpp
Last active August 11, 2019 17:36
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" functions to disable compiler optimization
static void escape(void *p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}
@socantre
socantre / clone_llvm.sh
Created October 10, 2014 20:21
clone llvm
git clone http://llvm.org/git/llvm.git
cd llvm/projects
git clone http://llvm.org/git/compiler-rt.git
git clone http://llvm.org/git/libcxx.git
cd ../tools
git clone http://llvm.org/git/lld.git
git clone http://llvm.org/git/clang.git
cd clang/tools
git clone http://llvm.org/git/clang-tools-extra.git extra
cd ../../../../..
@socantre
socantre / wasapi_test.cpp
Last active November 12, 2018 09:23
Test with windows audio API
#define NOMINMAX
#include "scoped_resource.h"
#include <Audioclient.h>
#include <atlbase.h>
#include <audiopolicy.h>
#include <mmdeviceapi.h>
#include <chrono>
@socantre
socantre / type_name.cpp
Created February 3, 2013 17:09
"human readable" C++ types
#include <string>
#include <iostream> // cout
#include <cstdint> // intmax_t
#include <typeinfo>
#include <memory> // unique_ptr
#include <cstdlib> // free
#include <cxxabi.h> // __cxa_demangle
extern "C" template<typename T> using c_linkage = T;
@socantre
socantre / regions.lua
Last active September 30, 2017 20:12
regions.lua composing bitmaps
local module = {}
function module.circle(cx, cy, radius)
return function(x, y) return (x - cx)^2 + (y - cy)^2 < radius^2 end
end
function module.halfspace(rise, run, x0, y0)
return function(x, y) return run*(y - y0) < rise*(x - x0) end
end