Skip to content

Instantly share code, notes, and snippets.

@jameslyons
jameslyons / gist:7819163
Created December 6, 2013 05:47
test gist
for i = 1:10
print(i)
end
import urllib
from xml.etree.ElementTree import parse
URL = '''http://jameslyons0.blogspot.com.au/feeds/posts/default?max-results=9999'''
xml = parse(urllib.urlopen(URL)).getroot()
info = {}
for post in xml.getchildren():
if post.tag=='{http://www.w3.org/2005/Atom}entry':
headers,title,link=[],None,None
@jameslyons
jameslyons / caesarCipher.py
Last active May 27, 2024 20:52
Caesar Cipher Python
# we need 2 helper mappings, from letters to ints and the inverse
L2I = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ",range(26)))
I2L = dict(zip(range(26),"ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
key = 3
plaintext = "DEFEND THE EAST WALL OF THE CASTLE"
# encipher
ciphertext = ""
for c in plaintext.upper():
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[]){
char plaintext[] = "DEFEND THE EAST WALL OF THE CASTLE";
int L = strlen(plaintext);
char *ciphertext = malloc(sizeof(char)*(L+1));
// enciphering
plaintext = "DEFEND THE EAST WALL OF THE CASTLE";
var key = 3;
ciphertext = ""; var re = /[a-z]/;
for(i=0; i<plaintext.length; i++){
if(re.test(plaintext.charAt(i))) ciphertext += String.fromCharCode((plaintext.charCodeAt(i) - 97 + key)%26 + 97);
else ciphertext += plaintext.charAt(i);
}
// deciphering
# return the autocorrelation of x
function ac(x)
N = length(x)
# zero pad x
x = [x,zeros(N-1)]
R = irfft(abs(rfft([2,3,1,0,0])).^2, 2*N-1)
R[1:N]
end
x = [2,3,1]
@jameslyons
jameslyons / levinson.jl
Last active October 26, 2023 02:59
Levinson durbin recursion for LPC calculation
function levinson(R,L)
a = zeros(L,L)
P = zeros(1,L)
# for m = 1
a[1,1] = -R[2]/R[1]
P[1] = R[1]*(1-a[1,1]^2)
# for m = 2,3,4,..L
for m = 2:L
@jameslyons
jameslyons / arcov.jl
Last active January 18, 2016 08:39
covariance method of LPC calculation
function arcov(x,L)
N = length(x)
phi = zeros(L+1,L+1)
for k = 0:L, i=0:L, n=L:N-1
phi[k+1,i+1] += x[n+1-k]*x[n+1-i]
end
phi = phi./(N-L)
a = phi[2:end,2:end]\-phi[2:end,1]
P = phi[1,1] + phi[1,2:end]*a
@jameslyons
jameslyons / armcov.jl
Last active January 18, 2016 08:39
Modified covariance method (a.k.a forward-backward method) of LPC calculation
function armcov(x,L)
N = length(x)
phi = zeros(L+1,L+1)
for k = 0:L, i=0:L, n=0:N-L-1
phi[k+1,i+1] += x[n+1+k]*x[n+1+i] + x[n+1+L-k]*x[n+1+L-i]
end
phi = phi./(2*(N-L))
a = phi[2:end,2:end]\-phi[2:end,1]
P = phi[1,1] + phi[1,2:end]*a
  • Update HISTORY.rst
  • Update version number in my_project/__init__.py
  • Update version number in setup.py
  • Run the tests:
python setup.py test
tox
  • Commit the changes: