Skip to content

Instantly share code, notes, and snippets.

View Kuxe's full-sized avatar

Joakim Thorén Kuxe

  • Sweden, Gothenburg
View GitHub Profile
@Kuxe
Kuxe / rofi-code-workspaces.sh
Last active October 6, 2022 00:03
A script that allows you to open workspaces in Code - OSS via rofi, e.g: "rofi -modes drun,window,code-workspaces:~/bin/code-workspaces.sh -show drun". You need ripgrep and awk available in $PATH.
#!/bin/bash
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
@Kuxe
Kuxe / levenshtein.hpp
Last active February 10, 2018 12:50
Computes levenshtein distance between two char pointers
#include <algorithm> //std::min, std::max
#include <cctype> //tolower
#include <array> //std::array
//Computes levenshtein-distance between two strings recursivly using dynamic programming
template<size_t MAX_STR_LEN>
constexpr static size_t levenshtein(const char* a, const char* b, const size_t len_a, const size_t len_b, std::array<std::array<size_t, MAX_STR_LEN>, MAX_STR_LEN>&& memo = {{0}}) {
return memo[len_a][len_b] != 0 ? memo[len_a][len_b] :
len_a == 0 ? memo[len_a][len_b] = len_b :
len_b == 0 ? memo[len_a][len_b] = len_a :
@Kuxe
Kuxe / node.hpp
Last active June 12, 2023 21:51
Generic tree class in C++ with some useful transforms
#ifndef NODE_HPP
#include <vector>
#include <stack>
#include <functional>
#include <list>
#include <iterator>
#include <type_traits>
/** A class representing an arbitrary tree **/
template<typename T>
@Kuxe
Kuxe / queue.hpp
Last active March 19, 2023 17:30
C++ implementation of a general semaphore and a thread-safe circular queue. I recommend refitting the queue class with the standard semaphore available in <semaphore> if you can use C++20.
#ifndef QUEUE_HPP
#define QUEUE_HPP
#include <cstdio>
#include "semaphore.hpp"
/** A thread-safe queue which supports one read-thread and one write-thread
manipulating the queue concurrently. In other words, the thread-safe queue can
be used in the consumer-producer problem with one consumer and one producer. **/
template<typename T>
@Kuxe
Kuxe / chaosgame.m
Last active May 1, 2017 15:39
Matlab script for generating a movie showing the "Chaos game" explained by Numberphile https://www.youtube.com/watch?v=kbKtFN71Lfs
clc;
clear;
% CONSTANTS
N_ITERS = 1000000;
IM_DIM = 1024;
N_VERTICES = [3, 4, 5, 7, 20, 50];
TOT_VERTS = length(N_VERTICES);
N_FRAMES_PER_FRACTAL = 30*3;
TOT_FRAMES = N_FRAMES_PER_FRACTAL * TOT_VERTS;