Skip to content

Instantly share code, notes, and snippets.

@daniel-j
daniel-j / closure.nim
Last active February 28, 2024 21:20
Nim closure wrapping C with generics
# does not leak with --mm:arc :)
# nim c -d:release -d:useMalloc --debugger:native --mm:arc --threads:off closure && valgrind --leak-check=full ./closure
{.emit: """
typedef void(* c_callback) (int param, void *arg);
struct cState {
int param;
@daniel-j
daniel-j / README.md
Last active February 21, 2024 06:48
Converts images in a directory to a comic/manga EPUB3 ebook. Can be used to convert extracted CBZ/CBR to EPUB3.

images2epub.py

Converts a directory of images into a modern EPUB3 ebook. Use a tool to extract CBZ/CBR/CBT files and then run this program to generate a nice fixed-layout EPUB ebook of it. You can optionally set the reading direction to right-to-left (e.g. for manga). For Kobo ereaders, use the file extension .kepub.epub to get the modern reader and correct reading direction.

Usage

Install dependencies with pip install imagesize lxml

@daniel-j
daniel-j / hdmvpgs.js
Last active February 8, 2024 09:27
HDMV/PGS subtitle Javascript parser
'use strict'
function HDMVPGS (ctx) {
this.ctx = ctx || document.createElement('canvas').getContext('2d')
this.lastVisibleSegment = null
this.segments = []
this.loaded = false
}
HDMVPGS.prototype.loadBuffer = function (arraybuffer) {
@daniel-j
daniel-j / piglow_fft.py
Last active January 14, 2024 02:28
PiGlow FFT audio visualizer | https://youtu.be/lJcLoAAGdoo
#!/usr/bin/env python
# by djazz, using various bits of code found over the web
# works with both python2 and python3
# requires: python-alsaaudio, python-numpy, python-smbus, piglow
# install piglow: curl get.pimoroni.com/piglow | bash
# usage:
# this script accepts raw audio in this format: S16LE 44100 kHz Mono
# script-that-outputs-audio | python piglow_fft.py
@daniel-j
daniel-j / spotify.js
Last active January 6, 2024 04:19
A simple node.js program to listen to Spotify tracks, albums and playlists
#!/usr/bin/env node
'use strict';
/*
This is a simple Spotify cli-based client with optional Icecast2/shout support!
It should work for non-premium users, but you must connect your Spotify account to Facebook.
Usage:
$ node spotify <spotify uris> <playlist uri> <album uri> <track uri> <etc...>
@daniel-j
daniel-j / moonradio.m3u
Last active October 23, 2023 19:24
Parasprite Radio Playlists
music/Sailor Moon/English/Full Moon Collection/01 - Pan Flute.flac
music/Sailor Moon/English/Full Moon Collection/02 - Sailor Moon Theme (S.A.F. Remix).flac
music/Sailor Moon/English/Full Moon Collection/07 - Moon Crystal Power.flac
music/Sailor Moon/English/Full Moon Collection/13 - Tuxedo Mask.flac
music/Sailor Moon/English/Full Moon Collection/16 - Nothing At All.flac
music/Sailor Moon/English/Full Moon Collection/18 - It's A New Day.flac
music/Sailor Moon/English/Full Moon Collection/20 - Sailor Moon Theme (S.A.F. Club Mix).flac
music/Sailor Moon/English/Full Moon Collection/21 - Queen Beryl.flac
music/Sailor Moon/English/Songs From the TV Series/01 - Sailor Moon Theme Song.flac
music/Sailor Moon/English/Songs From the TV Series/02 - I Want to be a Star.flac
@daniel-j
daniel-j / gpd-powerinfo.py
Created May 4, 2018 08:10
Script to read the battery drain/charge rate of the GPD Pocket, outputs wattage. Negative is draining, positive is charging.
#!/usr/bin/python3
dir='/sys/class/power_supply/max170xx_battery/'
with open(dir + 'current_avg', 'r') as f:
current = int(f.read()) / 1000000.0
with open(dir + 'voltage_avg', 'r') as f:
voltage = int(f.read()) / 1000000.0
wattage = voltage * current
# print('{0:.2f}V {1:.2f}A {2:.2f}W'.format(voltage, current, wattage))
@daniel-j
daniel-j / main.nim
Last active September 15, 2022 11:42
super simple nim video player with libmpv. requires nimterop for now
from mpvclient as mpv import nil
proc mpv_check_error(status: cint) =
if status < 0:
echo "mpv API error: ", mpv.mpv_error_string(status)
quit(1)
proc main: int =
result = 1
@daniel-j
daniel-j / wallpaper-changer
Last active July 26, 2022 08:07
This is a simple random wallpaper changer to use with Awesome WM. You need to install feh to use this.
#!/bin/bash
#
# Created by djazz // Dangershy
# Dependencies: feh
#
FOLDER="~/Pictures/wallpapers"
DELAY=10
# to make it loop over lines instead of spaces in filenames
@daniel-j
daniel-j / obs-visualizer.html
Last active March 14, 2021 19:09
OBS-Studio Audio Visualizer. Add --enable-media-stream to Linux Browser command line arguments.
<!DOCTYPE html>
<html>
<head>
<title>Visualizer</title>
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;