Skip to content

Instantly share code, notes, and snippets.


Hugo Manrique hugmanrique

View GitHub Profile
hugmanrique / LICENSE
Created Jul 3, 2022
What's the size 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 / bezier_cubic_splines.m
Created Aug 28, 2021
Piecewise cubic Bézier curve interpolation
View bezier_cubic_splines.m
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 / 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 /
Last active Jan 1, 2021
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 / adapsimpson2.m
Last active Nov 17, 2020
Adaptive Simpson's rule for a bivariate function
View adapsimpson2.m
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 / svd.m
Created Apr 28, 2020
Toy program to compress greyscale images using a singular value decomposition
View svd.m
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 / 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,
# 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:
# Required:
# fonttools, zopfli, installable via pip install.
set -e
FORMATS=(woff woff2)
View VelocityFlowchart.mmd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.