Skip to content

Instantly share code, notes, and snippets.

@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
/*
# 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"]
"""
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
@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 / 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
@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>
@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)

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 / 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