Skip to content

Instantly share code, notes, and snippets.

@quaat
quaat / storage-backend-example.py
Last active March 6, 2024 08:43
Example of how to abstract the storage backend for a caching service in Python, using the principles of protocols from type hinting for runtime type checking.
from dataclasses import dataclass, field
from typing import Any, Dict, Protocol, runtime_checkable
from redis import Redis
@runtime_checkable
class ICacheBackend(Protocol):
"""
Defines an interface for cache backends. Any class that implements this protocol
must provide `set`, `get`, and `aclose` methods. This allows for flexibility in
the cache implementation, as different storage mechanisms can be used as long as
@quaat
quaat / fisher_random.py
Last active February 10, 2024 14:03
Fisher Random starting positions
"""Generate and validate starting positions for Fischer Random Chess,
also known as Chess960. Fischer Random Chess is a variant of
traditional chess invented by the former World Chess Champion Bobby
Fischer. It was introduced to add variety to the game and reduce the
reliance on opening memorization by randomly shuffling the positions
of the back-row pieces (rooks, knights, bishops, queen, and king)
while adhering to certain rules to ensure the game remains balanced
and playable.
Fischer Random Chess follows these specific rules for setting up the
identity: http://onto-ns.com/entity/v1/demo#a77e5e81-2107-45f9-9dde-1f559d961d0a
description: Demonstration
dimensions:
N: Number of items
properties:
lat:
type: float
shape: ["N"]
description: Latitude
{
"name": "TextFile",
"version": "0.1",
"namespace": "http://onto-ns.com/meta",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"description": "Representation an experimental image.",
"dimensions": [],
"properties": [
{
"name": "data",
@quaat
quaat / yml
Created October 28, 2021 14:40
language-codes
languages:
- af : Afrikaans
- af-ZA : Afrikaans (South Africa)
- ar : Arabic
- ar-AE : Arabic (U.A.E.)
- ar-BH : Arabic (Bahrain)
- ar-DZ : Arabic (Algeria)
- ar-EG : Arabic (Egypt)
- ar-IQ : Arabic (Iraq)
@quaat
quaat / create-gitlab-runner.sh
Last active November 18, 2021 18:03
dind gitlab-runner
#!/bin/bash
read -p "Enter runner name [my-runner]: " name
read -p "Enter registration token: " token
read -p "Enter gitlab url: " url
volume_name=gitlab-volume-$name
runner_name=gitlab-runner-$name
docker volume create $volume_name
@quaat
quaat / .emacs
Last active October 29, 2020 12:42
My basic emacs config
;;; Code:
(add-to-list 'load-path "~/.emacs.d/lisp/")
(add-to-list 'load-path ".")
(setq c-basic-indent 2)
(setq tab-width 4)
(setq indent-tabs-mode nil)
(require 'org)
@quaat
quaat / binsearchtest.f90
Created September 11, 2013 19:00
Generic binarySearch algorithm in Fortran 2003 (pure, recursive)
program binSearchTest
integer :: idx
real, allocatable :: v(:)
integer, allocatable :: v2(:)
interface binarySearch
procedure binarySearch_real
procedure binarySearch_int
end interface binarySearch
@quaat
quaat / ifort.prf
Created September 9, 2013 13:44
Simple project file (no dependency support) for Intel Fortran compilers
NEWLINE = $$escape_expand(\\n\\r\\t)
!isEmpty(MODULE_DIR){
MODFLAGS += -J$$MODULE_DIR
INCLUDEPATH += $$MODULE_DIR
}
F90 = ifort
MKDIR = $$quote($(MAKEFILE))
@quaat
quaat / gfortran.prf
Created September 3, 2013 22:13
qmake prf-file for mixed programming with fortran
isEmpty( fortran_compiler ) {
# gfortran.prf
# Adds gfortran as extra compiler to the qmake build system.
#
# This file must reside in the path of QMAKEFEATURES
#
# Thomas Hagelien
#
F90 = gfortran