Skip to content

Instantly share code, notes, and snippets.

@JeffCarpenter
JeffCarpenter / add_or_update_firewalld_policy.sh
Created September 6, 2023 01:40
Bash function to add or update a firewalld policy for accepting incoming traffic on a specified port.
#!/bin/bash
# Function to add or update firewalld policy
add_or_update_firewalld_policy() {
local protocol=$1
local port=$2
local zone=$3
# Check if the rule already exists
if firewall-cmd --zone=$zone --query-port=$port/$protocol; then
@JeffCarpenter
JeffCarpenter / gh2sqlite-starred-tb.py
Last active September 27, 2022 19:32
github-to-sqlite starred ~/.local/share/dogsheep/github.db 39.51s user 72.27s system 11% cpu 16:28.50 total
Traceback (most recent call last):
File "/Users/jeff/brew/bin/github-to-sqlite", line 8, in <module>
sys.exit(cli())
File "/Users/jeff/Library/Python/3.10/lib/python/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/Users/jeff/Library/Python/3.10/lib/python/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/Users/jeff/Library/Python/3.10/lib/python/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/jeff/Library/Python/3.10/lib/python/site-packages/click/core.py", line 1395, in invoke
;; To run export from Bash:
;; emacs -batch -l ~/.emacs.d/init.el -eval "(org-agenda-export-to-ics)" -kill
;; if [[ "$?" != 0 ]]; then
;; notify-send -u critical "exporting org agenda failed"
;; fi
(setq org-directory "~/Dropbox/org/")
(defun set-org-agenda-files ()
"Set different org-files to be used in `org-agenda`."
(setq org-agenda-files (list (concat org-directory "things.org")
#!/bin/sh
# dependencies:
# - antiword & pandoc: installable with the package manager in any major distro
# - html2csv: `pip install html-to-csv`
antiword -x db "$1" | pandoc --from=docbook --to=html | html2csv -
@JeffCarpenter
JeffCarpenter / wwb-emulator.c
Last active October 3, 2021 23:33
ATTiny45-based 60Hz WWVB signal transmitter by Steven Mullins
/*
3-20-14
Copyright Steven Mullins 2014
ATTiny45
60Khz Transmitter
Modulated with WWVB signal
Source: https://www.instructables.com/WWVB-radio-time-signal-generator-for-ATTINY45-or-A/
@JeffCarpenter
JeffCarpenter / module-dep-tree.sh
Created August 12, 2021 16:12
Draw kernel module dependency graph
# Author: bandie91
# Source: https://www.commandlinefu.com/commands/view/9775/draw-kernel-module-dependancy-graph
lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -
@JeffCarpenter
JeffCarpenter / LatencyTester.ino
Created July 13, 2021 16:12 — forked from trishume/LatencyTester.ino
Latency Tester and Foot Pedals Teensyduino sketch
// Tristan's Foot Pedals and Latency Tester Arduino Program
// Provides 5 buttons: left click, right click, scroll up, scroll down, latency test
// If you don't want all of these you can comment out the buttons you don't need.
#define BOUNCE_LOCK_OUT
#include <Bounce2.h>
#include "Keyboard.h"
const int scrollInterval = 80;
@JeffCarpenter
JeffCarpenter / dumpCurrentBuffer.vim
Created May 20, 2021 22:14
Dump current Vim Buffer
" courtesy of the gocode autocompletion project
" https://github.com/nsf/gocode/blob/9d1e0378d35b0527c9aef0d17c0913fc38d88b81/vim/autoload/gocomplete.vim#L6-L19
fu! s:dumpCurrentBuffer()
let buf = getline(1, '$')
if &encoding != 'utf-8'
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")')
endif
if &l:fileformat == 'dos'
" XXX: line2byte() depend on 'fileformat' option.
@JeffCarpenter
JeffCarpenter / flask_subpath.py
Created December 2, 2020 05:48
Serve Flask from a non-root path
class FlaskSubpath(Flask):
def __init__(self, *args, application_root="/", **kwargs):
super().__init__(*args, **kwargs)
self.application_root = application_root
def wsgi_app(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.application_root):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.application_root):]
environ["SCRIPT_NAME"] = self.application_root
#!/bin/bash
# Make a PDF look scanned.
# Extracted from https://github.com/baicunko/scanyourpdf and modified for smaller output files (compression lower density).
INPUT_FILE=$1
/usr/local/bin/convert -density '80' ${INPUT_FILE} -colorspace 'gray' -linear-stretch '3.5%x10%' \
-blur '0x0.5' -attenuate '0.25' +noise Gaussian -rotate 0.5 \
-compress lzw -quality 50 scanned_${INPUT_FILE}