Skip to content

Instantly share code, notes, and snippets.

# note name (example: C3, C#3) into midi note number (example: 60, 61, etc.)
import re
note = "F3"
pattern = r"([A-Ga-g]#?[0-9])"
m = re.match(pattern, note)
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
@josephernest
josephernest / markdowntemplate.html
Created December 2, 2016 11:42
MarkdownTemplate
<!--
#
# 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>

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 / eeencode.py
Created January 26, 2017 17:46
Sublime Text plugin that adds simple encryption/decryption with password. Available with CTRL+SHIFT+P as "Eeencode" and "Dddecode"
# 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
@josephernest
josephernest / simplestdb.js
Created December 22, 2014 22:21
Simplest JSON DB possible in node.js
var DBFILENAME = './myDb.json';
var fs = require('fs'); // filesystem access needed
var myDb = {}; // the DB will be in RAM
try { myDb = JSON.parse(fs.readFileSync(DBFILENAME)); } catch(e) { } // read DB from disk
function serialize() { fs.writeFile(DBFILENAME + '.temp', JSON.stringify(myDb), function(err) { if (!err) { fs.rename(DBFILENAME + '.temp', DBFILENAME); } } ); }
function serializeSync() { fs.writeFileSync(DBFILENAME + '.temp', JSON.stringify(myDb)); fs.rename(DBFILENAME + '.temp', DBFILENAME); }
setInterval(serialize, 60 * 1000); // serialize to disk every minute
process.on('exit', serializeSync); process.on('SIGINT', serializeSync); process.on('SIGTERM', serializeSync); // serialize to disk when process terminates
/*
@josephernest
josephernest / samplerbox_maker.sh
Last active November 14, 2017 23:29
Script to make the SamplerBox ISO Image
#!/bin/bash -v
# CREATE A RASPBIAN JESSIE IMAGE FOR SAMPLERBOX
# 2016-08-31
#
# USAGE: chmod 777 samplerbox_maker.sh ; nohup sudo ./samplerbox_maker.sh &
set -e
sudo apt-get update && sudo apt-get install -y cdebootstrap kpartx parted sshpass zip
@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>