Skip to content

Instantly share code, notes, and snippets.

View ergo70's full-sized avatar

Ernst-Georg Schmid ergo70

View GitHub Profile
@ergo70
ergo70 / testRegex.js
Created August 19, 2024 20:20 — forked from hanxiao/testRegex.js
Regex for chunking by using all semantic cues
// Updated: Aug. 15, 2024
// Run: node testRegex.js testText.txt
// Used in https://jina.ai/tokenizer
const fs = require('fs');
const util = require('util');
// Define variables for magic numbers
const MAX_HEADING_LENGTH = 7;
const MAX_HEADING_CONTENT_LENGTH = 200;
const MAX_HEADING_UNDERLINE_LENGTH = 200;
@ergo70
ergo70 / floatvecinbytea.c
Last active April 5, 2024 09:44
cosine similarity function on float4 vectors, stored as PostgreSQL bytea
#include <math.h>
#include "postgres.h"
#include "fmgr.h"
#include "utils/array.h"
#include "access/htup.h"
#include "catalog/pg_type.h"
#include "utils/lsyscache.h" // Required for building with PGXS (at least on macOS)
/*
CREATE FUNCTION cast_bytea_to_float4_array(bytea) RETURNS float4[]
@ergo70
ergo70 / dm-toilet-paper.js
Created February 29, 2024 17:35 — forked from marco79cgn/dm-toilet-paper.js
iOS Widget, das die Anzahl an Klopapier Packungen in deiner nächsten dm Drogerie anzeigt (für die scriptable.app)
// dm Klopapier Widget
//
// Copyright (C) 2020 by marco79 <[email protected]>
//
// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
@ergo70
ergo70 / cognito_PAM.py
Last active February 25, 2022 20:59
pam-python PAM module for AWS Cognito
import boto3
import jwt
from json import dumps
from requests import get
from botocore import UNSIGNED
from botocore.config import Config
from warrant.aws_srp import AWSSRP
from cryptography.hazmat.primitives import serialization
_PAM_DUMMY_PROMPT = ''
@ergo70
ergo70 / README.md
Created September 26, 2019 16:22 — forked from waveform80/README.md
Extract thumbnails from images captured by picamera.

Relies upon PIL to parse the initial JPEG structure and then does its own TIFF/Exif parsing because PIL's isn't up to dealing with the "full" Exif structure; looks like it gives up after IFD0.

Only tested with the V1 camera module, but I expect it'll work with either model. There's lots of stuff in here which isn't as efficient as it could be and a fair bit of cruft, but it's only a demo :)

@ergo70
ergo70 / FingerprintGenerator.java
Created April 17, 2019 10:10
How to generate fingerprints for similarity screening
package org.theplateisbad.fp;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.BitSet;
@ergo70
ergo70 / FindBySimilarity.java
Created April 17, 2019 10:08
How to screen for chemical similarity using binary fingerprints
package org.theplateisbad.fp;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.BitSet;
@ergo70
ergo70 / __init__.py
Last active April 1, 2019 09:43
OpenWeatherMap FDW
import requests
from multicorn import ForeignDataWrapper
from multicorn.utils import log_to_postgres, ERROR
__author__ = "Ernst-Georg Schmid"
__copyright__ = "Copyright (c) 2019 Ernst-Georg Schmid"
__license__ = "PostgreSQL"
__version__ = "2.0"
class OWMForeignDataWrapper(ForeignDataWrapper):
@ergo70
ergo70 / orientation.py
Created January 18, 2019 09:29
orientation.py
from vectors import Vector
from math import atan2
v1 = Vector(70.47130647130646,93.56190476190476,316.37118437118437) # Schreibtisch
v2 = Vector(73.91990231990232,96.26080586080586,328.06642246642247) # Schreibtisch + 20 h
v3 = Vector(-87.71428571428571,-183.37533577533577,-63.27423687423687) # Fenster
m1 = v1.magnitude()
m2 = v2.magnitude()
m3 = v3.magnitude()
@ergo70
ergo70 / CC2650.py
Last active December 6, 2018 14:51
import time
import struct
import os
import uuid
import json
from boto3 import resource
from boto3.dynamodb.conditions import Key
from bluepy.btle import UUID, Peripheral, Scanner
from decimal import Decimal
from datetime import datetime