Skip to content

Instantly share code, notes, and snippets.

@milasudril
milasudril / genpattern.m
Created April 6, 2016 08:08
Matlab/Octave pattern generator
function [pattern]=genpattern(stamp,d_max,pattern_size,density)
density=density/prod(pattern_size);
pattern=rand(pattern_size)<density;
[y,x]=find(pattern);
d=2*norm(0.5*size(stamp,1) , 0.5*size(stamp,2));
pattern=zeros(pattern_size);
disp(numel(y))
for k=1:numel(y)
B=rand()*imrotate(stamp,360*rand(),'bicubic','loose',0);
B=double( rand()*imresize(B,d_max*(0.5+0.5*rand())/d,'bicubic') )/255;
@milasudril
milasudril / texmakedeps.sh
Last active November 14, 2015 08:37
Shell script generating deps for LaTeX compilation
#!/bin/bash
filename=$1
echo $filename
reportname=${filename%.*}
grep -o '\\input{[a-z/.A-Z_0-9\-]*}' $filename \
| sed 's/\\input{\([a-z/.A-Z_0-9\-]*\)}/\1/g' > deps.txt
grep -o '\\includegraphics\(\[.*\]\)*{[a-z/.A-Z_0-9\-]*}' $filename \
#!/bin/bash
sudo apt-get install apt-transport-https software-properties-common wget
wget https://launchpad.net/~kxstudio-debian/+archive/kxstudio/+files/kxstudio-repos_9.2.1~kxstudio1_all.deb
sudo dpkg -i kxstudio-repos_9.2.1~kxstudio1_all.deb
sudo apt-get install bc
DISTRIB_RELEASE=`lsb_release -sr`
if [ $(echo "$DISTRIB_RELEASE >= 15.10" | bc) -eq 1 ]; then
wget https://launchpad.net/~kxstudio-debian/+archive/kxstudio/+files/kxstudio-repos-gcc5_9.2.1~kxstudio1_all.deb
sudo dpkg -i kxstudio-repos-gcc5_9.2.1~kxstudio1_all.deb
#!/bin/bash
OPTIND=1
rate=48000
period=64
cloop=0
show_help()
{
echo 'Starts the JACK(1) server using graphical choice of device. Options:
-r sample_rate in Hz
function get_tempo(filename)
[data,fs]=wavread(filename);
beat_spectrum=abs(fft(data.^2)./length(data));
f=linspace(0,1,length(beat_spectrum ))*fs*60;
index=find(f>=30 & f<=480);
plot(f(index),beat_spectrum(index));
xlabel('BPM');
ylabel('Intensity');
xlim([30 480]);
set(gca,'XTick',30:30:480);
@milasudril
milasudril / genrefs.sh
Created August 17, 2015 10:53
XSL thing for writing LaTeX bibliography. The template inspired by CTH style guide.
#!/bin/bash
bibstyle=$(grep '\\bibstyle' "${1}" | sed -r 's/(\\bibstyle\{)(.*)\}/\2/').xsl
bibdata=$(grep '\\bibdata' "${1}" | sed -r 's/(\\bibdata\{)(.*)\}/\2/').xml
bblfile="${1%.*}".bbl
echo "Writing $bibdata to $bblfile"
xsltproc "$bibstyle" "$bibdata" > "$bblfile"
%%
%% This is file `mybibstyle.bst',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% merlin.mbs (with options: `ay,har,harnm,vonx,nm-rev,ed-rev,jnrlst,nmlm,x2,m1,blkyear,dt-beg,yr-par,aymth,dtrev,note-yr,jxper,trtit-b,vnum-cm,volp-com,pgsep-s,jwdpg,pp-last,jwdvol,num-xser,ser-vol,ser-ed,add-pub,isbn,issn,url-doi,edparxc,bkedcap,blk-tit,pp,abr,ednx,ord,etal-xc,url,url-blk,nfss,')
%% ----------------------------------------
%% *** CTH ***
%%
@milasudril
milasudril / csvformat.cpp
Last active August 29, 2015 14:25
Simple csv formatter
// Compile with g++ -std=c++11 -O2 -DNDEBUG csvformat.cpp -o csvformat
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdint>
struct Option
{
@milasudril
milasudril / gabish.cpp
Last active August 29, 2015 14:18
Simple shell with calculator facilities. Not complete but it does something...
#ifdef __WAND__
target[name[gabish] type[application] platform[;GNU/Linux]]
#endif
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <cmath>
@milasudril
milasudril / fundamental-frequency.cpp
Last active August 29, 2015 14:07
Compute fundamental frequency
#ifdef __WAND__
target[name[mindist_test] type[application]]
#endif
#include <herbs/array_fixedsize/array_fixedsize.h>
#include <herbs/array/array.h>
#include <herbs/pairsame/pairsame.h>
#include <algorithm>
#include <cstdio>