Skip to content

Instantly share code, notes, and snippets.

/*
* 1:1 Lichttunnel
* Kuzmin 2017
* code für Arduino Mega 2560
* Anschlüsse wie in https://youtu.be/xOhIc03cWW4
* Peter Jung (2017)
* 2017-10-18
*/
bpm = 200 # Beats Per Minute (BPM) = Schläge pro Minute
bptakt = 4 #
base = :a4
sc = scale(base, :aeolian)
takt_duration = 60.0/bpm*bptakt
haenschenklein = [
[ [5,1], [3,1], [3,2] ],
[ [4,1], [2,1], [2,2] ],
[ [1,1], [2,1], [3,1], [4,1] ],
@peter-jung
peter-jung / sudoku.py
Created February 23, 2017 07:08
Minimal naive Sudoku solver
sstr = '''
71 4
6 8
3 4 16
6 1
3 8
1 7 2
8 9
53 4 2
4 1 9 '''
@peter-jung
peter-jung / corr_intuition.py
Created February 23, 2017 07:06
check your intuition: when x is evenly distributed around 0, and x^2 are totally uncorrelated
'''
check your intuition: when x is evenly distributed around 0, and x^2 are totally uncorrelated
'''
import pandas as pd
import numpy as np
x = np.random.normal(0,1,1000)
y = x**2
@peter-jung
peter-jung / leveldb_jsonstore.py
Created February 23, 2017 07:05
Minimal JSON-Store based on LevelDB
# leveldb json store
import leveldb
import struct
def i2s(i):
res = ''
while i > 255:
res += chr(i % 256)
i = i >> 8
'''
https://en.wikipedia.org/wiki/Knapsack_problem
'''
v = [1,2,3,2,10]
w = [2,5,7,8,15]
W = 22
n = len(v)
m = [[0 for _ in range(W+1)] for _ in range(n)]
for i in range(n):
@peter-jung
peter-jung / dawkins_weasel.py
Created February 22, 2017 17:42
Minimal implementation of Dawkins Weasel in Python. The aim is to demonstrate that Evolution (Mutation + Selection) is different from pure chance.
# DawkinsWeasel.py
import random
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'
target = 'The aim is to demonstrate that the process that drives evolutionary systems, random variation combined with non-random cumulative selection, is different from pure chance.'
print len(chars), len(target)
#b
def randchar():
@peter-jung
peter-jung / applescript_from_mac.py
Created February 22, 2017 09:28
How to call an Applescript from Python on Mac?
import subprocess, sys
applescript='''
tell application "System Events"
set processName to name of processes whose frontmost is true
do shell script "echo " & processName
end tell
'''
args = [item for x in [("-e",l.strip()) for l in applescript.split('\n') if l.strip() != ''] for item in x]
proc = subprocess.Popen(["osascript"] + args ,stdout=subprocess.PIPE )
progname = proc.stdout.read().strip()
@peter-jung
peter-jung / annuities.py
Created February 22, 2017 09:16
Solving an Annuity Loan for any of the parameters with Newton Raphson
'''
calculate annuities
'''
'''
annuities kernel
s: total amount
r: nominal annual rate
t: duration/years

Keybase proof

I hereby claim:

  • I am peter-jung on github.
  • I am pjung (https://keybase.io/pjung) on keybase.
  • I have a public key whose fingerprint is B7C0 77CB 9C5A B947 4371 E77A 2EFB F090 9E22 0423

To claim this, I am signing this object: