Skip to content

Instantly share code, notes, and snippets.

View ramiroaisen's full-sized avatar

ramiroaisen ramiroaisen

  • 17:21 (UTC -03:00)
View GitHub Profile
@ramiroaisen
ramiroaisen / timeout_io.rs
Last active December 31, 2024 05:24
Tokio Timeout IO for use in Hyper servers
// [dependencies]
// pin_project = "1"
// tokio = { version = "1", features = "time" }
// hyper = { version = "1" }
use std::{pin::Pin, task::{Context, Poll}, time::Duration};
use std::future::Future;
use tokio::{io::{AsyncRead, AsyncWrite}, time::Sleep};
use pin_project::pin_project;
@ramiroaisen
ramiroaisen / birthday-problem.js
Created March 8, 2024 20:05
Birthday problem collision calculator in javascript
/**
* @param p {number} - The total number of different possibilities (days in a year)
* @param n {number} - The number of occurrences (number of people)
* @returns {number} - The probability of at least two people having the same birthday. @min 0 - @max 1
*/
export const birthday_problem = (p, n) => {
let acc = 1;
for(let i = 1; i < n; i++) {
acc *= (1 - ( i / p ));