Skip to content

Instantly share code, notes, and snippets.

View borsna's full-sized avatar
🍞

Olof Olsson borsna

🍞
View GitHub Profile
@borsna
borsna / madmp-validate.py
Created April 4, 2024 15:15
Validate responses from endpoint against maDMP 1.1
import requests, json, urllib.request, os.path
from jsonschema import validate
countValid = 0
countInvalid = 0
api_endpoint = 'https://cthdmps.azurewebsites.net/api/v0/search'
bearer_token = 'mytoken'
if not os.path.exists('maDMP-schema-1.1.json'):
@borsna
borsna / SubSupText.php
Last active February 5, 2024 12:01
PHP string to subscript and superscript string
<?php
/**** example usage ****
print SubSupText::replaceSubSupHtml("H<sub>2</sub>O") . PHP_EOL; //H₂O
print SubSupText::replaceSubSupHtml("42km<sup>2</sup>") . PHP_EOL; //42km²
print SubSupText::replaceSubSupHtml("2<sup>th</sup> chapter") . PHP_EOL; //2ᵗʰ chapter
*/
class SubSupText{
const superscriptMap = [
'0' => '⁰', '1' => '¹', '2' => '²', '3' => '³', '4' => '⁴', '5' => '⁵',
@borsna
borsna / kubectl-log-tail.sh
Last active October 9, 2023 17:51
Tail log for kubernetes pod by geting list of pods and filter by substring
#!/bin/bash
namespace=mynamespace
pods=$(kubectl get po -n $namespace -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{end}')
for i in $(echo $pods | sed "s/\t/ /g")
do
case $i in *"$1"*)
kubectl logs -n $namespace $i --follow;;
esac
done
@borsna
borsna / geopoints-to-countrycode.py
Last active October 31, 2022 22:31
Get country code by geopoint
import json
import urllib.request
import os.path
from shapely.geometry import shape, Point
# download countries.geojson if needed
if not os.path.exists('countries.geojson'):
urllib.request.urlretrieve("https://datahub.io/core/geo-countries/r/countries.geojson", "countries.geojson")
# load GeoJSON containing country polygons
@borsna
borsna / Program.cs
Last active March 8, 2022 15:07
Simple C# script to create a ro-crate manifest
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Collections.Generic;
using System.Security.Cryptography;
using HeyRed.Mime;
if(Environment.GetCommandLineArgs().Length == 1){
Console.WriteLine("Provide argument for directory");
@borsna
borsna / html-links-to-plain.php
Created September 8, 2021 10:46
Html links to plain text in PHP
@borsna
borsna / milight.py
Created June 22, 2015 14:34
communicating with mi lights (network controllable led lights)
import socket
import sys
import time
import random
#docs:
# http://www.limitlessled.com/dev/
host = '10.10.10.255' #broadcast ip for my subnet
port = 8899