Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

Hugo Manrique hugmanrique

🙃
View GitHub Profile
@hugmanrique
hugmanrique / SETUP.md
Last active Sep 4, 2022
How to install and interface with LAPACK from a C++ project
View SETUP.md

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 Aug 26, 2022
What's the cardinality of the intersection of the English dictionary and npm package names?
View LICENSE
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:
View pairing.rs
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 Aug 28, 2021
Piecewise cubic Bézier curve interpolation
View bezier_cubic_splines.m
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 Jan 30, 2021
Checks if a number is perfect
View isPerfect.js
// 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 Jan 1, 2021
Panama (3-b385) MemoryAccess vs Unsafe vs ByteBuffer on the heap
View MemoryAccessBenchmark.java
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 Nov 17, 2020
Adaptive Simpson's rule for a bivariate function
View adapsimpson2.m
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 Apr 28, 2020
Toy program to compress greyscale images using a singular value decomposition
View svd.m
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 Nov 17, 2020
Jekyll Liquid block that allows includes with content
View jekyll-transclude.rb
# 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:
View optimizeFont.sh
#!/bin/bash
# Required:
# fonttools, zopfli, installable via pip install.
set -e
ORIGINAL=original.otf
UNICODES_FILE=unicodes.txt
FORMATS=(woff woff2)