Skip to content

Instantly share code, notes, and snippets.

View felipetavares's full-sized avatar

Felipe Tavares felipetavares

View GitHub Profile
@felipetavares
felipetavares / gauss-jackson.jl
Created May 17, 2021 21:36
Incomplete implementation of the Gauss-Jackson Integrator
"""
Backwards difference
∇fᵢ = (fᵢ - fᵢ₋₁)
"""
function ∇(power, f, i)
if power > 1
∇(power-1, f, i) - ∇(power-1, f, i-1)
else
f[i] - f[i-1]
@felipetavares
felipetavares / net.rkt
Last active March 6, 2021 23:35
Simple backprop neural net
#lang racket
(require math/matrix)
(define (sigmoid x) (/ (exp x) (+ (exp x) 1)))
(define (sigmoid~ x) (* (sigmoid x) (- 1 (sigmoid x))))
(define (tanh~ x) (/ 1 (expt (cosh x) 2)))
(define activation sigmoid)
(define activation~ sigmoid~)
@felipetavares
felipetavares / crypto.rkt
Created January 7, 2021 14:20
Notes on Crypto
#lang racket
;; Week 1
;; There are two protocols in secure communication:
;; - handshake protocol: finding a shared key
;; - record layer: sending and receiving data
;;
;; Encrypting files is the same as sending encrypted
;; messages between A -> B, except B is actually A in
@felipetavares
felipetavares / paletted_png.c
Created October 17, 2019 11:04
Detect if a PNG has a palette and load palette+data with libpng
// This examples read a PNG and its palette
#include <png.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main() {
png_image img;
@felipetavares
felipetavares / tetrafrac.glsl
Last active October 20, 2019 01:04
Tetrahedron fractals with raymarching. Camera & ambient occlusion. View with https://github.com/Gargaj/Bonzomatic
#version 450 core
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
@felipetavares
felipetavares / integration.js
Last active August 9, 2019 17:38
Neurologic Client-Side Integration example
// O nome da função pode ser escolhido arbitrariamente
//
// config: objeto contendo configuração estática relacionada ao fluxo;
//
// callback: função que recebe como argumento um bloco a ser adicionado
// ao chat e termina o estado de loading.
function nldAPI_JornalDoCarro_LeadComplete(config, callback) {
// Extrai os dados usando o objeto global "neurolead"
var leadData = neurolead.getData();
@felipetavares
felipetavares / simple_useful_slow.js
Last active October 31, 2024 08:33
Simple, Useful and Slow: Assorted Reference Statistics Functions (utf-8)
// Simple, Useful and Slow
// Assorted Reference Statistics Functions
// UTF-8 Edition
// Shorthands
pow = Math.pow
sqrt = Math.sqrt
pi = Math.PI
function vec_(x, y)
return { x = x, y = y }
end
function add(a, b)
return vec_(a.x+b.x, a.y+b.y)
end
function sub(a, b)
return vec_(a.x-b.x, a.y-b.y)
@felipetavares
felipetavares / lparser.c
Created November 19, 2018 15:43
+= extension for Lua 5.3
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
expdesc e;
check_condition(ls, vkisvar(lh->v.k), "syntax error");
if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
struct LHS_assign nv;
nv.prev = lh;
suffixedexp(ls, &nv.v);
if (!vkisindexed(nv.v.k))
check_conflict(ls, lh, &nv.v);
@felipetavares
felipetavares / polygon.js
Created November 16, 2018 19:19
Polygon Generator: given a set of tile positions create a polygon from its boundary
function cantor(x, y) {
return (x+y)/2*(x+y+1)+y;
}
function decantor(z) {
let w = Math.floor((Math.sqrt(8*z+1)-1)/2);
let t = (w*w+w)/2;
return {
y: z-t,