Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am stekern on github.
  • I am ekern (https://keybase.io/ekern) on keybase.
  • I have a public key ASCIEXlhT9VjmD39jqYGgQSakoSM1yZoYUJ2JenmRPF-rQo

To claim this, I am signing this object:

@stekern
stekern / scrollingffmpeg.sh
Created April 11, 2019 09:55
Create a scrolling text video with a static image background using ffmpeg
# Creates a 20-second video with a scrolling text overlay.
# The image is named 'input.png', and the textfile it reads from is called 'yourfile.txt'.
# Create a video of the image
ffmpeg -loop 1 -t 20 -i input.png output.mp4
# Add scrolling text to the video
ffmpeg -i output.mp4 -filter_complex \
"[0]split[txt][orig];[txt]drawtext=fontfile=tahoma.ttf:fontsize=55:fontcolor=white:x=(w-text_w)/2+20:y=h-20*t:textfile='yourfile.txt':bordercolor=black:line_spacing=20:borderw=3[txt];[orig]crop=iw:50:0:0[orig];[txt][orig]overlay" \
-c:v libx264 -y -preset ultrafast -t 20 output_scrolling.mp4
@stekern
stekern / _.css
Created May 13, 2019 09:12
Styling for Tree Style Tab
/* Firefox > Tree Style Tab > Manage Extension > Advanced > "Extra style rules for sidebar contents" */
/* Show title of unread tabs with red and italic font */
.tab.unread .label {
color: red !important;
font-style: italic !important;
}
/* Add private browsing indicator per tab */
.tab.private-browsing .label:before {
@stekern
stekern / ntnu_gpa_calculator.js
Created May 15, 2019 18:02
Calculate GPA from StudentWeb
// This script will calculate your GPA according to your grades on StudentWeb.
// 1. Go to https://fsweb.no/studentweb/resultater.jsf
// 2. Open up your browser's developer console
// 3. Run the following code
{const e=$x('//table[@id="resultatlisteForm:HeleResultater:resultaterPanel"]/tbody/tr[@class="none" or @class="resultatTop"]/td[contains(@class, "col6Resultat") or contains(@class, "col7Studiepoeng")]//span[last()]/text()').reduce((e,t,s,a)=>(s%3==0&&1===a[s+1].length&&e.push({grade:a[s+1].data,credits:parseFloat(a[s+2].data.replace(",","."))}),e),[]),t=e.reduce((e,t)=>e+t.credits,0),s=e.reduce((e,t)=>e+(70-t.grade.charCodeAt(0))*t.credits,0)/t;console.log(`GPA: ${s}, sum of credits: ${t}`)}
@stekern
stekern / spotifyseek.sh
Last active May 25, 2019 13:14
Seek a Spotify track from the command-line
#!/usr/bin/env bash
#
# Copyright (C) 2019 Erlend Ekern <dev@ekern.me>
#
# Distributed under terms of the MIT license.
# # # # # # # # # # # # # # # # #
# A script for seeking a currently playing Spotify track using the command-line
# # # # # # # # # # # # # # # # #
@stekern
stekern / lambda_shellcheck.py
Created July 30, 2020 15:17
Verify a shell command in an AWS Lambda function
import subprocess
def lambda_handler(event, context):
shell_command = event.get("shell_command", "")
with open("/tmp/script.sh", "w") as f:
f.write(shell_command)
try:
subprocess.check_call("sh -n /tmp/script.sh", shell=True)
except subprocess.CalledProcessError:
raise ValueError("'shell_command' does not contain a valid shell command")
@stekern
stekern / example.py
Created August 10, 2020 14:38
Using Pythons's reduce function to group a list of dictionaries by a specific key
#!/usr/bin/env python3.7
#
# Copyright (C) 2020 Erlend Ekern <dev@ekern.me>
#
# Distributed under terms of the MIT license.
"""
An example of using `functools.reduce` to group a list of dictionaries by a specific key.
"""
@stekern
stekern / script.sh
Created November 12, 2020 07:50
Shell one-liner for pretty-printing JSON
python -c "import sys; import json; j = json.load(sys.stdin); json.dump(j, sys.stdout, indent=2, sort_keys=True, separators=(',', ': '))"
@stekern
stekern / locate-cdk-v1-stacks.sh
Last active June 2, 2022 12:21
Locate CloudFormation stacks created using CDK v1
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
read -r -d '' -a regions < <(aws ec2 describe-regions --query "Regions[].[RegionName]" --output text && printf '\0')
for region in "${regions[@]}"; do
echo "[$region] Finding CloudFormation stacks deployed using CDK"
read -r -d '' -a stacks < <(aws cloudformation list-stacks --region "$region" --query "StackSummaries[?!contains(keys(@), 'DeletionTime')].[StackName]" --output text && printf '\0')
test -z "${stacks:-}" && continue
@stekern
stekern / replace_placeholders.sh
Created June 23, 2022 13:29
Shell script for replacing placeholders in files in a portable-ish manner
#!/usr/bin/env bash
#
# Helper functions for replacing placeholders in files.
#
# Distributed under terms of the MIT license.
set -euo pipefail
IFS=$'\n\t'
# Print example usage of the script.