Skip to content

Instantly share code, notes, and snippets.

{reverse, sum, empty, all, fold, concat-map, flatten, span, Obj, sort-by, head} = require 'prelude-ls'
# [[String]] -> Bool
in-order = (xss) -> all (-> it.length == 1), xss
# [[String] -> Data -> [[String]]] -> Data -> [String] -> [[String]]
order-by-one = (fs, d, xs) -->
| xs.length < 2 => [xs]
| otherwise =>
fold ((ys, f) -> if ys.length == 1 then f(ys[0], d) else ys), [xs], fs
@bzar
bzar / better.cc
Last active August 29, 2015 14:22
Muhkeimmat sanat
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <locale>
#include <codecvt>
#include <bitset>
@bzar
bzar / gist:b0fb12d97801ddf76c84
Last active August 29, 2015 14:16
N-dimensional hypercube single-solution maze generation algorithm with waypoints

Inputs

  • Maze dimensions as an N-vector containing size in each dimension
  • List of waypoints as N-vectors

Algorithm

  1. Define N-dimensional hypercube with given dimensions and intercell wall state
  2. Generate main path
import QtQuick 2.4
import QtQuick.Window 2.2
import goqml 1.0
Window {
visible: true
property var roles: ["bullet", "enemyBullet", "player"]
function getRole(name)
{
@bzar
bzar / E.js
Created January 26, 2015 18:04
function E(node) {
function isChildren(x) { return x instanceof Array; }
function isText(x) { return typeof x === "string"; }
if(!(node instanceof Array))
return node;
var element = node[0];
var props = null;
var text = null;
#!/bin/bash
COMMAND=$1
TESTLIST=$2
DONELIST=$3
touch "$DONELIST"
while read TEST; do
if [ -z "$TEST" ]; then
echo
#include <iostream>
#include <functional>
#include <vector>
using Cb = std::function<void()>;
using Cbs = std::vector<Cb>;
void print(Cbs& cbs)
{
auto n = cbs.size();
for(decltype(n) i = 0; i < n; ++i)
@bzar
bzar / gist:406cddabeff450e988cb
Created December 11, 2014 18:45
A tuple of containers with compile-time seek by type in C++
#include <iostream>
#include <vector>
#include <type_traits>
template<template<typename...> class Container, typename T, typename... Ts>
class ContainerTuple
{
public:
template<typename TT>
typename std::enable_if<std::is_same<T, TT>::value, Container<T>&>::type get()
@bzar
bzar / algebraic.cpp
Last active August 29, 2015 14:11
Algebraic datatype emulation in C++ (and the same in Rust)
#include <iostream>
#include <cassert>
#include <string>
// Algebraic type
enum ShapeType { CIRCLE, RECTANGLE, ZERO };
struct Circle { int cx, cy, r; static const ShapeType type = CIRCLE; };
struct Rectangle { int x, y, w, h; static const ShapeType type = RECTANGLE; };
struct Zero { static const ShapeType type = ZERO; };
@bzar
bzar / deaddrop.md
Last active April 14, 2016 11:49
Dead drop imaginary messaging server spec

Rationale

A centralized messaging system that should impart as little information as possible to any third parties, including the server administrator. Any information accessible by the server administrator is considered public as far as user security is concerned.

The server should be practical and attempt to disencourage unwanted behaviour like spamming. It should also have access control to allow private servers, but not at the cost of revealing message senders.