Skip to content

Instantly share code, notes, and snippets.

View Ddedalus's full-sized avatar

Hubert Bereś Ddedalus

View GitHub Profile
@Ddedalus
Ddedalus / progressBar.Rmd
Created May 12, 2018 22:33
Progress bar by text in R
```{r}
pb <- txtProgressBar(min = 0, max = 20, style = 3)
for(i in 1:20){
Sys.sleep(0.1)
# update progress bar
setTxtProgressBar(pb, i)
}
close(pb)
```
@Ddedalus
Ddedalus / Law of Large Numbers for Binomial.tex
Created May 22, 2018 16:48
Sets and probability theory operators - commands for LaTeX preamble
% define basic sets:
\newcommand{\R}{\mathbb{R}} % real numbers
\newcommand{\N}{\mathbb{N}} % natural numbers
\newcommand{\Z}{\mathbb{Z}} % integers etc.
\newcommand{\bb}{\mathbb} % blackboard font
%and probability operators
\newcommand{\Pb}[1]{\mathbb{P}(#1)}
\newcommand{\Ex}[1]{\mathbb{E}(#1)}
@Ddedalus
Ddedalus / Law of Large Numbers for Binomial.tex
Last active May 22, 2018 16:51
Multiline equations in LaTeX
\usepackage{amsmath}
% lazy numbering for aling*:
\newcommand{\numberthis}{\addtocounter{equation}{1}\tag{\theequation}}
%in the document:
\begin{align*}
&\Pb{X_n > n(p + \epsilon)} = \sum_{j = K}^{n} \Pb{X_n = j} \\
&\leq \sum_{j = K}^{n} \Pb{X_n = K} r_K ^{j-K}
\leq \sum_{j = K}^{\infty} \Pb{X_n = K} r_K ^{j-K} \\
&= \Pb{X_n = K} \cdot \frac{1}{1 - r_K} \numberthis \label{eq:bound}
@Ddedalus
Ddedalus / any.tex
Created May 22, 2018 16:52
LaTeX: Right alligned square
\raggedleft $ \square $
@Ddedalus
Ddedalus / Henkel.Rmd
Created June 5, 2018 17:42
Remove some strange characters to form a valid column name
colnames()%<>% trimws %>% gsub("\\(%\\)", "pp", .) %>%
make.names %>% gsub("\\.+", "\\.", .)
# whitespace from the beginning/end is trimmed
# replaces (%) with a "pp" abbreviation for percentage
# all white chars are subed with a dot
# multiple dots are concatenated to a single one
require(magrittr)
@Ddedalus
Ddedalus / POETS_Input_Analysis.Rmd
Created June 18, 2018 12:20
Label points on a plot
plot(sapply(nets, gorder), sapply(nets, gsize),
xlab="vertices", ylab="edges")
text(sapply(nets, gorder), sapply(nets, gsize), labels = netNames, pos = c(3, 4, 4, 4, 4, 2, 3, 2, 3))
######### pos: vector of label locations: 1-below, 2-left, 3-above, 4-right; may be just a single number
######### the same ploting series must be passed to the plot and text. May use with(df, ...) for convenience
@Ddedalus
Ddedalus / runOnSizes.R
Created June 19, 2018 10:19
Attributes in R
attr(obj, 'name') <- value
attributes(obj)
@Ddedalus
Ddedalus / main.cpp
Created June 27, 2018 11:35
Size of adjacency list
uint64_t size = 0;
for(auto n : neighbours){
size += n.size() * sizeof(uint32_t);
}
cout<< "Loaded large graph. Size of adj. list is: " << size << endl;
@Ddedalus
Ddedalus / bash
Created June 27, 2018 11:52
Release build in CMake
cd release
cmake -DCMAKE_BUILD_TYPE=Debug ..
@Ddedalus
Ddedalus / shell
Created June 28, 2018 10:46
discard unstaged git changes
git checkout filename
git checkout -- filename # if it happend to clash with branch name