Skip to content

Instantly share code, notes, and snippets.

View laurelkeys's full-sized avatar
👋
💻+🎨=😊

Tiago Chaves laurelkeys

👋
💻+🎨=😊
View GitHub Profile
@laurelkeys
laurelkeys / quadric.glsl
Created June 3, 2021 16:21
Ray-quadric intersection.
//
// Quadric : dot(vec4(x, y, z, 1.0), Q * vec4(x, y, z, 1.0)) = 0
//
// ax2 + 2bxy + 2cxz + 2dx + ey2 + 2fyz + 2gy +hz2 + 2iz + j = 0
//
// Q = mat4(vec4(a, b, c, d), vec4(b, e, f, g), vec4(c, f, h, i), vec4(d, g, i, j))
//
float iQuadric(in vec3 ro, in vec3 rd, in vec2 distBound, inout vec3 normal,
@laurelkeys
laurelkeys / bgnet.h
Last active September 6, 2020 20:11
Notes on "Beej’s Guide to Network Programming", with examples rewritten in C99.
/*****************************************************************************
*** IP Addresses, structs, and Data Munging *********************************
============================================================================*/
// See https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
// |
// | struct addrinfo {
// | int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc.
// | int ai_family; // AF_INET, AF_INET6, AF_UNSPEC
// | int ai_socktype; // SOCK_STREAM, SOCK_DGRAM
@laurelkeys
laurelkeys / ijkl.ahk
Created August 29, 2020 18:07
AutoHotKey script to map CapsLock + { i, j, k, l } to Arrow Keys
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Disable CapsLock
SetCapsLockState, AlwaysOff
/* Base layer
* ,----------------------------------------------------------------------------------------.
@laurelkeys
laurelkeys / box_sample.cpp
Created June 6, 2020 17:22
Pixel sampling with bilinear interpolation.
// Bilinear interpolation.
static Color3f blerp(
const Image& image,
const std::size_t x0, const std::size_t y0,
const std::size_t x1, const std::size_t y1,
const float fx, const float fy
) {
// Compute weights:
const float wx1 = fx - x0;
const float wy1 = fy - y0;
@laurelkeys
laurelkeys / floatcmp.md
Created April 17, 2020 00:57
Summary of Christer Ericson's "Floating-point tolerances revisited"

Absolute tolerance comparison of x and :

// Fails when x and y become largey
if (abs(x - y) <= EPSILON)
    // ...

Relative tolerance comparison of x and y:

// Fails when x and y become small
@laurelkeys
laurelkeys / gsoc-proposal.md
Last active May 5, 2020 11:59
GSoC 2020 Project Proposal
@laurelkeys
laurelkeys / colorpalette.glsl
Created March 15, 2020 14:57
Comparison of iq's cosine palette to matplotlib's Viridis and Google AI's Turbo color palettes.
// Visualizing selected colors from one of Iñigo Quilez's color palettes
// See https://www.shadertoy.com/view/ll2GD3
// https://www.shadertoy.com/view/3lBXR3
//#define THREAD_INDEX 0.0
#define N_OF_THREADS 4.0
// 0 = iq's cosine palette
@laurelkeys
laurelkeys / airsim_coordinate_conversion.py
Last active February 21, 2020 16:30
Convert AirSim's local NED values to Unreal's coordinate system.
# connect to airsim
player_start_UE4 = client.getHomeGeoPoint() # obs.: this can be changed by OriginGeopoint in settings.json
ground_offset_NED = client.simGetVehiclePose().position # assumes the drone is at PlayerStart
assert ground_offset_NED.x_val == ground_offset_NED.y_val == 0
def to_NED(coords_UE4, ground_offset_NED=ground_offset_NED, player_start_UE4=player_start_UE4):
''' Converts Unreal coordinates to NED system.
Assumes PlayerStart is at (0, 0, 0) in AirSim's local NED coordinate system. '''
coords_NED = coords_UE4 - player_start_UE4 # Unreal uses cm and +z aiming up
@laurelkeys
laurelkeys / steganography.py
Last active October 28, 2019 14:49
Hide and retrieve ASCII messages on image bit planes
import numpy as np
def encode(bgr_img, message, bit_plane):
height, width, depth = bgr_img.shape
max_bytes = height * width * depth // 8
max_bits = max_bytes * 8 # we can only store whole byte words
if len(message) < max_bytes:
message += b'\0' # mark the end of the message
import numpy as np
def each_count(array):
count = np.bincount(array)
nonzero_count = np.nonzero(count)[0]
return zip(nonzero_count, count[nonzero_count])