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 / ackermann.ml
Created February 26, 2021 13:47
Ackermann function OCaml
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))
@gabyfle
gabyfle / subset.lua
Created February 11, 2021 19:08
Returns the set of subsets of an original set (lol)
local function subsets(e)
local n = #e
local sub = {}
for i = 1, math.pow(2, n + 1) do
local set = {}
for k = 1, n do
if ((i >> k) & 1) == 1 then set[#set + 1] = e[k] end
end
@gabyfle
gabyfle / hex_to_rgb.lua
Created May 24, 2020 17:48
Lua HEX to RGB (for Garry's Mod format)
--- Hex to RGB function. We assume the hex color has been given following the standard #RRGGBB
-- @param string sHex: hex color format given in a string
-- @return table color: a color table following Garry's Mod way to handle color tables
local function hexToRGB(sHex)
return {
r = tonumber("0x" .. string.sub(sHex, 1, 2)),
g = tonumber("0x" .. string.sub(sHex, 2, 3)),
b = tonumber("0x" .. string.sub(sHex, 4, 6)),
a = 255
}
@gabyfle
gabyfle / kind_of_working.asm
Created May 6, 2020 13:50
Okay this is kind of working but still has to fix issues
; Generated by Brainfuck, a brainfuck compiler written in OCaml
; @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
; During the process, EDX will carry the cell address
; System calls macros
; write to ebx
%define SYS_WRITE 4
; read from ebx
%define SYS_READ 3
@gabyfle
gabyfle / intermediate_bugged.asm
Created May 6, 2020 10:58
Still generated code (and bugged code)
; Generated by Brainfuck, a brainfuck compiler written in OCaml
; @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
; During the process, EDX will carry the cell address
; System calls macros
; write to ebx
%define SYS_WRITE 4
; read from ebx
%define SYS_READ 3
@gabyfle
gabyfle / intermediate.asm
Last active May 5, 2020 22:32
Assembly code generated using Brainfuck (to test compile)
; Generated by Brainfuck, a brainfuck compiler written in OCaml
; @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
; During the process, EDX will carry the cell address
; System calls macros
; write to ebx
%define SYS_WRITE 4
; read from ebx
%define SYS_READ 3
@gabyfle
gabyfle / bugged.asm
Created May 5, 2020 19:19
Brainfuck to x86 generated code
; Generated by Brainfuck, a brainfuck compiler written in OCaml
; @author Gabriel Santamaria <gaby.santamaria@outlook.fr>
; During the process, EDX will carry the cell address
; System calls macros
; write to ebx
%define SYS_WRITE 4
; read from ebx
%define SYS_READ 3
@gabyfle
gabyfle / load_materials.lua
Last active April 6, 2020 17:29
Load materials from path
--- Loads all materials in a path
-- @param string path: path to analyse
-- @return table: a table containing every materials depending on
local function loadMaterials(path)
local files, directory = file.Find(path .. '*', 'GAME')
local materials = {}
for _, dir in pairs(directory) do -- launch the function in the other directories
table.Merge(materials, loadMaterials(path .. dir .. '/'))
end
@gabyfle
gabyfle / autoloader.lua
Created April 6, 2020 11:07
File autoloader GLua
-- Adding files to client side
local function load_client_file(file)
AddCSLuaFile(file)
if CLIENT then
include(file)
end
end
-- Adding files to server side
local function load_server_file(file)
@gabyfle
gabyfle / dm3.ml
Created October 30, 2019 17:52
Something special for school
let pi = 4.0 *. atan 1.0
(*
function approx
Approximate the alpha value
(dm 2)
*)
let approx max =
let counter = ref 1 in
let result = ref (pi /. 3.0) in