Skip to content

Instantly share code, notes, and snippets.

View standy66's full-sized avatar

Andrew Stepanov standy66

  • Quantum Light Capital
  • London, United Kingdom
View GitHub Profile
@standy66
standy66 / vpio-macos-example.cc
Created January 21, 2019 09:28
Voice-Processing I/O MacOS example
#include <iostream>
#include <cmath>
#include <fstream>
#include <AudioToolbox/AudioToolbox.h>
// Files with raw float32 data
std::ifstream ifile("ifile.f32");
std::ofstream file("file.f32");
OpenSSL 1.0.2g 1 Mar 2016
built on: reproducible build, date unspecified
options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: cc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 0.00 0.00 0.00 0.00 0.00
mdc2 0.00 0.00 0.00 0.00 0.00
md4 127034.79k 377429.23k 859238.66k 1
OpenSSL 1.0.2k 26 Jan 2017
built on: reproducible build, date unspecified
options:bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) aes(partial) idea(int) blowfish(ptr)
compiler: arm-brcm-linux-uclibcgnueabi-gcc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -ffunction-sections -fdata-sections -O3 -Wall -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DBSAES_ASM -DGHASH_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
md2 0.00 0.00 0.00 0.00 0.00
mdc2 2197.96k 2339.09k 2417.00k 2428.89k 2446.42k
md4 11506.71k 38225.13k 93329.90k 151152.50k 184607.98k
md5 8904.43k 27768.25k 67982.16k 104957.58k 124709.36k
@standy66
standy66 / c_extension_call_overhead.py
Created March 28, 2018 21:29
PyPy vs CPython extension call overhead
"""
Original code: https://gist.github.com/brentp/7e173302952b210aeaf3
Compare speed of a cython wrapper vs a cffi wrapper to the same underlying
C-code with a fast function and a longer-running function.
This should run anywhere that has cffi and cython installed.
$ python3.6 -V
Python 3.6.2 (default, Jul 17 2017, 16:44:45)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
"""
Based on example here: https://gist.github.com/awni/56369a90d03953e370f3964c826ed4b0
"""
import numpy as np
import math
import collections
NEG_INF = -float("inf")
@standy66
standy66 / variable_scope.py
Last active August 20, 2017 18:27
tf variable scope example
with tf.name_scope("subgraph_1"):
with tf.variable_scope(tf.get_variable_scope(), resue=False):
y_1 = output(x_1)
with tf.name_scope("subgraph_2"):
with tf.variable_scope(tf.get_variable_scope(), reuse=True):
y_2 = output(x_2)
@standy66
standy66 / pymystem3_example.py
Created August 2, 2017 14:27
pymystem3 example
import sys, re, pymystem3
mystem = pymystem3.Mystem()
def stem(s):
return [(e['text'].strip(), \
e['analysis'][0]['lex'] \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
re.match('^([A-Z]+)', e['analysis'][0]['gr']).group(0) \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
@standy66
standy66 / sawtooth.py
Created July 13, 2017 09:12
Python sawtooth wave generator
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Audio
from scipy.signal import spectrogram
sample_rate = 8000
t = np.arange(0, 10, 1.0/sample_rate)
x = t % (2 / sample_rate)
plt.figure(figsize=(16, 6), dpi=200)
@standy66
standy66 / audio_from_spectrogram.py
Created July 12, 2017 14:47
A small snippet that helps reconstruct audio from spectrogram in Python
from scipy.signal import stft, istft
def reconstruct(spectrogram, sample_rate, nperseg, iters=100):
length = istft(spectrogram, sample_rate, nperseg=nperseg)[1].shape[0]
x = np.random.normal(size=length)
for i in range(iters):
# Code based on the answer here: https://dsp.stackexchange.com/a/3410
X = stft(x, sample_rate, nperseg=nperseg)[2]
Z = spectrogram * np.exp(np.angle(X) * 1j)
x = istft(Z, sample_rate, nperseg=nperseg)[1]
\documentclass[a4paper,12pt]{article}
\usepackage[T2A]{fontenc}
%\usepackage[utf8]{inputenc} % older versions of ucs package
\usepackage[utf8x]{inputenc} % more recent versions (at least>=2004-17-10)
\usepackage[russian]{babel}
\usepackage{amsmath}
\sloppy % Hyphenation is a problem..