Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Writing and Coding

jamesg capjamesg

💻
Writing and Coding
View GitHub Profile
@capjamesg
capjamesg / robots.py
Last active Aug 10, 2021
robots.txt parser in Python
View robots.py
import requests
HEADERS = {
"User-agent": "YOUR USER AGENT"
}
SITE_URL = "jamesg.blog"
def find_robots_directives():
"""
@capjamesg
capjamesg / macros.lua
Created Jul 18, 2021
Some of my Keybow macros.
View macros.lua
require "keybow"
muted = false
-- this code lets me press multiple keys at once (use a keyboard shortcut)
-- I found the modifier function online but cannot remember the source
function modifier(key, ...)
for i = 1, select('#', ...) do
local j = select(i, ...)
@capjamesg
capjamesg / markdown_jekyll_to_img_tags.py
Created Jul 11, 2021
This program converts ![]() markdown image syntax to an img tag with a u-photo microformats2 class.
View markdown_jekyll_to_img_tags.py
import os
for filename in os.listdir("_posts/"):
if ".md" in filename:
with open("_posts/{}".format(filename), "r") as file:
line_number = 0
line_to_replace = ""
lines = list(file.readlines())
final_img_tag = ""
for l in lines:
@capjamesg
capjamesg / opml.py
Created Jun 24, 2021
Process OPML files from Feedly OPML export.
View opml.py
# Written by capjamesg
# Required dependencies: requests, beautifulsoup4
from bs4 import BeautifulSoup
import requests
# Please save your opml file as feed.opml before running this program, otherwise you'll encounter an error
with open("feed.opml", "r") as file:
contents = file.read()
@capjamesg
capjamesg / hcard.py
Created Jun 16, 2021
Print a hcard with a thermal printer
View hcard.py
import mf2py
import main
import requests
import os
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
printer.setLineHeight(28)
@capjamesg
capjamesg / analytics.sh
Created Oct 7, 2020
A bash script to parse my nginx access logs.
View analytics.sh
#!/bin/bash
rm /home/james/logs/*
log_files=/home/james/logs/
# Copy log files to temporary directory
cp /var/log/nginx/access*.gz $log_files
@capjamesg
capjamesg / webmention_feed.py
Created Oct 3, 2020
Convert webmention.io JSON to an RSS feed.
View webmention_feed.py
import json
import requests
import datetime
from feedgen.feed import FeedGenerator
# Retrieve most recent 10 webmentions
open_feed = requests.get("WEBMENTION_IO_API_URL")
fg = FeedGenerator()