Skip to content

Instantly share code, notes, and snippets.

View dataPulverizer's full-sized avatar

dataPulverizer dataPulverizer

View GitHub Profile
@dataPulverizer
dataPulverizer / ctseq.md
Last active May 6, 2022 11:09
Introduction to programming with compile time sequences in D

Introduction

Compile time sequences in D are insane, not insane "crazy" but insanely interesting. One of the selling points of D is that it takes compile time programming in C++ to another level, where templates in C++ were a 'happy?' accident, in D they were purposely built into the language along with other generic and meta-programming tools. To highlight this aspect of the D language, we will implement a selection of templates to manipulate compile time sequences of types, only the text function from the standard library in the std.conv module will be imported which is for concatenating text, we will build everything else including AliasSeq and Nothing from the std.meta module which they are easy one-liners.

This article builds on the concepts of a

@dataPulverizer
dataPulverizer / kernelmatrix.chpl
Last active May 26, 2020 08:00
Superceded, please disregard. Chapel Kernel Matrix Benchmark (WIP)
use CPtr;
use Math;
record DotProduct {
type T;
proc kernel(xrow:c_ptr, yrow:c_ptr(?T), p: int): T
{
var ret: T = 0: T;
for i in 0..#p {
ret += xrow[i] * yrow[i];
@dataPulverizer
dataPulverizer / byteOrder.nim
Last active May 8, 2020 19:13
Endian functions for Nim
#[
Byte order functions for Nim intendend for 2, 4, 6, 8, 16 - byte basic types
]#
#[ Basic functions for in-place reversing bytes 2, 4, 6, 8, 16 ]#
proc reverse2(x: var array[0..1, byte]): void {.inline.} =
var tmp: byte = x[0];
x[0] = x[1];
x[1] = tmp;
@dataPulverizer
dataPulverizer / paralleldemo.d
Created February 17, 2020 10:21
Basic use of std.parallelism in D
/*
Basic use of std.parallelism in D to play with it before
using it in my library.
*/
import std.parallelism;
import std.random : Mt19937_64, unpredictableSeed, uniform01;
import std.math : exp, log;
import std.range : iota;
import std.array: array;
import std.stdio: writeln;
@dataPulverizer
dataPulverizer / BinaryFileIO.jl
Last active January 20, 2023 15:42
Binary file i/o in Julia
# Write binary file
function write_bin(x::Array{T, 1}, fileName::String)::Int64 where T
# Open the file
io = open(fileName,"w")
# Cast this number to make sure we know its type
write(io, Int64(size(x)[1]))
# Get the type as a string
@dataPulverizer
dataPulverizer / RegularExpressionsInJulia.jl
Created February 17, 2018 02:53
Regular Expressions In Julia
#=
Notes on Regular expressions in Julia:
Sources:
Regular Expressions Cookbook, Jan Goyvaerts & Steven Levithan.
https://www.regular-expressions.info/wordboundaries.html
https://www.regular-expressions.info/lookaround.html
http://www.rexegg.com/regex-disambiguation.html
Julialang Gitter Chat.
=#
@dataPulverizer
dataPulverizer / delegates.jl
Created December 12, 2017 22:02
Delegates in Julia
# Delegates in Julia
function makeFun(x::Float64)
return y::Float64 -> y^2 + x^2
end
ff = makeFun(4.0)
# (generic function with 1 method)
ff(5.0)
# 41.0
@dataPulverizer
dataPulverizer / JuliaWishList.jl
Last active December 12, 2017 12:13
Julia features wishlist
#==
Feature wish list for julia in no particular order:
==#
"1. Immutable members of mutable types, something like:"
mutable struct myType
immutable x::Int64 # to break all that old code! :-)
end