Skip to content

Instantly share code, notes, and snippets.

View hugoferreira's full-sized avatar

Hugo Sereno Ferreira hugoferreira

View GitHub Profile
const _ = require('lodash')
const tournaments = _.range(1, 100000)
const dieA = [1, 1, 4, 4, 4, 4]
const dieB = [3, 3, 3, 3, 3, 3]
const dieC = [2, 2, 2, 2, 5, 5]
const roll = (die) => _.sample(die)
const count = (as, e) => _.filter(as, (x) => x === e).length
<main class="container">
<section class="content">
<canvas class="canvas" id="canvas" resize></canvas>
</section>
</main>
@hugoferreira
hugoferreira / index.html
Created March 2, 2022 17:53
Paper.js - Setup Template
<main class="container">
<section class="content">
<canvas class="canvas" id="canvas" resize></canvas>
</section>
<footer class="footer">
<div class="footer__body">
<p class="footer__text">A template for quickly starting a PaperJS project. <span class="signature">-CH</span></p>
</div>
<nav class="footer__nav">
<a href="https://codepen.io/cooper_hu" target="_blank">Other Pens</a>
@hugoferreira
hugoferreira / PropositionalCalculus.ts
Last active January 10, 2022 19:39
Type-Level Propositional Calculus
// Primitives
type Theorem = string
type Parenthesis<T> = `(${T extends Theorem ? T : never})`
type P = 'P'
type Q = 'Q'
type R = 'R'
type And<A extends Theorem, B extends Theorem> = `(${A}&${B})`
type Or<A extends Theorem, B extends Theorem> = `(${A}|${B})`
@hugoferreira
hugoferreira / hvsync_generator.scala
Created November 18, 2021 22:20
Comparison of HVSync Generator in Chisel and Hand-written SystemVerilog
import chisel3._
def bits(x: Int) = Math.ceil((Math.log(x) / Math.log(2))).toInt
class hvsync_generator(
h_display: Int, h_back: Int, h_front: Int, h_sync: Int,
v_display: Int, v_top: Int, v_bottom: Int, v_sync: Int) extends Module {
val h_sync_start = h_display + h_front
val h_sync_end = h_display + h_front + h_sync - 1

YM2149

Frequency Calculation = CLK / 16 * TP

Equal-temperade scale

  • Lowest Possible Note: B0 (30.87Hz ~= 0xFD1)
  • Highest Possible Note: G#8 (6644.88Hz ~= 0x013)
  • Possible loss of accuracy; verify effective frequency with oscilloscope.
@hugoferreira
hugoferreira / books.md
Last active August 14, 2020 15:09
Living in/with modern times
@hugoferreira
hugoferreira / golf-1.md
Last active April 10, 2020 23:24
Code Golf Challenges

Challenge 1 (10/4/2020)

Implement a function that given a list of natural numbers, returns the lowest number not present in the list.

Premises

0 &lt;= list size &lt;= 2^16
import fc = require('fast-check')
import isArraySorted = require('is-array-sorted')
class AsyncSemaphore {
private promises = Array<() => void>()
constructor(private permits: number) {}
signal() {
this.permits += 1
@hugoferreira
hugoferreira / asyncqueue-test.ts
Last active April 2, 2019 01:33
Tests the behaviour of an AsyncQueue by doing a random permutation of Enqueues and Dequeues
const isArraySorted = require('is-array-sorted')
async function testAsyncQueueBehavior(nOps: number): Promise<Boolean> {
const result = new Array<number>()
const q = new AsyncQueue<number>()
const enqueue = (m: number) => q.enqueue(m)
const dequeue = () => q.dequeue()
const promises = Array<Promise<void>>()