Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

Hugo Manrique hugmanrique

🙃
View GitHub Profile
@hugmanrique
hugmanrique / regionfile-pr.md
Last active Oct 26, 2020
Paper PR about RegionFiles
View regionfile-pr.md

Currently, the RegionFile (line 52) class extends the file if it's size is not a multiple of 4KB, but does it in a inefficient way:

for(int i = 0; i < (this.file.length() & 0xfff); i++) {
        this.file.write(0);
}

That code could potentially cause up to 4095 file extensions, when we could just do them at once with the following code:

@hugmanrique
hugmanrique / Navbar.js
Last active Nov 18, 2022
Next.js Navbar component using the new React Hooks API
View Navbar.js
import React, { useState, useEffect } from 'react';
import Router from 'next/router';
import Link from 'next/link';
export default function Navbar({ brand, items }) {
const [activeIndex, setActiveIndex] = useState(-1);
useEffect(
() => {
const handleRouteChange = url => {
@hugmanrique
hugmanrique / detectMath.js
Created Dec 30, 2018
Next.js MathML feature detection + polyfill
View detectMath.js
import Router from 'next/router';
const namespaceURI = 'http://www.w3.org/1998/Math/MathML';
let supports = false;
let inserted = false;
function supportsMathML() {
const div = document.createElement('div');
div.innerHTML = '<math><mspace height="23px" width="77px" /></math>';
@hugmanrique
hugmanrique / findMinimum.js
Last active Jul 24, 2021
Multivariate (ℝ^2) relative minimum brute-force finder
View findMinimum.js
// The function we want to find the minimums of
// https://i.imgur.com/GG6uXvD.png
const getValue = (m, n) => m * m + n * n;
// The sampling interval (in ℝ^2)
let mStart = 0;
let nStart = 0;
let mEnd = 1;
let nEnd = 1;
@hugmanrique
hugmanrique / index.html
Last active Jun 12, 2019
Plot of a BivariateBeta(alpha_X, beta_X, alpha_Y, beta_Y) distribution (assumes X and Y are independent events)
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Plot</title>
</head>
<body>
<div id="plot"></div>
<script src="https://unpkg.com/@stdlib/stdlib@0.0.32/dist/stdlib-flat.min.js"></script>
@hugmanrique
hugmanrique / birthday.r
Created Jul 13, 2019
Birthday Paradox in R
View birthday.r
d = 365 # days
n = 100 # people
prob = function(i) { 1 - ((d - 1) / d)^(i * (i - 1) / 2)}
X <- seq(1, n, 1)
plot(prob(X), type="l")
prob(72)
# = 0.9990993
View BooleanFieldEnum.java
public enum BooleanFieldEnum {
// 2000 enum constants
private final boolean set;
BooleanFieldEnum() {
// Compute value on class loading, doesn't affect benchmark results
this.set = ThreadLocalRandom.current().nextBoolean();
}
@hugmanrique
hugmanrique / PackageInjector.java
Created Jul 29, 2019
Byte Buddy PackageInjector
View PackageInjector.java
import com.google.common.reflect.ClassPath;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.loading.ClassInjector;
import java.io.File;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.nio.file.Files;
View VelocityFlowchart.mmd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View optimizeFont.sh
#!/bin/bash
# Required:
# fonttools, zopfli, installable via pip install.
set -e
ORIGINAL=original.otf
UNICODES_FILE=unicodes.txt
FORMATS=(woff woff2)