Skip to content

Instantly share code, notes, and snippets.

View asinghvi17's full-sized avatar
๐Ÿ“‘

Anshul Singhvi asinghvi17

๐Ÿ“‘
View GitHub Profile
@asinghvi17
asinghvi17 / zoom_to_extent.jl
Created November 21, 2024 21:07
a way to zoom in to a rectangle in 2d
using Makie
zoom_to_extent!(ax, target::Rect, factor = 1.0) = zoom_to_extent!(ax, ax.finallimits[], target, factor)
function zoom_to_extent!(ax, current_lims::Rect, target_lims::Rect2, factor = 1.0)
# Get current limits
current_xlims = current_lims.origin[1], current_lims.origin[1] + current_lims.widths[1]
current_ylims = current_lims.origin[2], current_lims.origin[2] + current_lims.widths[2]
# Calculate target limits
@asinghvi17
asinghvi17 / zoom_to_extent.jl
Created November 21, 2024 21:07
a way to zoom in to a rectangle in 2d
using Makie
zoom_to_extent!(ax, target::Rect, factor = 1.0) = zoom_to_extent!(ax, ax.finallimits[], target, factor)
function zoom_to_extent!(ax, current_lims::Rect, target_lims::Rect2, factor = 1.0)
# Get current limits
current_xlims = current_lims.origin[1], current_lims.origin[1] + current_lims.widths[1]
current_ylims = current_lims.origin[2], current_lims.origin[2] + current_lims.widths[2]
# Calculate target limits
  • Dependent / independent (are x and y coords dependent on each other (most transformations) or independent (each axis is transformed separately)?
  • "safe"/"unsafe" : can this transformation emit NaN or Inf given finite input?
  • densification traits - is densification needed or not?
  • what else do we need?
@asinghvi17
asinghvi17 / icosphere_skipping.jl
Created October 17, 2024 17:08
An icosphere refinement algorithm that skips triangles. It's a bug (but looks super cool!)
using GeometryBasics, LinearAlgebra
function add_vertex!(vertex_list, vertex)
push!(vertex_list, LinearAlgebra.normalize(vertex))
return length(vertex_list)
end
function get_middle_point!(vertex_list, midpoint_cache, p1::Int, p2::Int)
first_is_smaller = p1 < p2
smaller_index = first_is_smaller ? p1 : p2
@asinghvi17
asinghvi17 / what-do-i-do.md
Created October 11, 2024 20:20
Minimum criteria for docstrings

Minimum criteria for docstrings

  • Must have a usage example of real use - what the hell do I do with this?
  • If user-facing, must explain package-specific concepts (this can be a few words but it has to be done, since people will come in with no knowledge of package internals)
  • If output is a custom type, must mention what it is and what you can do with it.
@asinghvi17
asinghvi17 / neural_network_visualization.jl
Last active July 29, 2024 21:27
Using Makie to visualize activations of neural networks
using CairoMakie
fig = Figure()
# Number of neurons per layer
neurons_per_column = [1, 10, 7, 5, 8, 1]
# A grid for each layer (arranged in a column)
col_grids = [GridLayout(fig[1, i]; valign = :center) for i in eachindex(neurons_per_column)]
# An axis per neuron
col_axes = [
[Axis(col_grids[i][j, 1]) for j in 1:neurons_per_column[i]]
@asinghvi17
asinghvi17 / tiles_as_raster.jl
Created July 6, 2024 18:27
Getting a tile image in your desired dimensions from MapTiles.jl and TileProviders.jl
#=
# Getting (noninteractive) raster images from the MapTiles/TileProviders ecosystem
=#
import HTTP # to run the actual request and fetch the tiles
import ImageMagick # to read returned images, since they may be any bitmap format
using MapTiles, TileProviders # Julia map-tile infrastructure
# Julia geographic infrastructure
using Extents
import GeoInterface as GI
@asinghvi17
asinghvi17 / svg_colormap.jl
Created June 25, 2024 21:42
Implementing colormaps in SVG via passing colors as grays (allowing value based interpolation)
using Colors
function cgrad2svgf(cgrad)
stops = LinRange(0, 1, 256)
colors = cgrad[stops]
# no Alpha support yet
# but soon!
# <feFuncA type="table" tableValues="$(join(alpha.(colors), ","))"></feFuncA>
return """
<filter id="table" x="0" y="0" width="100%" height="100%">
using GLMakie
using Meshing, GeometryBasics
isoval = 100
algo = MarchingCubes(iso=isoval, insidepositive=false)
struct CameraRotationMove{T} <: FlyThroughPaths.PathChange{T}
duration::T
@asinghvi17
asinghvi17 / r_sf_integration.jl
Last active May 9, 2024 13:52
Hook into RCall.jl to convert SF geometries to GeoInterface wrappers
#=
This file provides integration for R's SF objects
which are essentially geo-dataframes,
into Julia DataFrames with GeoInterface wrapper
geometries.
This requires https://github.com/JuliaInterop/RCall.jl/pull/528,
so run `Pkg.add((; url = "https://github.com/asinghvi17/RCall.jl", rev = "patch-1"))` to get that.
TODO: