Skip to content

Instantly share code, notes, and snippets.

View bisqwit's full-sized avatar

Joel Yliluoma bisqwit

View GitHub Profile
@bisqwit
bisqwit / complexity_estimator.py
Last active December 23, 2023 18:44
Runtime complexity estimator
import numpy as np
import scipy
import traceback as tb
def latexnum(n, num_decimals=6):
s = "%.*g" % (num_decimals, n)
s = s.replace('e+', '\\cdot 10^{')
s = s.replace('e-', '\\cdot 10^{-')
if '{' in s: s += '}'
s = s.replace('.', '{,}')
<?php
/* Word-wrapping code from Simon’s Quest Multilingual Retranslation project
* Copyright © 2020 Joel Yliluoma — https://iki.fi/bisqwit/cv2fin/
*/
class WordWrapState
{
// Output state
var $x=0,$y=0, $outcome='';
// Input state
@bisqwit
bisqwit / recursion_exercise.cc
Last active July 12, 2019 01:18
Recursion exercise (C++17)
#include <utility>
/* https://godbolt.org/z/9ic5bL
A child couldn’t sleep, so her mother told a story about a little frog,
who couldn’t sleep, so the little frog’s mother told a story about a little bear,
who couldn’t sleep, so the little bear’s mother told a story about a little weasel
— who fell asleep;
… and the little bear fell asleep;
… and the little frog fell asleep;
… and the child fell asleep.
<?php
/* THIS SCRIPT EDITS *ALL* YOUTUBE VIDEOS BELONGING TO THE AUTHENTICATED USER,
* AND REPLACES http:// LINKS WITH https:// LINKS IN THE VIDEO DESCRIPTION.
* ONLY LINKS MATCHING A WHITELIST ARE MODIFIED (see preg_replace below).
* Copyright © 2018 Joel Yliluoma — https://iki.fi/bisqwit/
* License: MIT
*/
/* Note: You will need to create OAuth credentials at: https://console.developers.google.com/apis/credentials
@bisqwit
bisqwit / dijkstra.hh
Last active March 23, 2023 12:42
Dijkstra’s algorithm implementation (C++17 template code)
#include <unordered_map>
#include <type_traits>
#include <queue>
#include <vector>
#include <algorithm>
#include <optional>
/**
* \fn Dijkstra<DistanceType,NodeType>(firstnode, lastnode, for_all_neighbors_of, return_route)
* \brief Searches for the shortest route between nodes `firstnode` and `lastnode`.
@bisqwit
bisqwit / clamp_with_desaturation.hh
Created January 6, 2018 09:41
Clamp with desaturation (partial code)
// RGB to YUV conversion matrix
#define LUMA_COEFFICIENTS 0.29900, 0.58700, 0.11400
#define CHROMA1_COEFFICIENTS -0.14713, -0.28886, 0.43600
#define CHROMA2_COEFFICIENTS 0.61500, -0.51499, -0.10001
// YUV to RGB conversion matrix
#define R_YUV_COEFFICIENTS 1, 0.00000, 1.13983
#define G_YUV_COEFFICIENTS 1, -0.39465, -0.58060
#define B_YUV_COEFFICIENTS 1, 2.03211, 0.00000
template<typename VecType>
@bisqwit
bisqwit / .bashrc
Created October 5, 2017 06:55
From .bashrc
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
@bisqwit
bisqwit / runXterm.cc
Created October 5, 2017 06:54
My Xterm launcher script
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
#include <cstdio>
using namespace std;
/* saturation, value and hue all are 0..1 */
@bisqwit
bisqwit / textbox.hh
Last active December 8, 2023 00:32
Abstraction for 2-dimensional text strings with VT100 linedrawing support; and a tree structure visualizer function
#include <string>
#include <vector>
#include <algorithm>
/* textbox: Abstraction for 2-dimensional text strings, with VT100 linedrawing support */
/* Copyright (c) 2017 Joel Yliluoma - http://iki.fi/bisqwit/ */
/* License: MIT */
/* Requires a C++17 capable compiler and standard library. */
struct textbox
{
@bisqwit
bisqwit / transform_iterator.hh
Last active February 3, 2019 18:58
Add another example
#include <memory>
#include <iterator>
#include <typeindex>
/* Tiny transform_iterator for C++. Copyright 2018 © Joel Yliluoma - http://iki.fi/bisqwit/
* License: MIT
Example WITHOUT transform_iterator:
template<typename Func>