Skip to content

Instantly share code, notes, and snippets.

View estebanz01's full-sized avatar
🤓
I'm scared, I see data everywhere.

Esteban Zapata Rojas estebanz01

🤓
I'm scared, I see data everywhere.
View GitHub Profile
@estebanz01
estebanz01 / distances.ex
Last active July 30, 2023 15:29
Some distance metrics implemented in plain Elixir, with tests. Blog in spanish: https://estebanz.co/posts/distance-metrics-in-elixir/
defmodule Distances do
def euclidean(a, b) when length(a) > 0 and length(b) > 0 and length(a) == length(b) do
# We zip both lists into one, then we reduce it to the euclidean calculation.
# Enum.zip_reduce(a, b, 0, fn) <- as a shortcut.
Stream.zip(a, b)
|> Enum.reduce(0, fn {x, y}, accumulator ->
accumulator + (x - y) ** 2
end)
|> :math.sqrt()
end
@estebanz01
estebanz01 / Gemfile
Created December 18, 2021 02:54
Generate a hash with arbitrary depth and keys with fake information. Because why not.
source 'https://rubygems.org'
gem 'faker'
@estebanz01
estebanz01 / chat.css
Last active March 23, 2024 23:42
A chat with webworkers in it.
/*
* CSS chat
*/
body {
top: 0;
left: 0;
background-color: #caccd1;
margin-left: 35%;
margin-right: 35%;
We can't make this file beautiful and searchable because it's too large.
RADICADO,FECHA,HORA,DÍA DE LA SEMANA,CLASE DE VEHICULO,TIPO DE SERVICIO,TIPO DE VICTIMA,SEXO,ESTADO DE BEODEZ,RESULTADO DE BEODEZ,GRAVEDAD,CLASE DE ACCIDENTE,CAUSA,DIRECCIÓN,BARRIO,AREA,Coordenadas
2181714,06/30/2018,2:55 p.m.,sábado,TRACTOCAMION,PUBLICO,Conductor,Masculino,No,N/A,SOLO DAÑOS,Choque,No mantener distancia de seguridad,Carrera 48 Calle 50 Sur,LAS VEGAS,Urbana,
2181733,06/30/2018,9:50 a.m.,sábado,BUS,PUBLICO,Conductor,Masculino,No,N/A,SOLO DAÑOS,Choque,Desobedecer senales,Carrera 50 Calle 46 Sur,LAS VEGAS,Urbana,"(6.16131219, -75.603198185)"
2181733,06/30/2018,9:50 a.m.,sábado,AUTOMOVIL,PARTICULAR,Conductor,Masculino,No,N/A,SOLO DAÑOS,Choque,Desobedecer senales,Carrera 50 Calle 46 Sur,LAS VEGAS,Urbana,"(6.16131219, -75.603198185)"
2181717,06/30/2018,10:45 p.m.,sábado,MOTOCICLETA,PARTICULAR,Motociclista,Masculino,No,N/A,SOLO DAÑOS,Choque,Desobedecer senales,Calle 37 Sur Carrera 36,MESA,Urbana,"(6.168044613, -75.583236971)"
2181717,06/30/2018,10:45 p.m.,sábado,AUTOMOVIL,PARTICULAR,Conductor,Mas
@estebanz01
estebanz01 / integral_aproximation_rules.rb
Created May 3, 2019 20:47
Implementation of the composite rules used to approximate defined integrals, written in ruby.
def x_sub(index, lower, h)
x_k = lower + (index * h)
end
def booles_rule(lower, upper, &block)
h = (upper - lower) / 4.0
sum = 0
sum += 7 * yield(lower)
sum += 32 * yield(x_sub(1, lower, h))
@estebanz01
estebanz01 / newtons_method.rb
Last active March 4, 2019 20:29
Ruby snippet that tries to compute and find the root for a function using the Newton-Raphson method.
#!/usr/env ruby
def derivative_of(f:, x:)
h = 1e-14 # 1 * 10^-14 this is the smallest number ruby can handle in calculations before defaulting result to zero.
(f.call(x + h) - f.call(x)) / h # This is a naive approach to calculate limit of f(x) in x.
end
# Newton's Method, where we calculate f(x), f'(x) and calculate error.
def find_root(f:, seed:, iterations: nil, error_level: nil)
@estebanz01
estebanz01 / bikesharing.R
Created November 13, 2018 02:59
Bike Sharing Dataset - Random Forest basic prediction with validation of variables used at training time
# I got this working with code from https://datascienceplus.com/random-forests-in-r/
# It is an excelent resource!
set.seed(50)
bikeperday <- read.csv('Bike-Sharing-Dataset/day.csv')
# Calculate sample
sample <- sample.int(n = nrow(bikeperday),
size = floor(.75 * nrow(bikeperday)),
replace = F)

Keybase proof

I hereby claim:

  • I am estebanz01 on github.
  • I am estebanz01 (https://keybase.io/estebanz01) on keybase.
  • I have a public key ASBd7idQRbpevu7U2Qy50R8IEZPCf9scloEWWPAoy-bLFwo

To claim this, I am signing this object:

@estebanz01
estebanz01 / openpgp.txt
Created November 29, 2017 13:06
Identité reliée à OpenKeychain
This Gist confirms the Linked Identity in my OpenPGP key, and links it to this GitHub account.
Token for proof:
[Verifying my OpenPGP key: openpgp4fpr:d97d4f52f25a2a8d5e8874a061dea3a7bf851a0f]
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Leave {
public:
int idNumber;
string name;