Skip to content

Instantly share code, notes, and snippets.

@bozbez
bozbez / config.ron
Last active May 2, 2022 14:55
bozbez's Trackmania rlm2c config 2022-05-02
Config(
event_dispatcher: (
// The key used to switch from normal operation to controller emulation:
// Grave (= tilde) is the key to the left of number 1 on the number row,
// and should work well for most cases
toggle_key: Grave,
),
event_handler: (
// Unitless coefficient, scale 0 -> +inf as you would expect
#include <stdio.h>
int f(int x) {
return x * x;
}
void g(void *p) {
printf("5 * 5 = %d\n", (*((int (*)(int)) p))(5));
}
@bozbez
bozbez / asm_test.c
Last active May 27, 2017 19:54
inline asm intel syntax test
#include <stdio.h>
#include <stdint.h>
void print_flags(uint8_t flags) {
printf("flags:\n");
printf("sign\t= %d\nzero\t= %d\nacarry\t= %d\n"
"parity\t= %d\ncarry\t= %d\n",
(flags & 0x80) >> 7, (flags & 0x40) >> 6,
(flags & 0x10) >> 4, (flags & 0x04) >> 2,
(flags & 0x01) >> 0);
public static Matrix<Matrix<Integer>> multiplyNested(Matrix<Matrix<Integer>> a, Matrix<Matrix<Integer>> b) {
return a.multiply(b, (m1, m2) -> {
m1.add(m2, Integer::sum);
}, (m1, m2) -> {
m1.multiply(m2, Integer::sum, (x, y) -> x * y);
});
}
public static Matrix<PairWithOperators> multiplyList(List<Matrix<PairWithOperators>> matrices) {
return matrices.stream()
@bozbez
bozbez / qtree.js
Created March 21, 2016 14:45
Short QTree implementation in JavaScript
function QTree (center, radius) {
this.center = center
this.radius = radius
this.children = [[null, null], [null, null]]
this.points = []
this.pointlimit = 1
}
QTree.prototype.addPoint = function(point) {
var pointrel = [point[0] - this.center[0], point[1] - this.center[1]]
var tc = require('telnet-client');
var telnet = new tc();
var params = {
host: 'horizons.jpl.nasa.gov',
port: 6775,
shellPrompt: /(Horizons> $|: $|:$)/,
timeout: 1500,
echoLines: true,
removeEcho: true
@bozbez
bozbez / telnet-client.js
Created December 5, 2015 00:54
telnet-client with response regex fix
// Node.js Telnet client
var events = require('events')
var net = require('net')
var Promise = require('bluebird')
var socket = new net.Socket()
var util = require('util')
// define a constructor (object) and inherit EventEmitter functions
function Telnet() {
@bozbez
bozbez / parentheses checker
Created February 26, 2015 17:45
returns 0 if correctly matched parentheses, 1 if incorrectly matched
a=[ord(d)*2-81 for d in input() if d in['(',')']];b=[sum(a[:d+1])for d in range(len(a))];1 if abs(max(b))+abs(b[-1]) else 0