Skip to content

Instantly share code, notes, and snippets.

@kaoskorobase
kaoskorobase / allocator.cpp
Created January 20, 2019 11:31
Faust DSP factory table using custom allocator
#include <iostream>
#include <list>
#include <map>
class memory_manager {
public:
void* allocate(size_t n) { return new char[n]; }
void destroy(void* ptr) { delete[] static_cast<char*>(ptr); }
};
@kaoskorobase
kaoskorobase / main.cpp
Last active November 24, 2016 09:47
sodium-cxx event at time 0
#include "gtest/gtest.h"
#include <sodium/sodium.h>
#include <sodium/time.h>
using namespace sodium;
using namespace std;
using boost::optional;
using boost::make_optional;
@kaoskorobase
kaoskorobase / shake
Last active April 14, 2016 09:53
Our goto shake build script these days
#!/bin/sh -e
SHAKE_ARGS="-j"
which stack 1>/dev/null \
|| (echo "Please install stack from http://haskellstack.org" ; exit 1)
stack build # --no-system-ghc --install-ghc
# Note: `stack exec` is problematic on Windows because stack includes a separate MinGW environment.
# Execute build script directly instead.
@kaoskorobase
kaoskorobase / README.md
Last active March 12, 2017 07:59
Generating mobile application icons from SVG with Shake

Shake is quite amazing: powered by Haskell, it's really easy to quickly throw together build rules for little problems that appear in everyday programming tasks.

Here's a small snippet of Shake rules that convert an SVG to an iOS application icon in the various required sizes. As a bonus point, it generates icons for different build configurations by showing and hiding layers using inkscape-export-layers. See this article for how to use the different icons sets.

-- Generate iOS icons from SVG
iosIcons :: String -> Rules ()
iosIcons target = do
  let resolutions = [(29,[1,2,3]), (40,[1,2,3]), (50,[1,2]), (57,[1,2]), (60,[2,3]), (72,[1,2]), (76,[1,2])]
      configurations = [Beta, Debug, Release]
@kaoskorobase
kaoskorobase / 00-README.md
Last active October 30, 2015 11:43
Cont monad with error handling in C++

So I've been looking at the new NSURLSession API and imagining the tangled mess of delegate methods and completion blocks blurred my vision and made my head spin. After regaining my composure I remembered the wonderful world of Haskell monad transformer stacks and in particular I remembered two blog posts I came across some time ago ([1] and [2]) about restructuring nested callbacks with the Cont(inuation) monad. Digging further, I found an excellent [article][3] about the continuation monad in C++.

This is an attempt at generalizing some of the definitions, in particular making Cont (Continuator in the article) a typedef for a std::function and expanding the definition of bind to allow a change from one continuation argument type to another. I've also added error handling by wrapping the continuation arguments in a boost::variant; this is effectively