Skip to content

Instantly share code, notes, and snippets.

@ruffianeo
ruffianeo / prioqueuebug.cpp
Created May 4, 2021 21:12
c++ priority queue with std::deque and custom compare function -> segmentation fault
// compile with: clang++ -O3 -std=c++20 -o pqbug prioqueuebug.cpp
#include <iostream>
#include <random>
#include <string>
#include <cctype>
#include <forward_list>
#include <deque>
#include <queue>
@ruffianeo
ruffianeo / gist:01b9fabf9413e6dc671e68ae1b61f2e4
Last active September 23, 2020 14:22
(scan-variation) behaves strangely
(in-package :pgn-tools)
(defun read-file (infile)
(with-open-file (instream infile
:direction
:input :if-does-not-exist nil)
(when instream
(let ((string (make-string (file-length instream))))
(read-sequence string instream)
string))))
@ruffianeo
ruffianeo / Program.cs
Created July 4, 2020 08:16
Twitch - Shahsquatch - Java data structures on array - C# version.
using System;
using BDSApp.BDS;
namespace BDSApp
{
class Program
{
static void AssertEq<T>(T a, T b) where T : IEquatable<T>
{
if (!a.Equals(b))
@ruffianeo
ruffianeo / pollard.hs
Last active June 22, 2020 21:34
Pollard Rho according to wikipedia in haskell...
{-# LANGUAGE ScopedTypeVariables #-}
pollard :: (Integral p, Eq p) => p -> Maybe p
pollard n =
calc 2 2 1
where
-- calc :: p -> p -> p -> Maybe p
calc x y (1 :: p) =
let x' = g x
y' = g (g y)
d' = gcd (abs (x' - y')) n in
@ruffianeo
ruffianeo / mandelbench.c
Created February 6, 2020 03:09
Mandelbrot C - edition... with 2 versions in one: single threaded and multi-threaded.
#define _CRT_SECURE_NO_WARNINGS
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
static
size_t
number_of_physical_cores
@ruffianeo
ruffianeo / sbcl_mandel.lisp
Created February 6, 2020 02:55
not a LISP pro yet... so it might be a bit unidiomatic around the nether regions...
(declaim (optimize speed (safety 0)))
(eval-when (:compile-toplevel :load-toplevel :execute)
(load "qpc.fasl"))
(eval-when (:compile-toplevel :load-toplevel :execute)
(load "utilities.fasl"))
(defun grid-2d (n1 n2)
"grid-2d :: Int -> Int -> Lambda ( Func 'a )
where
Func :: 'a -> Int -> Int -> Int -> Int -> 'a
@ruffianeo
ruffianeo / ml_mandel.ml
Created February 6, 2020 02:39
ML Mandelbrot as "benchmarking" tool. Not written to be utterly efficient - more as a work load which can be easily ported to other languages.
open Bytes
open Char
open Complex
let with_binary_output filename handler =
let ch = open_out_bin filename in
let result = handler ch in
flush ch;
close_out ch;
result
@ruffianeo
ruffianeo / test_custom_heap_allocator.cpp
Last active December 24, 2019 08:32
"Hardcore" test case for C++17 MSVC with C++17 language settings for a custom heap allocator implementation.
#include <windows.h>
#include <vector>
#include <stack>
#include <variant>
#include <memory>
template<typename T>
struct custom_heap_allocator
{
using value_type = T;
@ruffianeo
ruffianeo / FancyCpp.cpp
Created September 21, 2018 15:03
Lazy C++ with stateful Enumerator and referentially transparent lambdas. FizzBuzz included ;)
#include "stdafx.h"
#include <cstdint>
#include <functional>
#include <stdexcept>
#include <string>
#include <tuple>
#include <iostream>
#include <limits>
#include <vector>
@ruffianeo
ruffianeo / JSONBuilderDev.cpp
Last active June 21, 2023 04:57
Demo of easy-to-use JSON document construction in modern C++.
// BSD like license: You cannot put this code under viral licenses or claim sole ownership of it.
// It is public domain and anyone may use it as long as they do not mess with others, using it.
// JSONBuilderDev.cpp : Defines the entry point for the console application.
// To run it on on unix systems, get rid of precompiled header include (first include) and add
// a few more stl headers.
// This code showcases how to create a JSON document builder which is easy to use.
// - 2 hours of coding.