Skip to content

Instantly share code, notes, and snippets.

View zwim's full-sized avatar
🌴
on vacation

zwim

🌴
on vacation
  • Austria
View GitHub Profile
@zwim
zwim / 2-TOC-title-patch.lua
Created June 28, 2022 15:57
Patch for KOReader to show Document title in table of contents
-- a patch for changing ToC title to book title
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local ReaderToc = require("apps/reader/modules/readertoc")
local onShowToc_orig = ReaderToc.onShowToc
ReaderToc.onShowToc = function(self)
-- Run original code
@zwim
zwim / 2-toggle-usbnet.lua
Last active August 12, 2022 05:42
Patch for KOReader to show a menu entry for usbnet toggle in the network menu
-- a patch for KOReader to add a menu entry for usbnet toggle in the network menu
-- for usage on a Kobo eReader
local logger = require("logger")
local usbnet_toggle_path = "/usr/bin/usbnet-toggle"
if lfs.attributes(usbnet_toggle_path, "mode") == "file" then
local reader_menu_order = require("ui/elements/reader_menu_order")
@zwim
zwim / paris-ipairs-index-bench.lua
Created October 24, 2022 19:52
LUAJIT Comparison of pairs, ipairs and indexing
#!/usr/bin/env luajit
--[[
Adapted from https://gist.github.com/dpino/647b9d2e12aa8ff859b4
Environment: Lenovo ThinkPad T520 / 16GB RAM / i7-3740QM CPU @ 2.70GHz
| pairs | ipairs | indexing |
| 1.000000 | 4.283464 | 4.058733 |
| 0.233456 | 1.000000 | 0.947535 |
@zwim
zwim / 2-touchmenu-update-clock.lua
Last active January 9, 2023 20:29
Update the clock and battery state every minute
-- a patch for updating the touch menu clock every minute
-- Version 2.0: use closeMenu() to unschedule
-- Version 3.0: use onLeaveStandby to update, too
-- This is just a quick hack, which updates the whole menu.
-- It would be more efficient, if only the TouchMenu.time_info widget would get updated.
local UIManager = require("ui/uimanager")
local TouchMenu = require("ui/widget/touchmenu")
@zwim
zwim / 10-UpdateGermanPattern.lua
Last active December 19, 2022 19:28
KOREADER: A quick'n'dirty patch to allow overwriting the provided hyphenation pattern with a pattern file located in `/mnt/onboard/German.pattern`
-- A patch for updating a German.pattern file, if this is newer than the provide one.
-- quick and dirty; for my personal usage, will most likely not fit any other users needs
print("Update hyphenation patterns")
local language = "German" -- is someone wants to use this patch with another language
local xxx = "" -- add your location here
local lfs = require("libs/libkoreader-lfs")
local DataStorage = require("datastorage")
@zwim
zwim / 09-UpgradeMessage.lua
Last active December 20, 2022 06:25
Show a message, when KOReader was updated on next start.
-- a patch for showing a message after an update of KOReader
local lfs = require("libs/libkoreader-lfs")
local DataStorage = require("datastorage")
local ffiutil = require("ffi/util")
local patch_dir = DataStorage:getDataDir() .. "/patches"
if lfs.attributes(patch_dir .. "/09-UpgradeMessage.lua", "mode") == "file" then
os.remove(patch_dir .. "/29-UpgradeMessage.lua") -- to be safe, as there coulde be a patch with that name ;)
@zwim
zwim / 2-no-keyboard-shortcut.lua
Last active March 3, 2023 19:59
Don't show keyboard shortcut on KOReader devices which have a keyboard. (see https://gist.github.com/zwim/b0d46fa83d9dbb853324f3e0c17562b5)
-- 2-no-keyboard-shortcuts.lua
--
-- Hides keyboard shortcuts on devices with keyboard.
local Device = require("device")
Device.hasKeyboard = function () return false end
@zwim
zwim / 2-limit-crashlog-size.lua
Last active May 15, 2023 17:21
KOReader user patch, to limit the crash.log's filesize during run
-- A KOReader patch for limiting the crash.log file size during run (and not only on KOReader start)
-- The menu entry can be found in Filemanager: Settings > More tools > Developer options > Limit log file size
-- Version 0.2
-- Kobo os.execute("truncate") is not available -> os.execute("busybox truncate")
-- Version 0.3
-- onSuspend and onResume work now
-- Version 0.4
-- unschedule tasks in onClose