Skip to content

Instantly share code, notes, and snippets.

View daniel-sc's full-sized avatar

Daniel Schreiber daniel-sc

  • ti&m
  • Offenbach, Germany
View GitHub Profile
@daniel-sc
daniel-sc / rename-images.sh
Created January 1, 2024 20:01
rename images (jpg, heic) to have filenames matching capturing date
#!/bin/bash
# Use first argument as directory, default to current directory if not provided
IMAGE_DIR=${1:-$(pwd)}
# Change to the directory
cd "$IMAGE_DIR"
# Loop through HEIC, heic, JPG, and jpg files
for file in *.[hH][eE][iI][cC] *.[jJ][pP][gG]; do
@daniel-sc
daniel-sc / migrate-ngrx-action-classes.ts
Last active January 29, 2024 11:47
Automatically migrate NgRx action classes to creator functions
import {readdirSync, readFileSync, writeFileSync} from 'fs';
import {resolve} from 'path';
import * as ts from 'typescript';
/// original action class name to type enum
const actionMapping = new Map<string, {enumType: string; constructorParams: Param[]}>();
/// this matches only a limited nesting of brackets - it uses lookaheads as performance fix for catastrophic backtracking:
const bracketMatcherPart = '\\(((?:[^()]*(?=[()])|\\((?:[^()]*(?=[()])|\\((?:[^()]*(?=[()])|\\((?:[^()]*(?=[()])|\\([^()]*(?=[()])\\))*\\))*\\))*\\))*)\\)';
@daniel-sc
daniel-sc / cover_sun_blueprint.yaml
Last active April 29, 2024 18:52
Homeassistant blueprint to close/open covers depending on sun position and weather
# see https://community.home-assistant.io/t/close-open-curtain-cover-blinds-based-on-sun-and-weather/584240
blueprint:
name: cover sun
description: Close cover when sun is shining and open when stops. This considers weather (sunny, partly cloudy), sun position (elevation, azimuth) and temperature.
domain: automation
input:
cover_entity:
name: cover
selector:
@daniel-sc
daniel-sc / bitbucket-to-teams-webhook.js
Created April 5, 2023 09:49
Deno script that can be deployed to https://deno.com/deploy and registered as a bitbucket webhook to notifiy new PRs in a MS Teams channel.
import { Application, Router } from 'https://deno.land/x/oak/mod.ts';
// Load environment variables
const PORT = 8080;
const TEAMS_WEBHOOK_URL = 'https://XYZ.webhook.office.com/webhookb2/XYZ';
const TARGET_USERNAME = 'xyz';
if (!TEAMS_WEBHOOK_URL || !TARGET_USERNAME) {
throw new Error('Missing required environment variables.');
}
const minCharCode = Math.min(...'aAzZ019-_.:,'.toUpperCase().split('').map(c => c.charCodeAt(0)));
const maxCharCode = Math.max(...'aAzZ019-_.:,'.toUpperCase().split('').map(c => c.charCodeAt(0)));
const alphabetSize = maxCharCode - minCharCode + 2;
console.log(minCharCode, maxCharCode, alphabetSize, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
function toNumber(char) {
return char.toUpperCase().charCodeAt(0) - minCharCode + 1;
}
@daniel-sc
daniel-sc / compact.js
Last active May 17, 2023 08:03 — forked from BlakeGardner/compact.js
Compact all collections inside of a MongoDB database
// This script loops though all collections of all db in a MongoDB and runs the compact operation on them
// Simply paste this into the Mongo shell
rs.secondaryOk();
db.getMongo().getDBNames().forEach(function(dbName) {
if ("local" != dbName && "admin" != dbName && "system" != dbName /* use this to (re-)start: && dbName > "am"*/) {
var subject = db.getSiblingDB(dbName);
subject.getCollectionNames().forEach(function (collectionName) {
print(new Date() + ': Compacting: ' + dbName + " - " + collectionName);
sleep(1000); // assure a cancel (CTRL-C) after "done" is executed before compact command
@daniel-sc
daniel-sc / create-test-subtasks.js
Created June 26, 2019 15:21
bookmarklet to automatically create jira subtasks for testing
// convert via https://mrcoles.com/bookmarklet/
var tasks = prompt('Tasks mit Kommas abgetrennt eingeben:', 'Test planen,Testdaten definieren,Tests erstellen,Test durchführen & dokumentieren').split(',');
var match = window.location.pathname.match(/[A-Z]+-[0-9]+/);
if (match[0]) {
var task = match[0];
var match = task.match(/[A-Z]+/);
var project = match[0];
var promises = [];
for (var i = 0; i < tasks.length; i++) {
#!/bin/bash
# copy to: /etc/cron.hourly/check-wlan
# test with: sudo run-parts --test /etc/cron.hourly
if ifconfig wlan0 | grep "inet addr:" ; then
logger "wifi ok"
exit
else
logger "Network down! Attempting reconnection."
@daniel-sc
daniel-sc / list-transitive-references.py
Last active June 16, 2016 08:53
Build a generic (transitive) reference tree for any source files.
import re
import argparse
import os
import pprint
import mimetypes
parser = argparse.ArgumentParser(description='Listing transitive references.')
parser.add_argument('start', nargs='+', help='Starting file(s).')
parser.add_argument('--pattern', default='[\'"]([^\'":[\]]+\.(?:png|jpg|gif|xml|html?|php|js))[\'"]',
help='Regex for matching references. \
@daniel-sc
daniel-sc / podio-php_proxy_hack.php
Last active January 28, 2016 17:24
Workaround for podio-php with http proxy sending multiple http responses
// \Podio::request
$raw_response = preg_replace('/^.*\r\n\r\nHTTP/s', 'HTTP', $raw_response);
$header = preg_split('/\r\n\r\n/s', $raw_response, 2)[0];
$raw_headers_size = strlen($header) + 4;