Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@redrabbit
redrabbit / mutable_bucket.ex
Last active June 29, 2017 22:44
Elixir mutable bucket via :ets
defmodule Bucket do
@moduledoc """
A mutable "bucket" implementing the `Access` behaviour.
"""
@behaviour Access
defstruct [:ets]
@type t :: %__MODULE__{ets: term}
@redrabbit
redrabbit / notification.cpp
Last active June 29, 2017 22:44
Generic C++ notification dispatcher with boost::signal2
#include <map>
#include <queue>
#include <typeinfo>
#include <iostream>
#include <boost/signals2/signal.hpp>
#include <boost/type_traits/is_base_of.hpp>
class notification_interface
@redrabbit
redrabbit / geometry.rs
Created June 29, 2017 22:47
Rust implementation of a Geometry trait (area, perimeter)
use std::fmt;
trait Geometry: fmt::Display {
fn perimeter(&self) -> f32;
fn area(&self) -> f32;
}
//
// Point
//
@redrabbit
redrabbit / opencv_threshold.c
Last active June 29, 2017 22:50
OpenCV thresholding
IplImage* createThresholding( IplImage* source, const CvScalar& min, const CvScalar& max )
{
const CvSize imgSize = cvSize( source->width, source->height );
IplImage* hsv = cvCreateImage( imgSize, 8, 3 );
cvCvtColor( source, hsv, CV_BGR2HSV );
IplImage* mask = cvCreateImage( imgSize, 8, 1 );
cvInRangeS( hsv, min, max, mask );
@redrabbit
redrabbit / recursive_path_iterator.ex
Created July 26, 2017 09:56
Lazy path iterator in Elixir
defmodule RecursivePathIterator do
@moduledoc """
This module provides a simple interface for iterating over filesystem directories.
"""
@doc """
Walks the given `path` recursively.
"""
@spec walk(Path.t) :: Enumerable.t
def walk(path) do

Keybase proof

I hereby claim:

  • I am redrabbit on github.
  • I am marioflach (https://keybase.io/marioflach) on keybase.
  • I have a public key ASAtsbkNpV5OCHoVw7r6FNG8j9qz_93f2bAmBmXffE14wgo

To claim this, I am signing this object:

readCopyInstruction :: (Integral a) => Word8 -> Get (a, a)
readCopyInstruction opcode = do
-- off -> offset in the source buffer where the copy will start
-- this will read the correct subsequent bytes and shift them based on
-- the set bit
offset <- foldM readIfBitSet 0 $ zip [0x01, 0x02, 0x04, 0x08] [0,8..]
-- bytes to copy
len' <- foldM readIfBitSet 0 $ zip [0x10, 0x20, 0x40] [0,8..]
let len = if coerce len' == 0 then 0x10000 else len'
-- FIXME add guard condition from `patch-delta.c`: if (unsigned_add_overflows(cp_off, cp_size) || ...
ERL_NIF_TERM
geef_object_zlib_inflate(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary bin;
char chunk[1024];
int error;
z_stream z;
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
@redrabbit
redrabbit / absinthe_ecto_resolution_schema.ex
Last active December 1, 2023 14:29
Absinthe.Ecto.Resolution.Schema
defmodule Absinthe.Ecto.Resolution.Schema do
@moduledoc """
This module provides helper functions to resolve a GraphQL query into `Ecto.Query`.
"""
import Absinthe.Resolution.Helpers
import Ecto.Query
alias Absinthe.Resolution
alias Absinthe.Blueprint.Document.Field