Skip to content

Instantly share code, notes, and snippets.

View capjamesg's full-sized avatar
writing words and code

James capjamesg

writing words and code
View GitHub Profile
@capjamesg
capjamesg / cracklepop.lisp
Created September 21, 2022 12:29
An implementation of CracklePop in Lisp.
(defun cracklepop (num)
(cond
((and (= (mod num 3) 0) (= (mod num 5) 0)) "CracklePop")
((= (mod num 3) 0) "Crackle")
((= (mod num 5) 0) "Pop")
(num)))
(loop for val from 1 below 100 do (print (cracklepop val)))
@capjamesg
capjamesg / checkins.rb
Created September 11, 2022 17:11
Script for generating checkins from a CSV on my website
require "csv"
for c in CSV.foreach("cafes.csv", :quote_char => '"', :col_sep =>', ', :headers => true)
slug = c['place_name'].downcase.gsub(/[^a-z0-9]+/i, '-')
front_matter = "
---
layout: checkin
latitude: #{c["lat"]}
longitude: #{c["long"]}
@capjamesg
capjamesg / robots.py
Last active August 10, 2021 10:06
robots.txt parser in Python
import requests
HEADERS = {
"User-agent": "YOUR USER AGENT"
}
SITE_URL = "jamesg.blog"
def find_robots_directives():
"""
@capjamesg
capjamesg / macros.lua
Created July 18, 2021 08:17
Some of my Keybow macros.
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 July 11, 2021 09:12
This program converts ![]() markdown image syntax to an img tag with a u-photo microformats2 class.
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 June 24, 2021 10:05
Process OPML files from Feedly OPML export.
# 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 June 16, 2021 07:05
Print a hcard with a thermal printer
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 October 7, 2020 08:35
A bash script to parse my nginx access logs.
#!/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