Skip to content

Instantly share code, notes, and snippets.

View hoogenm's full-sized avatar

Marc van den Hoogen hoogenm

  • The Netherlands
View GitHub Profile
@hoogenm
hoogenm / split_string_oracle.txt
Created April 30, 2024 15:56
Split/splitting a comma delimited string in Oracle (PL/) SQL
select regexp_substr('1,2,3,4','[^,]+', 1, level)
from dual
connect by regexp_substr('1,2,3,4', '[^,]+', 1, level) is not null;
-- Nice, smart, declarative way to split a comma-delimited string in Oracle SQL.
-- From: https://forums.oracle.com/ords/apexds/post/the-fastest-way-to-convert-comma-separated-list-into-table-3353
-- This may be slow for a long string, but for parsing a config value this results in concise code and may prevent boilerplate code.
-- Replace the 'copied & pasted' string (e.g. '1,2,3,4' in the example above) by one variable/constant in PL/SQL.
@hoogenm
hoogenm / calculate_determinant_std_python.py
Created July 13, 2023 19:20
Determinant using standard Python (Leibniz rule)
# Not for efficiency
def permutations(data, sign=0):
return ([(1, data)]
if len(data) == 1 else
[(sign * -1 if idx % 2 == 1 else sign, [value] + nested_permutation)
for idx, value in enumerate(data)
for sign, nested_permutation in permutations(data[:idx] + data[idx+1:])]
)
@hoogenm
hoogenm / linux_bluetooth_airpod2.md
Created August 22, 2022 18:40
Linux Bluetooth / Airpod 2
  • Set ControllerMode = bredr by editing /etc/bluetooth/main.conf file using sudo nano /etc/bluetooth/main.conf command (or another text editor of your choice)
  • sudo /etc/init.d/bluetooth restart
@hoogenm
hoogenm / exec.js
Created August 5, 2022 19:04
exec for node.js
const exec = (cmd) => console.log(require('child_process').execSync(cmd, { encoding: 'utf-8'}))
@hoogenm
hoogenm / d2c.sh
Created February 21, 2022 20:48
Docker Image to ContainerD
d2c() {
docker save "$1" | ctr image import -
}
@hoogenm
hoogenm / check_cert.py
Last active September 8, 2021 06:32
Certificate check
from cryptography import x509
from cryptography.hazmat.backends import default_backend
import socket
import ssl
from datetime import datetime
HOST = 'www.rabobank.nl'
def check_cert(host):
context = ssl.create_default_context()
@hoogenm
hoogenm / txt2pdf.sh
Created June 16, 2021 09:07
Generate pdf from text files in current folder
#!/bin/bash
# Install enscript and ps2pdf if not present
# -r for rotate (landscape)
ls -A *.txt | xargs -n 1 -I{} sh -c "enscript -r {} -o - | ps2pdf - {}.pdf"
@hoogenm
hoogenm / pdf2pdf.sh
Created November 16, 2020 20:35
PDF to rasterized (image) PDF
#!/bin/bash
# Note: filenames are fixed, replace before use
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=ae.pdf ae2.pdf
@hoogenm
hoogenm / mensinck.xml
Last active April 9, 2020 11:09
EAD voor Havezate Mensinck
<?xml version="1.0" encoding="UTF-8"?>
<ead audience="external" xmlns="urn:isbn:1-931666-22-9" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd">
<eadheader countryencoding="iso3166-1" dateencoding="iso8601" findaidstatus="unverified-full-draft" langencoding="iso639-2b" repositoryencoding="iso15511" scriptencoding="iso15924">
<eadid countrycode="NL" mainagencycode="NL-AhGldA">0416</eadid>
<filedesc>
<titlestmt>
<titleproper>Havezate Mensinck</titleproper>
<author>Rijksarchief in Gelderland</author>
</titlestmt>
<publicationstmt>
# Combines several solutions found on the internet
class ImplicitFTP_TLS(ftplib.FTP_TLS):
"""FTP_TLS subclass to support implicit FTPS."""
"""Constructor takes a boolean parameter ignore_PASV_host whether o ignore the hostname"""
"""in the PASV response, and use the hostname from the session instead"""
def __init__(self, *args, **kwargs):
self.ignore_PASV_host = kwargs.get('ignore_PASV_host') == True
super().__init__(*args, {k: v for k, v in kwargs.items() if not k == 'ignore_PASV_host'})
self._sock = None