Skip to content

Instantly share code, notes, and snippets.

View andrie's full-sized avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / doSNOW.R
Created October 21, 2015 10:08
Progress bars with foreach and doSNOW
library(doSNOW)
library(tcltk)
cl <- makeSOCKcluster(2)
registerDoSNOW(cl)
pb <- txtProgressBar(max=100, style=3)
progress <- function(n) setTxtProgressBar(pb, n)
opts <- list(progress=progress)
r <- foreach(i=1:100, .options.snow=opts) %dopar% {
@andrie
andrie / foreach-parallel-progressbar.R
Created February 21, 2015 13:53
Creating progress bars from each parallel worker using foreach and doParallel
library(foreach)
library(iterators)
library(doParallel)
library(tcltk)
# Choose number of iterations
n <- 1000
cl <- makeCluster(8)
@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)