Skip to content

Instantly share code, notes, and snippets.

View exaexa's full-sized avatar

Mirek Kratochvil exaexa

View GitHub Profile
@exaexa
exaexa / tablemagicks.tex
Created January 5, 2023 19:44
table magicks
\newif\ifglzcont
\def\glz{\glzconttrue\expandafter\glzi}
\def\glzi#1{\glzchar{#1}\ifglzcont\expandafter\glzi\else\expandafter\glzeat\fi}
\def\glzeat#1 {\textcolor{black!50}{#1}}
\def\glzchar#1{%
\if0#1\textcolor{black!20}{#1}\glzconttrue\else%
\if.#1.\glzconttrue\else%
#1\glzcontfalse%
\fi\fi}
import Data.List.Split
data Tabbed
= Tab [String] Tabbed Tabbed
| NoTab [String] Tabbed
| Nil
deriving (Show)
single [] = ""
single [str] = str
@exaexa
exaexa / memptr.cpp
Created January 25, 2020 22:41
C++ Member pointer to array element
#include <iostream>
#include <type_traits>
template<class M, typename T>
class member_ptr
{
size_t off_;
public:
member_ptr()
@exaexa
exaexa / weighted-sample.cpp
Created October 31, 2019 21:24
weighted sample selection by tree in c++
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <random>
#include <vector>
using namespace std;
@exaexa
exaexa / scattermore-in-ggplot.R
Created August 7, 2019 21:49
scattermore vs ggplot
library(scattermore) #from devtools::install_github('exaexa/scattermore')
library(ggplot2)
geom_scattermore <- function(
mapping=NULL, data=NULL, stat="identity", position="identity", ...,
na.rm=FALSE, show.legend = NA, inherit.aes = TRUE, interpolate = FALSE, pointsize = 0) {
layer(
data = data,
@exaexa
exaexa / dynamic.R
Created April 3, 2019 06:16
Shiny R dynamic pages
library(shiny)
renderPageSelect <- function(pageId, pages) {
selectInput("pageId", label="Select a page", selected=pageId, choices=as.list(pages))
}
renderMainPage <- function(pageId) {
res <- tagList()
if(pageId=='') res <- tagAppendChild(res, h3("No page selected"))
else res <- tagAppendChild(res, h3(paste0("The Page With Id ",pageId,".")))
############################
### CREATE EMBEDSOM PLOT ###
############################
#you might need this:
#devtools::install_github('exaexa/EmbedSOM')
set.seed(1234)
# run FlowSOM (initial steps prior to meta-clustering)
@exaexa
exaexa / embedsom-contour.R
Created January 18, 2019 15:12
EmbedSOM contour tool
EmbedContour <- function(e, bw=1, grid=c(201,201),
sub.ratio=.5, size.ratio=.5, cq=.666, add=T, ...) {
krnn <- KernSmooth::bkde2D(e,bandwidth=bw*sub.ratio,gridsize=grid)
krnw <- KernSmooth::bkde2D(e, bandwidth=bw, gridsize=grid,
range.x=list(
c(min(krnn$x1),max(krnn$x1)),
c(min(krnn$x2),max(krnn$x2))))
con <- list(x=krnw$x1, y=krnw$x2, z=krnn$fhat-sub.ratio*krnw$fhat)
contour(con, add=add, drawlabels=F, levels=c(quantile(con$z, cq)), ...)
{-# LANGUAGE ExistentialQuantification #-}
data Code = forall a . Interpret a => Code {getCode :: a}
class Interpret a where
interpret :: a -> Int
pprint :: a -> String
instance Interpret Code where
interpret (Code a) = interpret a