2020-04-16 15:33:59 +02:00
#+TITLE : My Own Library of Babel
2021-01-01 20:12:34 +01:00
#+SETUPFILE : ./setup/org-setup-file.org
2020-04-16 15:33:59 +02:00
* =get-password= - Get Password from =pass=
#+name : get-password
#+begin_src bash :var passname="""
2021-01-08 01:26:27 +01:00
pass $passname | sed -n 1p
2020-04-16 15:33:59 +02:00
#+end_src
* =pdf2svg= - Export to pdf/png/svg at the same time
#+name : pdf2svg
#+begin_src sh :var file="" :var ext= "svg" :results output
2021-01-08 01:26:27 +01:00
_mydir="$(pwd)";
file=$(echo "$file" | cut -f 2- -d ':');
_figdir=$(dirname "$file");
cd $_figdir;
filename=$(echo "${file##*/}" | cut -f 1 -d '.');
pdftocairo -png -transp -singlefile "$filename.pdf";
pdftocairo -svg "$filename.pdf";
cd "$_mydir";
echo "[[file:$_figdir/$filename.$ext ]]"
2020-04-16 15:33:59 +02:00
#+end_src
* =addhdr= - Add hline to tables
#+name : addhdr
#+begin_src emacs-lisp :var tbl=""
2021-01-08 01:26:27 +01:00
(cons (car tbl) (cons 'hline (cdr tbl)))
2020-04-16 15:33:59 +02:00
#+end_src
* Matlab Related
** =matlab-dir= Go to current directory
#+name : matlab-dir
#+begin_src matlab :tangle no :results none :exports none :var current_dir=""
2021-01-08 01:26:27 +01:00
%% Go to current Directory
cd(current_dir);
2020-04-16 15:33:59 +02:00
2021-01-08 01:26:27 +01:00
%% Initialize ans with org-babel
ans = 0;
2020-04-16 15:33:59 +02:00
#+end_src
** =matlab-init= Initialize matlab
#+name : matlab-init
#+begin_src matlab :results none :exports none
2021-01-08 01:26:27 +01:00
%% Clear Workspace and Close figures
clear; close all; clc;
2020-04-16 15:33:59 +02:00
2021-01-08 01:26:27 +01:00
%% Intialize Laplace variable
s = zpk('s');
2020-04-16 15:33:59 +02:00
#+end_src
** =plt-matlab= Plot figures
Some variable can be set by block that expands this org source code block:
- =path= : specify the path of the figure including the file extension. Can be relative or absolute. If not provided, it will create the figure in the =/tmp= folder
- =fig_size= : can specify the size of the figure. If not specify, default will be applied.
#+name : plt-matlab
#+begin_src matlab :results value raw replace :exports code :var filepath="" :var figsize= "normal-normal"
2021-01-08 01:26:27 +01:00
if ~exist('filepath') || length(filepath) < 2
symbols = ['a':'z' 'A':'Z' '0':'9'];
random_string = symbols(randi(numel(symbols),[1 5]));
filepath = ['/tmp/matlab-fig-', random_string];
end
2020-04-16 15:33:59 +02:00
2021-01-08 01:26:27 +01:00
size_strings = strsplit(figsize, '-');
2020-04-16 15:33:59 +02:00
2021-01-08 01:26:27 +01:00
ans = exportFig(filepath, 'width', size_strings{1}, 'height', size_strings{2});
2020-04-16 15:33:59 +02:00
#+end_src