Skip to content

Instantly share code, notes, and snippets.

@josephernest
josephernest / mklinkgui.py
Last active September 3, 2018 23:24
mklinkgui - make symbolic links in Windows Explorer with context menu
import win32clipboard # pip install pywin32 if needed
import sys, os, subprocess
fname = sys.argv[1]
win32clipboard.OpenClipboard()
filenames = win32clipboard.GetClipboardData(win32clipboard.CF_HDROP)
win32clipboard.CloseClipboard()
for filename in filenames:
base = os.path.basename(filename)
link = os.path.join(fname, base)
subprocess.Popen('mklink %s "%s" "%s"' % ('/d' if os.path.isdir(filename) else '', link, filename), shell=True)
@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()
@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 / 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 / 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 ?
"""
{"state": "checked"}
Hello, now click on the "Back" history button of your browser.