Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Patrik Patrikios

🎯
Focusing
View GitHub Profile
@Patrikios
Patrikios / Dockerfile
Last active September 20, 2022 15:42
Building a shinyproxy Dockerfile based on rhub/r-minimal for R shiny app
View Dockerfile
# Ressources:
# - https://github.com/r-hub/r-minimal
# - https://hosting.analythium.io/best-practices-for-r-with-docker/
# NOTE
# does not support Cairo or x11 add hoc, hence renderPlot will not work, renderPlotly und JS backends are working fine
# TEST and DEBUG
# - build: sudo docker build --build-arg http_proxy=x --build-arg https_proxy=x -t shiny_app_alpine .
# - run: sudo docker run -it -p 3899:3838 -v /home/xyz/:/home/xyz/ shiny_app_alpine
@Patrikios
Patrikios / generator_expressions_study.jl
Last active September 19, 2022 15:24
GEnerator Expressions in julialang
View generator_expressions_study.jl
# Generator Expressions
# - comprehensions can also be written without the enclosing square brackets, producing an object known as a generator
# - can be iterated to produce values on demand, instead of allocating an array and storing them in advance
# - Generators are implemented via inner functions.
# - simple example
(1/n^2 for n=1:1000)
# - collect
collect(1/n^2 for n=1:1000)
# - the following expression sums a series without allocating memory
map(tuple, (1/(i+j) for i=1:2, j=1:2), [1 3; 2 4])
@Patrikios
Patrikios / pairs_study.jl
Last active September 19, 2022 13:12
julia pairs data structure
View pairs_study.jl
a_tuple = (1, 2)
a_pair = 1 => 2
a_tuple != a_pair
# true
# The elements are stored in the fields first and second
a_pair.first
# 1
a_pair.second
# 1
typeof(a_pair)
@Patrikios
Patrikios / sync.md
Created September 13, 2022 15:44 — forked from xin053/sync.md
[go sync] go sync #go #sync
View sync.md

sync.WaitGroup

package main

import (
	"log"
	"math/rand"
	"sync"
	"time"
@Patrikios
Patrikios / DataFrames_Study.jl
Created September 13, 2022 14:49
A short excourse on the DataFrames.jl API
View DataFrames_Study.jl
using DataFrames
# create a data.frame (simple)
df = DataFrame(A=1:4, B=["M", "N", "O", "P"])
df[!, :A] # no copy
df[:, :A] # copy is returned
# create a data.frame (row by row - not performant, as DataFrames are like in R built columnwise)
df2 = DataFrame(A=Int[], B=String[])
push!(df2, (1, "M"));
@Patrikios
Patrikios / conditions.R
Last active September 11, 2022 09:27
implementes custom R conditions (like errors, warnings, messages) as found in 1st Edition of Hadley's Advanced R book
View conditions.R
# DOCUMENTATION
#
# Sources: http://adv-r.had.co.nz/Exceptions-Debugging.html & https://adv-r.hadley.nz/conditions.html
#
# - all conditions inherit from abstract class 'condition'
# - conditions are being signalled from functions
# - R conditions system was inpsired by Common Lisp
#
#
# Ressources:
@Patrikios
Patrikios / multithreading.jl
Last active September 20, 2022 15:42
Overview of the parallelism/concurrent/distributed framework of julia in a nutshell
View multithreading.jl
# Multithreaded programming in Julia
#=
Julia supports multiple types of parallelism
- SIMD (handled by the compiler) -> for instance the package StaticArrays.jl, short static vectors incline to encourage SIMD operations, a further reason why the package is so efficient
- Threads with shared memory (this documents touches upon this point)
- Distributed (multi-mode, not sharing memory)
- GPUs
=#
@Patrikios
Patrikios / function_parameter_pasing.jl
Created February 20, 2022 22:01
Passing by reference an passing by value in julialang
View function_parameter_pasing.jl
#= assignment of a function to a new name
- is shallow copy of a function
- in programming parlance: done by reference
=#
f(x) = 2x
g = f
g #f (generic function with 1 method)
g(2) #4
f(x) = 4x
@Patrikios
Patrikios / main.go
Last active February 20, 2022 21:58
Gist on type checking in go
View main.go
package main
// Sources:
// 1. https://go.dev/tour/methods/15
// 2. https://go.dev/tour/methods/16
// 3. https://stackoverflow.com/questions/6996704/how-to-check-variable-type-at-runtime-in-go-language
// 4. https://go.dev/tour/methods/9
// Notions
// concrete types like int, float64, string etc
@Patrikios
Patrikios / server.R
Created April 2, 2021 18:01 — forked from garrettgman/server.R
A shiny app that helps you explore stock returns (by way of yahoo finance and quantmod)
View server.R
library(shiny)
library(quantmod)
library(VGAM)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# acquiring data
dataInput <- reactive({
if (input$get == 0)