Skip to content

Instantly share code, notes, and snippets.

View ldaume's full-sized avatar
🐳
Doing the right things right

Leonard 'Lenny' Daume ldaume

🐳
Doing the right things right
View GitHub Profile
@ldaume
ldaume / json-clear-null-or-empties.ts
Created July 21, 2023 11:15
A TypeScript utility to recursively clean a JSON object or array by removing null, undefined, and empty values.
const isNullOrEmpty = (value: any) =>
value == null ||
(typeof value === 'string' && value.trim() === '') ||
(Array.isArray(value) && value.length === 0) ||
(typeof value === 'object' && Object.keys(value).length === 0);
export const clearNullEmpties = <T>(obj: T): T => {
if (Array.isArray(obj)) {
return obj
.map(clearNullEmpties)
@ldaume
ldaume / Scale all Docker services at once
Last active February 8, 2023 07:43
Loop over all Docker services (Docker Swarm) and set scale to 0, for example.
docker service ls | awk '{print $2}' | xargs -L1 sh -c 'docker service scale $0=0'
@ldaume
ldaume / changeSecurityGroupRuleID.py
Created January 12, 2022 10:05
Lambda that changes the IP in a ec2 Security group rule ID by domain
import json
import boto3
import socket
def lambda_handler(event, context):
client = boto3.client("ec2")
ip = socket.gethostbyname("example.com")
print("ip:", ip)
sg_rules_list = [
@ldaume
ldaume / setIpInSecurityGroupLambdaHandler.py
Last active January 7, 2022 10:14
aws lambda: Update the IP address to connect with a VPN that dynamically changes user IPs.
import boto3
import urllib3
# %% Description
'''Update the IP address to connect with a VPN that
dynamically changes user IPs.'''
def lambda_handler(event, context):
# %% Get current IP in CIDR notation
@ldaume
ldaume / ipByDomain.py
Created January 7, 2022 10:03
python get ip by domain name
import socket
domainName = input('Enter the domain name: ')
print(socket.gethostbyname(domainName))
@ldaume
ldaume / find-log4j-debian.sh
Created December 13, 2021 08:40 — forked from perryflynn/find-log4j-debian.sh
Find log4j for CVE-2021-44228 on some places * Log4Shell
#!/bin/bash
# Finds log4j resources on Linux (tested with Debian)
# by Christian Blechert <christian@serverless.industries>
# ATTENTION! It only checks ext3 + ext4 filesystems right now!
# Extend it if you use something else
while read -u 3 -r JAR
do
var mandrill = require('mandrill-api/mandrill');
var mandrill_client = new mandrill.Mandrill('api-key');
// Read recipients from file
//[ {"email": "me@example.com","name": "Me"} ]
var fs = require("fs");
var content = fs.readFileSync("recipients.json");
var recipients = JSON.parse(content);
var params = {
@ldaume
ldaume / robots.txt
Created January 31, 2018 12:49
disallow any via robots.txt
User-agent: *
Disallow:
@ldaume
ldaume / cozmo_unleashed-devel.py
Created December 30, 2017 18:09 — forked from acidzebra/cozmo_unleashed-devel.py
dev version of the cozmo_unleashed script. Rough edges ahead.
#!/usr/bin/env python3
# based on Copyright (c) 2016 Anki, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the file LICENSE.txt or at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@ldaume
ldaume / cozmo_unleashed_scheduler.py
Created December 30, 2017 18:08 — forked from acidzebra/cozmo_unleashed_scheduler.py
Autonomy for Cozmo, a script for having Cozmo freeplay until the battery runs low and then find/dock with the charger, with crude scheduler for weekdays/weekend and allowed play times. While in "allowed" play times, Cozmo has a 20% every 5 minutes of waking up and playing. Will attempt to find dock and charge when battery runs low.
#!/usr/bin/env python3
# based on Copyright (c) 2016 Anki, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the file LICENSE.txt or at
#
# http://www.apache.org/licenses/LICENSE-2.0
#