Skip to content

Instantly share code, notes, and snippets.

View omnp's full-sized avatar
🖌️

Olli M. omnp

🖌️
  • Turku, Finland
View GitHub Profile
@omnp
omnp / resolution.py
Last active August 15, 2025 15:20
Reverse resolution for CNF SAT
from sat import clause, get_variables, exclude, to3, randomize, propagate, clean
import php
import dimacs
import random
def preprocess(xs):
if not xs:
return xs
vs = get_variables(xs)
@omnp
omnp / multiplication.py
Last active November 26, 2024 15:26
A small convoluted example of multiplying two positive integers
def transform(n):
powers = []
k = 0
while n:
if n & 1:
powers.append(k)
n >>= 1
k += 1
return powers
@omnp
omnp / render_final-scene.py
Created November 23, 2024 11:45
PyTorch-based implementation of the final scene as seen in Ray Tracing in One Weekend — The Book Series, Ray Tracing the Next Week (as of August 2022)
import torch, torch.distributions as distributions
import numpy
import math
import random
DTYPE=torch.float32
device = 'cuda'
pi = None
inf = None
uniform = None
@omnp
omnp / color.py
Last active July 18, 2024 06:48
"Fake real" color mixing from RGB values, just something to play with (new revision updated).
import math
import matplotlib.pyplot as plot
EPS = 1e-24
red = (2.0,0.0,0.0)
green = (0.0,2.0,0.0)
blue = (0.0,0.0,2.0)
yellow = (1.0,1.0,0.0)
cyan = (0.0,1.0,1.0)
magenta = (1.0,0.0,1.0)
@omnp
omnp / vim-gtk3-css.patch
Created August 6, 2023 12:45
Loading CSS from a string for GVim with GTK 3 gui
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index 1f8b2ebcc..e216904fe 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -4059,6 +4059,28 @@ gui_mch_init(void)
G_CALLBACK(gtk_settings_xft_dpi_changed_cb), NULL);
}
+ if (GTK_IS_WIDGET(gui.mainwin))
+ {
@omnp
omnp / gtk-python-example4.py
Created August 3, 2023 19:04
Example showing how to create a minimal GTK 4 app with a main window and on it a Wayland subsurface fed by Vulkan.
# Example showing how to create a minimal GTK 4 app with a main window and on it a Wayland subsurface fed by Vulkan.
# The FPS counter printed on the console should show about 60 fps on Gnome/Mutter.
# One may need to install vulkan (the python package) from source.
# Maybe same for pywayland. Mileage may vary.
# I happen to have two discrete GPUs installed in the test computer, one AMD, one NVIDIA, and Intel integrated to top.
# The Radeon is the main one running Gnome/Mutter (after some /usr/share/glvnd/egl_vendor.d/ symlinking happened, that is)
# "Works for me" on the Radeon, when started from Gnome Terminal as python example4.py
# Playing around with switcherooctl style env variables trying to get the Nvidia card to render vulkan while being composited to
# the main window does not work though.
@omnp
omnp / dft.h
Created February 7, 2023 19:33
something like DFT (discrete fourier transform) in C++
#pragma once
#ifdef _WIN64
#define _USE_MATH_DEFINES
#endif
#include <cstdint>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
@omnp
omnp / my-test-plugin.php
Created October 18, 2019 04:06
A simple WordPress plugin to automatically compile less files into css using lessphp
<?php
/**
* Plugin Name: My Test Plugin
*/
defined('ABSPATH') or die();
require_once 'lessc.inc.php';
class my_test_plugin {
private $less;