Skip to content

Instantly share code, notes, and snippets.

@gue-ni
gue-ni / map_range.h
Last active October 20, 2023 11:05
Map numbers from one range to another
#include <tuple>
#include <cassert>
template<typename T>
T map_range(T s, const std::pair<T,T>& in, const std::pair<T,T>& out)
{
auto [in_min, in_max] = in;
auto [out_min, out_max] = out;
assert(in_min <= s && s <= in_max);
return out_min + (s - in_min) * (out_max - out_min) / (in_max - in_min);
@gue-ni
gue-ni / ray_sphere_intersection.rs
Created October 9, 2023 06:06
A Simple Ray-Sphere Intersection Implementation in Rust
mod vecmath {
use std::ops::{Add, Div, Mul, Sub};
#[derive(Debug, Copy, Clone)]
pub struct Vec3 {
pub x: f64,
pub y: f64,
pub z: f64
}
@gue-ni
gue-ni / wms_downloader.py
Created July 28, 2023 09:41
MapServer downloading util
import requests
import math
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--lat", type=float, required=True)
parser.add_argument("--lon", type=float, required=True)
parser.add_argument("--zoom", type=int, required=True)
@gue-ni
gue-ni / vec3.hpp
Last active October 19, 2022 09:59
A simple header only vector math library for C++
#pragma once
#include <cmath>
namespace q {
template <typename T>
struct vec3 {
union {
struct { T x, y, z; };
@gue-ni
gue-ni / alpine-js-fetch.markdown
Created July 31, 2022 08:08
Alpine JS + fetch()
@gue-ni
gue-ni / [...nextauth].js
Last active April 22, 2024 17:13
NextAuth.js postgres adapter
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import PostgresAdapter from "../../../lib/adapter";
const pool = new Pool({
user: "postgres",
host: "localhost",
database: "postgres",
password: "postgres",
port: 5432,
@gue-ni
gue-ni / redirect_from_mobile_wikipedia.js
Last active November 28, 2021 15:14
Redirect from wikipedia mobile pages to desktop pages
// ==UserScript==
// @name Redirect from mobile wikipedia
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Redirect wikipedia mobile pages to desktop pages
// @author Jakob Maier
// @match https://*.m.wikipedia.org/*
// @icon https://www.google.com/s2/favicons?domain=wikipedia.org
// @updateURL https://gist.githubusercontent.com/gue-ni/7de602dc5af933b2c47b6db5f4370ac8/raw/redirect_from_mobile_wikipedia.js
// @downloadURL https://gist.githubusercontent.com/gue-ni/7de602dc5af933b2c47b6db5f4370ac8/raw/redirect_from_mobile_wikipedia.js
@gue-ni
gue-ni / userscript.js
Last active November 28, 2021 15:09
Color Hackernews link for better readability
// ==UserScript==
// @name Color hackernews links
// @namespace http://tampermonkey.net/
// @version 1.0
// @description try to take over the world!
// @author You
// @match https://news.ycombinator.com/
// @icon https://www.google.com/s2/favicons?domain=ycombinator.com
// @grant GM_addStyle
// ==/UserScript==
@gue-ni
gue-ni / AdBlock.js
Last active February 23, 2022 11:56
AdBlock für derstandard.at
// ==UserScript==
// @name Der Standard AdBlock
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Easy way to block ads on derstandard.com
// @author Jakob Maier
// @match https://www.derstandard.at/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
@gue-ni
gue-ni / docker-compose.yml
Last active October 4, 2021 06:51
Run PostgreSQL in Docker
version: "3"
services:
db:
image: postgres
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres # default is postgres, same as POSTGRES_DB