Skip to content

Instantly share code, notes, and snippets.

View brendanzab's full-sized avatar
😵‍💫
writing elaborators

Brendan Zabarauskas brendanzab

😵‍💫
writing elaborators
View GitHub Profile
@jackrusher
jackrusher / logic-triples.clj
Created August 30, 2013 06:27
Transitive properties in a toy triple store using Clojure's core.logic.
(defrel triple ^{:index true} s ^{:index true} p ^{:index true} o)
(facts triple [[:Berlin :is-a :city]
[:city :is-a :permanent-settlement]
[:Berlin :part-of :Germany]
[:Germany :part-of :EU]
[:EU :part-of :Eurasia]
[:Eurasia :part-of :Earth]])
(run* [q] (triple q :is-a :city))
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef int i; //Save space by using 'i' instead of 'int'
typedef float f; //Save even more space by using 'f' instead of 'float'
//Define a vector class with constructor and operator: 'v'
struct v {
f x,y,z; // Vector has three float attributes.
@cnd
cnd / gist:7098985
Last active December 26, 2015 05:09
use std::task;
use std::rt::io::timer::sleep;
///<Summary>
///Simple butterfly
///</Summary>
pub fn butterfly<U>(f: &fn() -> U) -> U {
let (port, chan) = stream();
do task::spawn_sched(task::SingleThreaded) {
print(" ");
@Fristi
Fristi / Aggregate.hs
Last active December 21, 2024 10:17
DDD/Event Sourcing in Haskell. Implemented an aggregate as a type class and type families to couple event, command and error types specific to the aggregate. Errors are returned by using Either (Error e) (Event e). Applying Applicative Functors fits here well to sequentially check if the command suffice.
{-# LANGUAGE TypeFamilies #-}
import Data.Function (on)
import Control.Applicative
data EventData e = EventData {
eventId :: Int,
body :: Event e
}
@r-lyeh-archived
r-lyeh-archived / compo.cpp
Last active December 9, 2019 06:28
Component-entity system in 16 lines of C++11. extract from kult engine (https://github.com/r-lyeh/kult)
#include <map> // Component-entity system in 16 lines of C++11. 2013 rlyeh, MIT licensed
#include <set> // Code fragment from kult engine - https://github.com/r-lyeh/kult
enum {JOIN,MERGE,EXCLUDE};using set=std::set<unsigned>;template<typename T> set&system(){
static set entities;return entities;}template<typename T,int MODE>set subsystem(const set
&B){set newset;const set&A=system<T>();if(MODE==MERGE){newset=B;for(auto&id:A)newset.ins\
ert(id);}else if(MODE==EXCLUDE){newset=B;for(auto&id:A)newset.erase(id);}else if(A.size()
<B.size()){for(auto&id:A)if(B.find(id)!=B.end())newset.insert(id);}else{for(auto&id:B)if(
A.find(id)!=A.end())newset.insert(id);}return newset;}template<typename T>std::map<unsig\
ned,T>&components(){static std::map<unsigned,T>objects;return objects;}template<typename\
T>bool has(unsigned id){return components<T>().find(id)!=components<T>().end();}templat\
@XVilka
XVilka / TrueColour.md
Last active April 14, 2025 13:32
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!

@jackrusher
jackrusher / negative-space.clj
Last active October 15, 2024 10:38
Clojure, Haskell and OCaml implementations of the same algorithm, which is a negative space finder for a very constrained situation involving nested rectangles. For those interested in a more comprehensive take on these relationships (using scheme rather than clojure), see: http://lambda.jimpryor.net/translating_between_ocaml_scheme_and_haskell/
(def parent {:x1 0 :y1 0 :x2 600 :y2 400})
(def rs [{:x1 0 :y1 0 :x2 300 :y2 200 }
{:x1 0 :y1 200 :x2 300 :y2 400 }])
(defn negative-space [parent rs]
(let [x (apply max (map :x2 rs))
y (apply min (map :y1 (filter (comp (partial = x) :x2) rs)))]
{:x1 x :y1 y :x2 (parent :x2) :y2 (parent :y2)}))
(negative-space parent rs)
@emberian
emberian / links.md
Last active December 17, 2024 08:23
PL Theory etc
@gelisam
gelisam / IdiomaticLens.hs
Last active September 7, 2017 13:07
Idiomatic Lens
-- in reply to http://www.reddit.com/r/haskell/comments/23uzpg/lens_is_unidiomatic_haskell/
--
-- What the lens library might look like if Getter, Setter, Fold, Traversal,
-- Lens, Review, and Prism were separate datatypes.
--
-- For each optic, I only define enough combinators to explore pairs/sums
-- and lists of integers. Whenever possible, I reimplement the same
-- combinators and the same examples with all optics.
module IdiomaticLens where
@jozefg
jozefg / closconv.lhs
Last active April 2, 2025 03:08
Tutorial on Closure Conversion and Lambda Lifting
This is my short-ish tutorial on how to implement closures in
a simple functional language: Foo.
First, some boilerplate.
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-}
> import Control.Applicative
> import Control.Monad.Gen
> import Control.Monad.Writer
> import Data.Functor.Foldable