Skip to content

Instantly share code, notes, and snippets.

View mre's full-sized avatar
🪴
I like plants

Matthias Endler mre

🪴
I like plants
View GitHub Profile
@mre
mre / bitonic_sort.cu
Last active October 15, 2025 18:47
Bitonic Sort on CUDA. On a quick benchmark it was 10x faster than the CPU version.
/*
* Parallel bitonic sort using CUDA.
* Compile with
* nvcc -arch=sm_11 bitonic_sort.cu
* Based on http://www.tools-of-computing.com/tc/CS/Sorts/bitonic_sort.htm
* License: BSD 3
*/
#include <stdlib.h>
#include <stdio.h>
@mre
mre / types_crate.md
Created May 16, 2025 23:08
Are Type Crates an Antipattern?

Why you think it's an anti-pattern to have a "types" crate?

Discussion at: https://fosstodon.org/@ianthetechie/114517520321760826

That's a fair question. What I found is that "types" is a bit of a scapegoat for things that have a proper place yet, similar to "utils", "shared." The types crate tends to become a dumping ground for types that don't have a fixed place yet. Code in those crates is not really "discoverable" as in: I would have to look into the crate to see what's in there and how it relates to the rest of the codebase.

For example, the standard library has a bunch of primitive types, but they all live in their own module in the core crate. The rest lives close to the supporting code, e.g. see the structs in std::process (https://doc.rust-lang.org/std/process/index.html#structs). If these structs were all in the types crate, it would make the code and the documentation a lot harder to navigate in my opinion.

@mre
mre / main.rs
Created March 9, 2018 01:15
A simple clone of `ls -l` in Rust
extern crate chrono;
extern crate libc;
#[macro_use]
extern crate structopt;
use std::fs;
use std::path::PathBuf;
use std::error::Error;
use std::process;
use std::os::unix::fs::PermissionsExt;
// This is an algorithm, which creates an ID for a podcast episode.
// It is based on the the podcast's title, episode's title, the episode number,
// the date of the episode and the episode's mp3 file name.
//
// All fields can change over time, but the ID should remain the same.
// Think of it more like a user agent string than a unique ID: it is "unique
// enough" for identifying episodes in most cases.
//
// It's used to identify episodes in the database.
@mre
mre / radixsort.py
Created July 10, 2012 12:54
Radix Sort implementation in Python
from math import log10
from random import randint
def get_digit(number, base, pos):
return (number // base ** pos) % base
def prefix_sum(array):
for i in range(1, len(array)):
array[i] = array[i] + array[i-1]
return array
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mre
mre / gist:64672c481f8f1232d468e3e7169f4f77
Created September 27, 2017 11:23
Make a change in a composer vendor folder and push to branch
# Go into the directory of the vendor package that you changed
cd vendor/<owner>/<package>
# Create a new git repository (composer does not check out the full git repo by default. Only a sparse copy)
git init
# Create a new branch for your local changes
git checkout -b branchname
# Commit changes
@mre
mre / top2.json
Created January 4, 2021 22:05
Top Github Users by followers October 2020
[
{
"data": {
"search": {
"userCount": 2646,
"edges": [
{
"node": {
"login": "torvalds",
"followers": {
@mre
mre / fizzbuzz.rs
Created October 25, 2017 20:48
Fizzbuzz in Rust
#![feature(generators)]
#![feature(generator_trait)]
use std::ops::{Generator, GeneratorState};
fn fizzbuzz_println(upto: u64) {
for i in 0..upto {
if i % 3 == 0 && i % 5 == 0 {
println!("FizzBuzz");
} else if i % 3 == 0 {