Skip to content

Instantly share code, notes, and snippets.

View danlooo's full-sized avatar
🌍

Daniel Loos danlooo

🌍
View GitHub Profile
@danlooo
danlooo / makie-globe-zoom.jl
Created February 2, 2024 15:21
View sattelite data in Makie.jl: Globe at lower zoom levels, only load data required for the current camera view
using GeometryBasics, LinearAlgebra, GLMakie, FileIO, CoordinateTransformations, ColorSchemes
function intersect_line_sphere(p::Point3f, d::Point3f, c::Point3f, sphere_radius::Float32)
# Use indexing to access point/vector components
# Calculate coefficients of the quadratic equation (a*t^2 + b*t + c = 0)
a = dot(d, d)
b = 2 * dot(d, p .- c)
c = dot(p .- c, p .- c) .- sphere_radius^2
# Calculate discriminant
@danlooo
danlooo / view_dict.py
Last active August 14, 2022 12:58
Inspect a (big and nested) python dictionary in VSCode
#!/usr/bin/env python3
def view_dict(d: dict):
'''View a (nested) dictionary in a new VSCode paneas a temp file for inspection'''
from yaml import dump
from tempfile import NamedTemporaryFile
from os import system
from subprocess import call
with NamedTemporaryFile(suffix=".yml") as f:
@danlooo
danlooo / compose_n.R
Created November 8, 2021 08:32
Compose a function multiple times to itself in R
l <- list(
list(
list(
a = 1
)
)
) %>%
enframe()
# How to simplify this repetetive code?
@danlooo
danlooo / ggeulerr.R
Last active June 13, 2024 18:09
Area proportional venn diagrams in R using ggplot2 and eulerr (eulerr does not return a ggplot object)
library(tidyverse)
library(eulerr)
library(ggforce)
#' Area proportional venn diagrams
#'
#' This functions uses eulerr::euler to plot area proportional venn diagramms
#' but plots it using ggplot2
#'
#' @param combinations set relationships as a named numeric vector, matrix, or data.frame(See `eulerr::euler`)
@danlooo
danlooo / R-walrus.R
Last active July 21, 2021 13:45
Walrus Operator in R
#' Assignment expression operator
#'
#' Creates an object with name `lhs` with the value `lhs`
#' and finally returns the value e.g. to pipe and print it
`%:=%` <- function(lhs, rhs, envir = parent.frame()) {
assign(deparse(substitute(lhs)), rhs, envir = envir)
rhs
}
# Create a varaible and print it's value
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.