Skip to content

Instantly share code, notes, and snippets.

@Tokazama
Tokazama / RefTypes.jl
Created January 13, 2023 17:20
Reference types from A(tomic) to S(tatic)
module RefTypes
import .Base.Sys: ARCH, WORD_SIZE
export
AtomicRef,
ImmutableRef,
MutableRef,
StaticRef,
add!,
module GraphTraits
abstract type GraphStyle end
GraphStyle(x) = GraphStyle(typeof(x))
GraphStyle(::Type{T}) where {T} = throw(MethodError(GraphStyle, T))
vertex_type(x) = vertex_type(typeof(x))
vertex_type(::Type{T}) where {T} = throw(MethodError(vertex_type, T))
abstract type AccessStyle end
struct LinearElement <: AccessStyle end
struct CartesianElement <: AccessStyle end
struct LinearCollection <: AccessStyle end
struct CartesianCollection <: AccessStyle end
@Tokazama
Tokazama / layouts.jl
Created June 3, 2021 09:39
Partial conceptualization of layouts interface
if VERSION < v"1.6"
struct ComposedFunction{O,I} <: Function
outer::O
inner::I
ComposedFunction{O, I}(outer, inner) where {O, I} = new{O, I}(outer, inner)
ComposedFunction(outer, inner) = new{Core.Typeof(outer),Core.Typeof(inner)}(outer, inner)
end
(c::ComposedFunction)(x...; kw...) = c.outer(c.inner(x...; kw...))
end
@Tokazama
Tokazama / AxisIndicesGraphs.jl
Created March 11, 2020 12:25
AxisIndices + Graphs
module AxisIndicesGraphs
using AxisIndices, LightGraphs, SimpleWeightedGraphs
using Base: to_index, @propagate_inbounds
struct AxisIndicesGraph{T,G<:AbstractGraph{T},AI} <: AbstractGraph{T}
graph::G
axes::AI
@Tokazama
Tokazama / plot_tick_shortcuts.jl
Last active January 23, 2020 20:56
Easier interaction with plots.
"""
ticklabels(scene)
Returns the all the axis tick labels.
"""
function ticklabels(scene)
axis = scene[Axis]
@assert !isnothing(axis)
return axis.ticks.ranges_labels[][2]
end
@Tokazama
Tokazama / named_array_traits.jl
Last active September 18, 2019 07:26
Ideas for unifying array naming conventions in Julia.
import Base: tail, to_dim
struct Dim{Sym} end
const TimeDim = Dim{:time}()
const ColorDim = Dim{:color}()
struct HasDimNames{T} end
HasDimNames(x::T) where T = HasDimNames(T)
HasDimNames(::Type{T}) where T = HasDimNames{false}()