Skip to content

Instantly share code, notes, and snippets.

View kkaefer's full-sized avatar
🏳️‍🌈

Konstantin Käfer kkaefer

🏳️‍🌈
View GitHub Profile
@kkaefer
kkaefer / load_curl.cpp
Last active May 28, 2018 12:15
Load cURL dynamically at runtime to avoid CURL_OPENSSL_3 vs. CURL_OPENSSL_4 symbol version mismatches
#include <curl/curl.h>
// Dynamically load all cURL functions. Debian-derived systems upgraded the OpenSSL version linked
// to in https://salsa.debian.org/debian/curl/commit/95c94957bb7e89e36e78b995fed468c42f64d18d
// They state:
// Rename libcurl3 to libcurl4, because libcurl exposes an SSL_CTX via
// CURLOPT_SSL_CTX_FUNCTION, and this object changes incompatibly between
// openssl 1.0 and openssl 1.1.
// Since we are not accessing the underlying OpenSSL context, we don't care whether we're linking
// against libcurl3 or libcurl4; both use the ABI version 4 which hasn't changed since 2006
@kkaefer
kkaefer / changes.md
Last active May 15, 2018 08:16
N-API changes

v8.2.0:

  • NAPI_NO_RETURN
  • napi_fatal_error
  • napi_delete_property
  • napi_has_own_property
  • napi_delete_element

v8.3.0:

  • napi_create_error (changed)
@kkaefer
kkaefer / read_png.mm
Created July 6, 2015 16:39
Reading images
// Compile with:
// clang++ read_png.mm -framework ImageIO -framework CoreGraphics -framework CoreServices
#import <ImageIO/ImageIO.h>
int main() {
const unsigned char png[] = {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00,
@kkaefer
kkaefer / index.html
Created January 30, 2015 14:41
Pan SVG
<html>
<head>
<meta charset="utf-8">
<title>Pan SVG</title>
<script src="interaction.js"></script>
<style>
body {
font-family: Helvetica, Arial, sans-serif;
margin: 0;
#include <memory>
#include <type_traits>
#include <utility>
namespace util {
// C++14 backfill based on http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory
namespace detail {
template<class T> struct unique_type { typedef ::std::unique_ptr<T> single; };
@kkaefer
kkaefer / asserting_ptr.hpp
Last active August 29, 2015 14:06
std::shared_ptr and std::unique_ptr that assert presence of member pointer on dereferencing
#pragma once
#include <memory>
#include <cassert>
namespace {
template <template <typename...> class H, typename ...A>
class asserting_ptr : public H<A...> {
public:
@kkaefer
kkaefer / faster-sublimeclang.sh
Created June 16, 2014 08:40
Faster SublimeClang by using Xcode's libclang.dylib
#!/usr/bin/env bash
# Credits go to Dennis Luxen (https://twitter.com/DennisLuxen)
pushd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/SublimeClang/internals/
cp /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib .
cd ../src/build
make
popd
@kkaefer
kkaefer / inflate.js
Created May 13, 2014 09:01
CLI app for inflating files
#!/usr/bin/env node
var zlib = require('zlib');
var fs = require('fs');
var inflate = zlib.createInflate();
var input = process.stdin;
var output = process.stdout;
if (typeof process.argv[2] !== 'undefined') {
input = fs.createReadStream(process.argv[2]);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
// do stuff with unused parameters
#ifdef __clang__
#pragma clang diagnostic pop
#endif
@kkaefer
kkaefer / shared_ptr.hpp
Created April 19, 2013 14:23
Use std::shared_ptr without tr1 on glibc++ and libc++
#if defined(_LIBCPP_VERSION)
#include <memory>
#else
#include <tr1/memory>
namespace std { template <typename T> using shared_ptr = tr1::shared_ptr<T>; }
#endif