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
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)
# %%
import Base:
uniontypes,
get_world_counter,
_methods_by_ftype
import Core:
Const,
MethodMatch,
MethodInstance
@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)
@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
# %%
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 / 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)
// 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}`
})
module BQUtils
using CSV
using MacroTools: @>, @>>
struct Query
s::String
end
Query(q::Query) = q
@aviatesk
aviatesk / collectgen-standalone.jl
Last active May 18, 2020 05:30
`@collect` and `@generator` macro, standalone implementation
function decompose_forblk(forblk)
@assert Meta.isexpr(forblk, :for) "for block expression should be given"
itrspec, body = forblk.args
@assert Meta.isexpr(itrspec, :(=)) "invalid for loop specification"
v, itr = itrspec.args
return body, v, itr
end
function recompose_to_comprehension(forblk, cond = nothing; gen = false)
body, v, itr = decompose_forblk(forblk)
@aviatesk
aviatesk / dfchain.jl
Created May 9, 2020 06:01
dataframe chaining while plotting
# what I will do here:
# - dataframe chain
# - keep to pass dataframe while plotting with `StatsPlots.@df`
# - pass columns names as variables
using DataFrames, Pipe, StatsPlots
theme(:juno)
df = DataFrame(x = randn(100), y = rand(Int, 100))