Skip to content

Instantly share code, notes, and snippets.

View justinmeiners's full-sized avatar

Justin Meiners justinmeiners

View GitHub Profile
@justinmeiners
justinmeiners / vector.h
Last active January 20, 2020 07:03
generic vector template in ANSI C
/*
https://gist.github.com/pervognsen/c56d4ddce94fbef3c80e228b39efc028
https://gist.github.com/pervognsen/6f295f356010186f3c350f31fbeec28b
*/
/*
EXAMPLE
@justinmeiners
justinmeiners / http_request_parameters_node.js
Last active January 22, 2020 03:21
How to make a node.js HTTP GET request with query parameters.
/*
https://nodejs.org/api/url.html#url_url_format_urlobject
Use the module to build a URL with query parameters:
*/
const requestUrl = url.parse(url.format({
protocol: 'https',
hostname: 'yoursite.com',
pathname: '/the/path',
query: {
@justinmeiners
justinmeiners / unity3d_multiplypoint_3_4.md
Last active January 19, 2021 06:31
What is the difference between MultiplyPoint and MultiplyPoint3x4 in Unity3D?

What is the difference between MultiplyPoint and MultiplyPoint3x4 in Unity3D?

What steps of a matrix multiplication could Unity possibly be skipping to make an optimization? The optimization is possible because a scaling and rotation needs only a 3x3 matrix and another vector for the translation, so part of the full 4x4 matrix is unused and can be ignored.

Here is the source code taken from the decompilation [here][1]:

public Vector3 MultiplyPoint(Vector3 v)

{

NSOpenPanel *panel;
NSArray* fileTypes = [NSArray arrayWithObjects:@"pdf", @"PDF", nil];
panel = [NSOpenPanel openPanel];
[panel setFloatingPanel:YES];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:YES];
[panel setAllowedFileTypes:fileTypes];
int i = [panel runModal];
if (i == NSOKButton){
@justinmeiners
justinmeiners / why_is_std_map_a_red_black_tree.md
Last active January 31, 2024 17:54
Why is std::map typically implemented as a red-black tree?

Why is std::map typically implemented as a red-black tree?

Why not a hash table?

A type only requires < operator (comparison) to be used as a key in a tree. However, hash tables require that each key type has a hash function defined. Keeping type requirements to a minimum is very important for generic programming so you can use it with a wide variety of types and algorithms.

Designing a good hash table requires intimate knowledge of the context it which it will be used. Should it use open addressing, or linked chaining? What levels of load should it accept before resizing? Should it use an expensive hash that avoids collisions, or one that is rough and fast?

Since the STL can't anticipate which is the best choice for your application, the default needs to be more flexible. Trees "just work" and scale nicely.

; either input works in SBCL
;(load "~/quicklisp/setup.lisp")
;(ql:quickload "asdf")
(require "asdf")
;(print (asdf:asdf-version))
; of course "cat" is superfulous here,
; but I just wanted to try out piping data.
(defparameter cat
// gcc -I/usr/X11/include -L/usr/X11/lib -lX11 xlib_image.c
// bsd: gcc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 xlib_image.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void draw(char *rgb_out, int w, int h)
(defun vec-zero (n &key (element-type 'float))
(make-array n
:element-type element-type
:initial-element (coerce 0 element-type)))
(defun vec-basis (n i &key (element-type 'float))
(let ((r (vec-zero n :element-type element-type)))
(progn
(setf (aref r i) (coerce 1 element-type))
r)))
// node kernel.js > out.txt; gnuplot -p -e 'plot "out.txt" using 1:2 with points pt 7'
function minimizeEnergy(samples, sampleCount, steps) {
// energy conservation
// https://web.archive.org/web/20090422055305/
// http://www.malmer.nu/index.php/2008-04-11_energy-minimization-is-your-friend/
for (var step = 0; step < steps; ++step) {
for (var i = 0; i < sampleCount; ++i) {
var x = samples[i * 2];
(defun group-adjacent (list &key (test #'eql))
((
(lambda (group x)
(if (or (funcall test (car group) x) (funcall test x (car group)))
(progn
(push group result)
(list x))
(cons x group)))
(cdr list)