Skip to content

Instantly share code, notes, and snippets.

View andrie's full-sized avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / rro-mkl-benchmark.R
Last active December 15, 2023 10:20
Test performance of Intel MKL on matrix operations
# Set MKL threads if Revolution R Open or Revolution R Enterprise is available
if(require("RevoUtilsMath")){
setMKLthreads(4)
}
# Initialization
set.seed (1)
@andrie
andrie / 092323-26203-01.dmp
Created September 23, 2023 07:09
Windows BSOD minidump
************* Preparing the environment for Debugger Extensions Gallery repositories **************
ExtensionRepository : Implicit
UseExperimentalFeatureForNugetShare : true
AllowNugetExeUpdate : true
AllowNugetMSCredentialProviderInstall : true
AllowParallelInitializationOfLocalRepositories : true
-- Configuring repositories
----> Repository : LocalInstalled, Enabled: true
@andrie
andrie / app.py
Created August 22, 2023 10:51
Shiny for python app that filters data prior to display in grid.
import pandas # noqa: F401 (this line needed for Shinylive to load plotly.express)
import plotly.express as px
import plotly.graph_objs as go
from shinywidgets import output_widget, render_widget
from shiny import App
from shiny import experimental as x
from shiny import reactive, render, req, session, ui
@andrie
andrie / app.py
Created August 11, 2023 14:17
Reprex of pyshiny dataframe not selecting correct rows
import pandas # noqa: F401 (this line needed for Shinylive to load plotly.express)
import plotly.express as px
import plotly.graph_objs as go
from shinywidgets import output_widget, render_widget
from shiny import App
from shiny import experimental as x
from shiny import reactive, render, req, session, ui
@andrie
andrie / networkD3.R
Last active July 21, 2023 19:35
Visualise graph using the networkD3 package
library("networkD3")
library("igraph")
# Download prepared igraph file from github
url <- "https://github.com/andrie/cran-network-structure/blob/master/pdb/depGraph-CRAN.rds?raw=true"
datafile <- tempfile(fileext = ".rds")
download.file(url, destfile = datafile, mode = "wb")
gs <- readRDS(datafile)
# Remove all nodes with fewer than 50 edges
@andrie
andrie / hilbert.R
Created July 17, 2023 10:23
Compute the hilbert curve using R
# compute hilbert curve
# inspired by https://logicgrimoire.wordpress.com/2020/06/19/how-to-draw-the-hilbert-curve-using-a-computer-program/
library(ggplot2)
library(dplyr)
library(magrittr)
# rotate matrix
rotate <- function(x, th = pi/2) {
x %*% matrix(c(cos(th), -sin(th), sin(th), cos(th)), ncol = 2, byrow = TRUE)
@andrie
andrie / hexagon.tsx
Created February 28, 2023 18:26
Motion-canvas: extending the `Line` class to implement a Polygon
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';;
import {createRef} from '@motion-canvas/core/lib/utils';
import {all} from '@motion-canvas/core/lib/flow';
import {createSignal} from '@motion-canvas/core/lib/signals';
import {Polygon} from '../components/Polygon';
export default makeScene2D(function* (view) {
const myPoly = createRef<Polygon>();
@andrie
andrie / repr options.R
Created September 25, 2015 15:16
Changing plot size in Jupyter IRkernel
library(repr)
# Change plot size to 4 x 3
options(repr.plot.width=4, repr.plot.height=3)
curve(sin(x), from = 0, to=2*pi, n = 100)
# Change plot size to 8 x 3
options(repr.plot.width=8, repr.plot.height=3)
curve(sin(x), from = 0, to=4*pi, n = 200)
@andrie
andrie / gamma_parameters.R
Created October 7, 2015 15:19
Fit a gamma distribution based on prior information
# Objective
#
# Fit a gamma distribution knowing that:
# - 20% fall below 15 days
# - 80% fall below 60 days
# Inspired by http://www.johndcook.com/blog/2010/01/31/parameters-from-percentiles/
x <- c(0.2, 0.8)
y <- c(15, 60)
@andrie
andrie / pagerank.R
Last active April 16, 2021 01:50
Analyze R packages for popularity, using pagerank algorithm
## Analyze R packages for popularity, using pagerank algorithm
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------