Skip to content

Instantly share code, notes, and snippets.

@niklasf
niklasf / cpuid.py
Last active Jun 22, 2022
Detect support for popcnt and pext instructions on amd64, x86-64, x86 and i686 CPUs
View cpuid.py
import ctypes
import contextlib
import os
import platform
def detect_cpu_capabilities():
# Detects support for popcnt and pext instructions
modern, bmi2 = False, False
View gives-check.ts
type Square = number;
type Piece = 'p' | 'n' | 'b' | 'r' | 'q' | 'k' |
'P' | 'N' | 'B' | 'R' | 'Q' | 'K';
interface Board {
turn: boolean;
fmvn: number;
pieces: {
[s: number]: Piece
@niklasf
niklasf / .gitignore
Last active Sep 22, 2020
Sierpinski triangle generator
@niklasf
niklasf / bratko-kopec.py
Last active Feb 24, 2020
An implementation of the Bratko-Kopec Test using python-chess
View bratko-kopec.py
#!/usr/bin/python
import chess
import chess.uci
import sys
import time
MOVETIME = 120.0
@niklasf
niklasf / asyncio-private-loop.py
Last active Sep 23, 2019
A ChildWatcher that does not require the asyncio loop to be running in the main thread
View asyncio-private-loop.py
#!/usr/bin/python
import asyncio
import os
import sys
import threading
import time
import warnings
View install-display-kiosk.sh
#!/bin/sh
#
# Ausführen um Raspbian (oder ein anderes Debian) zu einem Anzeiger für IServ
# zu konfigurieren.
# Superuser Rechte holen.
if [ $(id -u) -ne 0 ]; then
echo Superuser Rechte nötig.
exit 1
fi
View calculator.c
#include <avr/io.h>
void USART_Init( unsigned int ubrr){
/* Set baud rate */
UBRR1H = (unsigned char)(ubrr>>8);
UBRR1L = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
/* Set frame format: 8data, 2stop bit */
UCSR1C = (1<<USBS1)|(1<<UCSZ11)|(1<<UCSZ10);
View bench-parallel.sh
#!/bin/bash
if [[ $# -ne 3 ]]; then
echo "usage:" $0 "base test n_runs"
echo "example:" $0 "./stockfish_base ./stockfish_test 10"
exit 1
fi
base=$1
test=$2
n_runs=$3
@niklasf
niklasf / tbdep.py
Created Jan 26, 2018
Create a Makefile for Syzygy tabebase generation
View tbdep.py
import sys
import chess.syzygy
import itertools
PCHR = chess.syzygy.PCHR
NORMAL = set(chess.syzygy.filenames())
def swap(egname):
w, b = egname.split("v")
@niklasf
niklasf / pgn-codebook.py
Last active Jan 19, 2018
Experiment with PGN compression. Usage: python pgn-codebook.py corpus.pgn
View pgn-codebook.py
import chess.pgn
import huffman
import sys
# https://github.com/flok99/feeks/blob/master/psq.py
PSQT = {
chess.PAWN: [
0, 0, 0, 0, 0, 0, 0, 0,
50, 50, 50, 50, 50, 50, 50, 50,