Skip to content

Instantly share code, notes, and snippets.

View gabyfle's full-sized avatar
:octocat:
I like Git, C#, OCaml, Lua and Linux.

Gabriel Santamaria gabyfle

:octocat:
I like Git, C#, OCaml, Lua and Linux.
View GitHub Profile
@gabyfle
gabyfle / bz2.py
Last active April 16, 2021 19:18
bz2 automated file compression
import os
import bz2
from pathlib import Path
files = list(Path('.').rglob('*.*'))
for file in files:
if file.name == __file__: continue
if file.suffix == '.bz2': continue
local f = 'mysterious_addon.lua'
local df = 'deobfuscated.lua'
---
--- This is just to get rid
--- of the ennoying fucking
--- invisible caracters when
--- using UTF-8 encoding shit
---
--- Enjoy.
@gabyfle
gabyfle / mercator.py
Created April 1, 2021 08:23
mercator projection
# Using Mercator projection formula
def mercator(lon, lat, width = 14, height = 8):
lon, lat, width, height = float(lon), float(lat), float(width), float(height)
r = width / (2 * PI)
x = r * np.radians(lon)
y = (height / 2) - r * np.log(np.tan(PI / 4 + np.radians(lat) / 2))
return np.array([x, y, 0])
type 'a cell_lc = { tete : 'a ; queue : 'a lc }
and 'a lc = ListecVide | Listec of 'a cell_lc
let tete = function
| ListecVide -> failwith "Liste vide"
| Listec(cell) -> cell.tete
let queue = function
| ListecVide -> ListecVide
| Listec(cell) -> cell.queue
@gabyfle
gabyfle / sets.ml
Created March 25, 2021 10:45
Operations over sets
let rec member x = function
| [] -> false
| h :: t when x = h -> true
| h :: t -> member x t
let rec subset a = function (* quite dumb, in O(n²) *)
| [] -> true
| h :: t when (member h a) -> subset a t
| h :: t -> false
@gabyfle
gabyfle / begaie.ml
Last active March 25, 2021 09:23
Useless algorithms on lists
let begaie b =
let rec begaie_aux l = function
| [] -> l
| h :: t -> begaie_aux (h :: h :: l) t
in
List.rev (begaie_aux [] b)
(* sans utiliser List.rev (et donc sans la version récursive terminale)
let rec begaie = function
@gabyfle
gabyfle / stack.ml
Last active March 24, 2021 23:09
Stack by array
let lmax = 100
type 'a stack = { tab: 'a array; mutable length: int }
let empty default =
{ tab = Array.make lmax default; length = 0 }
let push x stack = match stack with
| { tab = _; length = 100 } -> failwith "Stack overflow"
| { tab = t; length = n } -> t.(n + 1) <- x; stack.length <- n + 1
@gabyfle
gabyfle / list_file.ml
Last active March 23, 2021 14:13
File (based on lists)
(* Empty the list l into m, reversing it *)
let rec clear l m = match l with
| [] -> m
| h :: t -> clear t (h :: m)
type 'a file = {top: 'a list; back: 'a list}
let empty () = {top= []; back = []}
let add a f = match f with
@gabyfle
gabyfle / postfix.ml
Last active March 23, 2021 11:47
Evaluation of postfixed expressions using pattern matching and piles
(* Evaluate postfixed expressions *)
type 'a status =
Number of 'a
|Operator of ('a -> 'a -> 'a)
|Function of ('a -> 'a)
let eval exp =
let s = Stack.create () in
let n = Array.length exp in
open Printf
let rec ackermann n p =
if n = 0 then p + 1
else if p = 0 then ackermann (n - 1) 1
else ackermann (n - 1) (ackermann n (p - 1))
(* Returns the list's head *)
let head = function
| [] -> failwith "Incorrect list, sorry man"