Skip to content

Instantly share code, notes, and snippets.

View aviatesk's full-sized avatar
✈️
JET it!

Shuhei Kadowaki aviatesk

✈️
JET it!
View GitHub Profile
module BQUtils
using CSV
using MacroTools: @>, @>>
struct Query
s::String
end
Query(q::Query) = q
// maybe handled by other client
s = `
foo [linktext](vscode-command:language-julia.openFile?${JSON.stringify({ file: 'foo', line: 10 })} "footitle")
bar [linktext](vscode-command:language-julia.openFile "bartitle")
`
s.replace(/vscode-command\:(.+)(|\?[\w\:\"\{\}\,]+)/g, (s, cmd, args) => {
console.log(args)
return `command:${cmd}${args}`
})
@aviatesk
aviatesk / scratched_graph.jl
Last active July 5, 2020 07:39
graph scratching
using LightGraphs, SparseArrays, GraphPlot
get_adj(g, v) = first(findnz(adjacency_matrix(g)[v, :]))
function dfs(g::AbstractGraph{T}, s::T,
visited = Set{T}(),
ret = T[]) where T
push!.((visited, ret), s)
# %%
using LanguageServer, CSTParser, StaticLint, SymbolServer
using LanguageServer: Range, TextDocumentIdentifier, TextDocumentPositionParams
const LS = LanguageServer
const SS = SymbolServer
server = let
pi = IOBuffer()
po = IOBuffer()
env = normpath(@__DIR__, "..", "scripts", "environments", "development")
@aviatesk
aviatesk / widening.jl
Last active September 14, 2020 18:15
flatten flatten
using BenchmarkTools, Cthulhu
f(a, b) = collect(Iterators.flatten((a, b)))
a = rand(10^6)
b = rand(10^6)
@btime f($a, $b) # 14.402 ms (21 allocations: 17.00 MiB)
# @descend f(a, b)
(@code_typed iterate(Iterators.flatten((a,b)))) |> last # ::Union{Nothing, Tuple{Float64, Tuple{Int64, Vector{Float64}, Int64}}} -> unwidened
@aviatesk
aviatesk / replusage.jl
Last active October 9, 2020 12:24
plot julia repl usage
using Dates, DataFrames, Pipe, Plots
df = let
ds = DateTime[]
r = r"# time: (?<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})"
for line in readlines(normpath(homedir(), ".julia/logs/repl_history.jl"))
m = match(r, line)
isnothing(m) || push!(ds, DateTime(m[:datetime], dateformat"Y-m-d H:M:S"))
end
DataFrame(datetime = ds)
# %%
import Base:
uniontypes,
get_world_counter,
_methods_by_ftype
import Core:
Const,
MethodMatch,
MethodInstance
julia> ] add Revise
julia> using Revise
julia> Revise.track(Core.Compiler)
# typeinf_local(interp::AbstractInterpreter, frame::InferenceState)の1行目に以下の変更を加えてsave
# println(frame.slottypes)
julia> code_typed(use_tvar_info, (Union{Int,Nothing},Int); optimize=false)
julia> using JET, JET.JETInterfaces
julia> get_module(sv::Core.Compiler.InferenceState) = sv.mod
get_module (generic function with 2 methods)
julia> function get_module(linfo::Core.MethodInstance)
def = linfo.def
return isa(def, Module) ? def : def.module
end
get_module (generic function with 2 methods)
# adapted from https://github.com/JuliaCompilerPlugins/Mixtape.jl/blob/75fc4aa25e918f92bfd0ba706236f61a466efc11/examples/dynamic_overlay.jl
module DynamicOverlay
using Mixtape
import Mixtape: CompilationContext, transform, allow
using MacroTools
using CodeInfoTools
using BenchmarkTools