Skip to content

Instantly share code, notes, and snippets.

View chiroptical's full-sized avatar

Barry Moore chiroptical

View GitHub Profile
@chiroptical
chiroptical / fib.cpp
Last active December 20, 2017 20:10
Recursive fibonacci at compile time (protected from negative numbers blowing up compiler)
namespace impl {
template <int n, bool isPositive>
struct fib_impl {
static constexpr int val = fib_impl<n - 1, isPositive>::val + fib_impl<n - 2, isPositive>::val;
};
template <>
struct fib_impl<1, true> {
static constexpr int val = 1;
};
@chiroptical
chiroptical / fib-tailrec.cpp
Created December 20, 2017 22:34
Potentially Tail Call
template <int n, int prev, int next, bool isPositive>
struct fib_impl {
static constexpr int val = fib_impl<n - 1, next, prev + next, isPositive>::val;
};
template <int prev, int next>
struct fib_impl<0, prev, next, true> {
static constexpr int val = prev;
};
@chiroptical
chiroptical / reduce.cpp
Created April 23, 2018 15:05
Parallel STL Test with Intel Parallel Studio 2018
#include <cstdlib>
#include <iostream>
#include <vector>
#include <sstream>
#include "pstl/execution"
#include "pstl/algorithm"
#include "pstl/numeric"
#include "pstl/memory"
#include "tbb/task_scheduler_init.h"
import Data.List.Split (splitOn)
main :: IO ()
main = do
contents <- getContents
let path = minPath $ csv3ToRoadSecs (lines contents)
let repr = pictoralRepr (pathStr path)
-- Need to deal with last character
let lastRepr = foldPaths repr (prev repr)
print $ "Minimum distance travelled: " ++ show (pathDist path)
@chiroptical
chiroptical / strategy.py
Created January 11, 2019 17:37
Example ABC
#!/usr/bin/env python
from abc import ABCMeta, abstractmethod
class StorageStrategy(metaclass=ABCMeta):
@abstractmethod
def printSomething(self, something):
pass
class MongoDBStorageStrategy(StorageStrategy):
def printSomething(self, something):
@chiroptical
chiroptical / zero_norm_cross_correlation.cpp
Created February 8, 2019 18:58
Compute Zero-norm Cross-Correlations from Numpy Arrays
#include <iostream>
#include <valarray>
#include <sstream>
#include <fstream>
#include <string>
#include <numeric>
#include <cmath>
#include <chrono>
using namespace std;
#include <math.h>
typedef struct {
float mean;
float std;
} MeanStd_f;
float compute_mean_f(
const float *a,
const int *x_dim,
{-# LANGUAGE OverloadedStrings #-}
module SemVer where
import Control.Applicative
import Text.Trifecta
import Data.Maybe
data NumberOrString =
NOSS String
#!/usr/bin/env python3
import pandas as pd
import numpy as np
from pathlib import Path
from scipy import signal
from librosa import load
from sklearn.preprocessing import MinMaxScaler
from PIL import Image
@chiroptical
chiroptical / match.hs
Created September 7, 2019 19:05
Pattern matching example
getNeighborCellFromCell :: Maze -> Cell -> Direction -> Cell
getNeighborCellFromCell maze cell North = ...
getNeighborCellFromCell maze cell East = ...