Skip to content

Instantly share code, notes, and snippets.

@scartill
scartill / dslice.py
Created June 27, 2025 05:40
Slice a dictionary into a new dictionary, using the keys to define the slice (Python)
def dslice(d, *keys):
'''
Slice a dictionary into a new dictionary, using the keys to define the slice.
Each key can be a string, or a dictionary with the following keys:
- k: the key to slice
- c: the cast or conversion function
- d: the default value
- n: the name of the key in the result dictionary
'''
@scartill
scartill / Move-Files-From-Clipboard.ps1
Created May 12, 2025 15:00
A script that moves files captured by Ctrl-C or Ctrl-X to a working directory
function Move-Files-From-Clipboard() {
Add-Type -AssemblyName System.Windows.Forms
$hasFile = [System.Windows.Forms.Clipboard]::ContainsFileDropList()
if (-not $hasFile) {
Write-Output "No valid file copied in File Explorer."
return
}
$files = [System.Windows.Forms.Clipboard]::GetFileDropList()
@scartill
scartill / collection_data_policy.json
Last active April 22, 2025 06:44
Correct Authenticated Call to AWS OpenSearch Serverless using Boto3 from Lambda
[
{
"Rules": [
{
"Resource": [
"collection/my-randon-objects-fulltext"
],
"Permission": [
"aoss:CreateCollectionItems",
"aoss:DeleteCollectionItems",
@scartill
scartill / extract.py
Created December 6, 2024 09:06
Extract abbreviation and terms from comments in a MS Word file
import sys
from pathlib import Path
import docx
from docx.document import Document
def extract_abbreviations(doc_path: str):
# Load the document
doc: Document = docx.Document(doc_path)
@scartill
scartill / hosted_zone.py
Last active December 6, 2024 09:07
A very basic AWS Route53 hosted zone export and import CLI script
import boto3
import click
import json
import logging as lg
from pathlib import Path
@click.group()
@click.option('--profile', '-p', default='default')
@click.pass_context
@scartill
scartill / Geodesy.kt
Last active July 29, 2024 06:40
Basic geodesy ECEF and ENU transformations in Kotlin
package safir.fusion.geodesy
import org.apache.commons.math3.linear.Array2DRowRealMatrix
import org.apache.commons.math3.linear.ArrayRealVector
import org.apache.commons.math3.linear.RealMatrix
import org.apache.commons.math3.linear.RealVector
import org.apache.commons.math3.util.FastMath
data class Datum (
val a: Double,
@scartill
scartill / AsyncAdapter.py
Last active June 9, 2024 11:50
Simple adapter to marshal multithreaded calls to an async loop in a dedicated thread (Python 3)
import asyncio
import threading
import utils as u
MESSAGE_STOP = ('control', 'stop')
class AsyncAdapter:
@scartill
scartill / pwsh-7-posh-conf.json
Last active June 10, 2025 15:22
PowerShell 7 Oh-My-Posh Configuration File
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 3,
"blocks": [
{
"alignment": "left",
"type": "prompt",
"newline": true,
"segments": [
{
@scartill
scartill / lambda_function.py
Created May 8, 2023 07:15
Test Lambda to play with Insights
import json
import traceback
import time
def lambda_handler(event, context):
action = None
timeout = None
qsp = event.get('queryStringParameters')
@scartill
scartill / login.sh
Last active April 9, 2023 13:05
Move an AWS Amplify application to Bitbucket repo (e.g., from Github)
# - This needs a temporary OAuth Application created in Bitbucket
curl -X POST -u "ID:KEY" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials