Skip to content

Instantly share code, notes, and snippets.

View hugmanrique's full-sized avatar

Hugo Manrique hugmanrique

View GitHub Profile
@hugmanrique
hugmanrique / Splash.qml
Last active January 15, 2023 23:18
Simple KDE Splash screen that displays a background image (ideally the desktop wallpaper)
/*
SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2023 Hugo Manrique <contact@hugmanrique.me>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.5
import QtQuick.Window 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
@hugmanrique
hugmanrique / SETUP.md
Last active September 4, 2022 02:25
How to install and interface with LAPACK from a C++ project

Installation

To install BLAS and LAPACK on a Debian-based system, run

$ sudo apt install libblas-dev liblapack-dev

The LAPACKE library provides a C interface to LAPACK, and can be installed using

$ sudo apt install liblapacke-dev
@hugmanrique
hugmanrique / LICENSE
Last active August 26, 2022 01:55
What's the cardinality of the intersection of the English dictionary and npm package names?
MIT License
Copyright (c) 2022 Hugo Manrique
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
use anyhow::Result;
use bluer::Address;
use std::collections::HashSet;
use std::fs::{File, OpenOptions};
use std::io::{ErrorKind, Read, Write};
use std::ops::Deref;
use std::path::PathBuf;
/// A set of paired device addresses, backed by a file.
pub struct PairedDevices {
@hugmanrique
hugmanrique / bezier_cubic_splines.m
Created August 28, 2021 21:03
Piecewise cubic Bézier curve interpolation
clear;
f = @(x) cos(x);
xa = 0;
xb = 2 * pi;
n = 4; % number of cubic polynomials
x = linspace(xa, xb, n + 1); % x_0, ..., x_n
y = f(x); % y_0, ..., y_n
@hugmanrique
hugmanrique / isPerfect.js
Last active January 30, 2021 21:03
Checks if a number is perfect
// Every perfect number is represented as p one bits followed by (p - 1) zero bits,
// where p is a Mersenne prime.
// Let x be the largest `MAX_BITS`-bit perfect number. Then ceil(log2(x)) = p + (p - 1).
const MAX_BITS = 32; // Bitwise operators operate on 32-bit integers
const MAX_ONES = Math.floor((MAX_BITS + 1) / 2); // upper bound on p
// Precomputed list of all prime m <= p s.t. 2^m - 1 is prime.
// TODO Compute automatically.
const MERSENNE_EXPS = new Set([2, 3, 5, 7, 13]);
@hugmanrique
hugmanrique / MemoryAccessBenchmark.java
Last active January 1, 2021 23:34
Panama (3-b385) MemoryAccess vs Unsafe vs ByteBuffer on the heap
package me.hugmanrique.mab;
import static jdk.incubator.foreign.MemoryLayouts.JAVA_INT;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import jdk.incubator.foreign.MemoryAccess;
import jdk.incubator.foreign.MemorySegment;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@hugmanrique
hugmanrique / adapsimpson2.m
Last active November 17, 2020 11:34
Adaptive Simpson's rule for a bivariate function
clear;
T = 7;
f = @(x, y) exp(-T * (x.^2 - y.^2)) - exp(-T * (x.^2 + y.^2));
xa = 0;
xb = 2;
ya = 0;
yb = 3;
S = adapsimpson2(f, xa, xb, ya, yb, 1.e18)
@hugmanrique
hugmanrique / svd.m
Created April 28, 2020 12:23
Toy program to compress greyscale images using a singular value decomposition
clear;
RGB = imread('escher.jpg');
I = double(rgb2gray(RGB));
[m, n] = size(I);
[V, S, W] = svd(I);
% Achieves a 2.04 compression ratio while still being visible
slimit = mean(mean(S)) + 4 * std(std(S));
@hugmanrique
hugmanrique / jekyll-transclude.rb
Last active November 17, 2020 11:41
Jekyll Liquid block that allows includes with content
# frozen_string_literal: true
# Based on https://github.com/jekyll/jekyll/blob/master/lib/jekyll/tags/include.rb,
# provides a transclude block that maintains Jekyll include semantics. Files can
# pass parameters to transcludes via the `include` object, with the addition of
# {{ include.content }} which includes the block content.
#
# Transcludes must be located in Jekyll's _includes dir.
#
# Example: