Skip to content

Instantly share code, notes, and snippets.

View sebastianknopf's full-sized avatar

Sebastian Knopf sebastianknopf

View GitHub Profile
@sebastianknopf
sebastianknopf / csv2ddb.py
Last active October 13, 2024 19:30
python helper script for memory efficient importing huge CSV files into a DuckDB database
import click
import csv
import duckdb
import polars
@click.command
@click.option('--file', '-f', help='Input CSV file')
@click.option('--db', '-d', help='DuckDB filename')
@click.option('--table', '-t', help='Destination table name to import the CSV file')
@click.option('--create-statement', '-c', default=None, help='Create statement filename for destination table')
@sebastianknopf
sebastianknopf / asc.py
Last active September 12, 2024 09:36
Python helper class to process *.asc files used in IVU.pool data for timetable exchange
import csv
import re
import os
from isa.ascdef import name2def
########################################################################################################################
# Helper class for reading and modifying *.asc files.
########################################################################################################################
@sebastianknopf
sebastianknopf / x10.py
Created August 1, 2024 08:41
Python helper class to process *.x10 files according to VDV-451
import csv
import re
########################################################################################################################
# Helper class for reading and modifying *.x10 files.
########################################################################################################################
def read_x10_file(filename):
x10_file = X10File()
x10_file.read(filename)
@sebastianknopf
sebastianknopf / offlinemaps.py
Created January 12, 2023 18:28
python script to fetch ZXY tiles from map servers
import os
import requests
import math
import zipfile
from optparse import OptionParser
# map server constants
MAP_SERVER_ADDRESS = '[YourMapServer]'
MAP_SERVER_USERNAME = ''
@sebastianknopf
sebastianknopf / objectunifier.py
Created May 11, 2022 21:03
unifies objects to a comparable (hash) string regardless of their spelling - use case: checking persons and addresses against a blacklist without storing personal data permanently in database
import hashlib
import re
import unittest
from abc import abstractmethod
class ObjectUnifier:
_token_list = []
@sebastianknopf
sebastianknopf / CommandLineParser.java
Last active May 25, 2020 10:53
a basic parser for command line arguments in java
import java.util.ArrayList;
import java.util.List;
/**
* Command line argument parser class for parsing command lines like
* program.jar -i input.txt -o output.txt --verbose.
*/
public class CommandLineParser {
/**
@sebastianknopf
sebastianknopf / MatrixImage.java
Last active March 18, 2020 20:48
Convert a ZXing BitMatrix to an JavaFX Image
import com.google.zxing.common.BitMatrix;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
/**
* Helper class for converting a com.google.zxing.common.BitMatrix into an Image object instance in JavaFX.
*/
@sebastianknopf
sebastianknopf / lib_gpio.php
Created November 18, 2019 06:53
Control Raspi GPIO with PHP
<?php
define('GPIO_HIGH', 1);
define('GPIO_LOW', 0);
function gpio_exec($cmd)
{
$output = array();
$return = 0;
@sebastianknopf
sebastianknopf / JwtAuthentication.php
Created July 10, 2019 21:06
Using JwtAuthenticator in CakePHP's Authentication Plugin
// to use the JwtAuthenticator in a CakePHP application you first have load the corresponding
// authenticator in your Application::getAuthenticationService(...)
$service->loadAuthenticator('Authentication.Jwt', [
'returnPayload' => false
]);
// The parameter 'returnPayload' is set to true by default - If you want your visitor using the JWT run trough a full authentication
// process, you should set it to false.
@sebastianknopf
sebastianknopf / date_time_compact.c
Last active March 21, 2019 11:06
simple and effective way to store date / time in only 4 byte
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
short date_compress(int day, int month, int year) {
short d = ((((year % 100) << 4) + month) << 5) + day;
return d;
}
int* date_decompress(int cdate) {