Skip to content

Instantly share code, notes, and snippets.

@josephernest
josephernest / wavfile.py
Last active March 17, 2024 02:54
wavfile.py (enhanced)
# wavfile.py (Enhanced)
# Date: 20190213_2328 Joseph Ernest
#
# URL: https://gist.github.com/josephernest/3f22c5ed5dabf1815f16efa8fa53d476
# Source: scipy/io/wavfile.py
#
# Added:
# * read: also returns bitrate, cue markers + cue marker labels (sorted), loops, pitch
# See https://web.archive.org/web/20141226210234/http://www.sonicspot.com/guide/wavefiles.html#labl
# * read: 24 bit & 32 bit IEEE files support (inspired from wavio_weckesser.py from Warren Weckesser)
@josephernest
josephernest / daemon.py
Last active March 22, 2023 05:20
Daemon for Python
# From "A simple unix/linux daemon in Python" by Sander Marechal
# See http://stackoverflow.com/a/473702/1422096 and http://web.archive.org/web/20131017130434/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
#
# Modified to add quit() that allows to run some code before closing the daemon
# See http://stackoverflow.com/a/40423758/1422096
#
# Modified for Python 3 (see also: http://web.archive.org/web/20131017130434/http://www.jejik.com/files/examples/daemon3x.py)
#
# Joseph Ernest, 20200507_1220
"""
zeroterm is a light weight terminal allowing both:
* lines written one after another (normal terminal/console behaviour)
* fixed position text
Note: Requires an ANSI terminal. For Windows 7, please download https://github.com/downloads/adoxa/ansicon/ansi160.zip and run ansicon.exe -i to install it.
"""
from sys import stdout
import time
Hello, now click on the "Back" history button of your browser.
{"state": "checked"}
@josephernest
josephernest / wave.py
Last active March 24, 2022 17:23
wave.py (enhanced)
# wave.py (Enhanced)
# Date: 2018/04/30 Joseph Ernest
#
# URL: https://gist.github.com/josephernest/e3903ba30b820cd199500e50f145a11f
# Source: Lib/wave.py
#
# Added:
# * IEEE support
# * 24 bit support
# * cue + loops markers support
@josephernest
josephernest / duckdbtest.py
Last active January 1, 2021 13:51
Quick benchmark of DuckDB / Sqlite3 (disclaimer: it doesn't necessarily showcase the power of both solutions, there might be better ways I'm not aware of)
"""
Quick benchmark of DuckDB / Sqlite3 (disclaimer: it doesn't necessarily showcase the power of both solutions, there might be better ways I'm not aware of)
https://gist.github.com/josephernest/2c02f7627b83a32fd2086fe9dde15215.js
https://github.com/cwida/duckdb/issues/1249
1M rows 10M rows 20M rows 50M rows
duckdb 13ms ? 130ms ? 285ms ? ?
sqlite 13ms 26 MB 113ms 260 MB 221ms 527 MB ?
"""
@josephernest
josephernest / index.html
Last active December 29, 2020 18:15
Electron Fiddle Gist
<html>
<head>
<style>
* { margin: 0; }
#topright { float: right; width: 100px; background-color: blue; -webkit-app-region: no-drag; }
#topright:hover { background-color: black; }
#topleft { background-color: red; -webkit-app-region: drag; padding: 10px; }
</style>
</head>
<body>
@josephernest
josephernest / _pdf_cut_half.py
Last active June 2, 2020 07:16
Cut PDF pages in two halfs + rotated (ready for ereaders!)
import os, glob, pdfrw # todo: pip install pdfrw
for f in glob.glob('*.pdf'):
if '_cut.pdf' in f:
continue
writer = pdfrw.PdfWriter()
for page in pdfrw.PdfReader(f).pages:
for y in [0, 0.5]:
newpage = pdfrw.PageMerge()
newpage.add(page, viewrect=(0, y, 1, 0.5))
p = newpage.render()
@josephernest
josephernest / fulltextsearch.py
Created October 14, 2018 18:26
Examples of FullTextSearch, spellfix, FullTextSearch+spellfix together, with Python and Sqlite
import sqlite3
db = sqlite3.connect(':memory:')
c = db.cursor()
c.execute('CREATE TABLE mytable (description text)')
c.execute('INSERT INTO mytable VALUES ("Riemann")')
c.execute('INSERT INTO mytable VALUES ("All the Carmichael numbers")')
print '1) EQUALITY'
c.execute('SELECT * FROM mytable WHERE description == "Riemann"'); print 'Riemann:', c.fetchall()