Skip to content

Instantly share code, notes, and snippets.

josephernest

View GitHub Profile
@josephernest
josephernest / _pdf_cut_half.py
Last active Jun 2, 2020
Cut PDF pages in two halfs + rotated (ready for ereaders!)
View _pdf_cut_half.py
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 Oct 14, 2018
Examples of FullTextSearch, spellfix, FullTextSearch+spellfix together, with Python and Sqlite
View fulltextsearch.py
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 / mklinkgui.py
Last active Sep 3, 2018
mklinkgui - make symbolic links in Windows Explorer with context menu
View mklinkgui.py
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 / wave.py
Last active May 13, 2019
wave.py (enhanced)
View wave.py
# 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 / eeencode.py
Created Jan 26, 2017
Sublime Text plugin that adds simple encryption/decryption with password. Available with CTRL+SHIFT+P as "Eeencode" and "Dddecode"
View eeencode.py
# Based on http://stackoverflow.com/a/16321853/1422096
# Added a few things to support UTF8.
#
# Install:
# 1) Put the file in C:\Users\***\AppData\Roaming\Sublime Text 2\Packages\User
# 2) Add a reference in C:\Users\***\AppData\Roaming\Sublime Text 2\Packages\User\Default.sublime-commands:
# [{ "caption": "Eeencode", "command": "eeencode" }, { "caption": "Dddecode", "command": "dddecode" }]
import sublime, sublime_plugin
View hamburger_icon.md

Here is a solution, inspired of DenisSheremet's comment and slightly modified.

[![enter image description here][1]][1]

document.getElementById('nav').addEventListener('click', function() { 
    document.getElementById('hello').className = ''; 
@josephernest
josephernest / wavfile.py
Last active Jul 4, 2020
wavfile.py (enhanced)
View wavfile.py
# 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)
View markdowntemplate.html
<!--
#
# This is a Markdown template. Write in Markdown in the main #content div. Let the result be rendered automatically.
#
# author: Joseph Ernest (twitter: @JosephErnest)
# url: http://github.com/josephernest/
# license: MIT license
-->
<!DOCTYPE html>
@josephernest
josephernest / findduplicateswholedisk.py
Last active Nov 15, 2016
Find duplicates in a whole disk
View findduplicateswholedisk.py
# -*- coding: utf-8 -*-
# DUPLICATES FINDER
# Nov 15, 2016, Joseph Ernest
#
# Required: Python 64 (Reminder: change build system to Python64 in Sublime)
PATH = 'd:\\' # path
N = 10*1024*1024 # find duplicates in files bigger than ... MB
@josephernest
josephernest / daemon.py
Last active May 7, 2020
Daemon for Python
View daemon.py
# 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
You can’t perform that action at this time.