Skip to content

Instantly share code, notes, and snippets.

View giulioz's full-sized avatar
👋

Giulio Zausa giulioz

👋
View GitHub Profile
@giulioz
giulioz / kontrol_usb_re.cpp
Created September 4, 2024 15:40
Control a Native Instrument Komplete Kontrol A-Series keyboard via raw USB HID commands. Can read the buttons and write to the LCD screen and LEDs.
#include <hidapi.h>
#include <stdio.h>
int main() {
hid_init();
hid_device *handle = hid_open(0x17cc, 0x1750, NULL);
// Disable local controls
unsigned char buf1[3] = {0xa0, 0x03, 0x04};
hid_write(handle, buf1, 3);
@giulioz
giulioz / roland_decoder.cpp
Last active December 18, 2024 04:27
Descrambler/decoder for FCE-DPCM Roland ROM encoding (JD-800/JV-1080/SC55), based on https://github.com/hackyourlife/srscramble
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@giulioz
giulioz / punch_tape.py
Created April 16, 2023 10:58
OpenCV punch card reader
import cv2 as cv
import numpy as np
img = cv.imread('IMG_2024.jpeg')
# Segmentation
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
h = hsv[:,:,0]
s = hsv[:,:,1]
v = hsv[:,:,2]
const fs = require("fs").promises;
const FileWriter = require("wav").FileWriter;
const muLawDecompressTable = [
32124,
31100,
30076,
29052,
28028,
27004,
@giulioz
giulioz / CircBuffer.ts
Created April 7, 2021 14:35
Circular Buffer for TypeScript
export default class CircBuffer<T> {
data: (T | null)[];
start: number = 0;
end: number = 0;
data_inside: number = 0;
constructor(public size: number) {
this.data = new Array(size).fill(null);
}
@giulioz
giulioz / oop.c
Created October 26, 2020 17:01
OOP Simulation using C
#include <stdio.h>
#include <stdlib.h>
//
// interface Animale
//
typedef struct Animale {
void (*faiVerso)();
} Animale;
import React, { useEffect, useRef, PropsWithChildren, useState } from "react";
import { makeStyles } from "@material-ui/core/styles";
import useComponentSize from "@rehooks/component-size";
// USAGE:
// const svgWrapperProps = useSvgWrapperProps();
// return (
// <SvgWrapper {...svgWrapperProps}>
// ...
// </SvgWrapper>
@giulioz
giulioz / tinySmalltalk.c
Created August 15, 2019 17:27
Tiny Smalltalk-like objects in C.
#include <stdio.h>
#include <stdlib.h>
typedef struct Object Object;
typedef struct MethodChain {
const char* selector;
Object* (*handler)(Object* self);
struct MethodChain* next;
} MethodChain;
@giulioz
giulioz / filterArray.cc
Created March 24, 2019 21:39
(C++) Creates a new vector from a generic array and a predicate, like JS's filter
template <typename Array, typename Predicate>
auto filterArray(Array arr, Predicate p) {
using arrElemType = typename std::remove_reference<decltype(arr[0])>::type;
auto result = std::vector<arrElemType>();
for (const auto el : arr) {
if (p(el)) result.push_back(el);
}
return result;
}
@giulioz
giulioz / buffer.hpp
Created March 24, 2019 21:34
Creates a simple graphics window and give access to the framebuffer (C++)
#pragma once
/*
A simple SDL2-based framebuffer for graphics programming.
(Giulio Zausa, 2019)
Usage:
auto wnd = BufferWindow<WIDTH, HEIGHT>();
auto time = 0.0;