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
@aviatesk
aviatesk / benchmarks.ipynb
Created July 24, 2019 13:19
Benchmarks for Traceur.jl: Cassette.jl to Vinyl.jl
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aviatesk
aviatesk / mdbranch.jl
Last active August 15, 2019 14:06
isa vs. multiple dispatch branching
# %% defines
function isabranch(numsary)
s = 0
for (n1, n2) ∈ numsary
if n1 isa Int8 && n2 isa Int8
s += 1
elseif n1 isa Int8 && n2 isa Int16
s += 2
elseif n1 isa Int8 && n2 isa Int32
s += 3
@aviatesk
aviatesk / nospecialize.ipynb
Created September 1, 2019 09:22
Benchmarks for `@nospecialize`
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aviatesk
aviatesk / quine.jl
Last active December 4, 2019 15:02
Julia one liner quine
(q = :(println("(q = $(repr(q))) |> eval"))) |> eval
@aviatesk
aviatesk / objmethods.jl
Last active December 9, 2019 16:55
methods on objects
const ACS = Union{AbstractChar, AbstractString}
(l::ACS)(f::Function, rs::ACS...) = f(l, rs...)
(l::ACS)(rs::ACS...) = l(*, rs...)
'1'("23") # "123"
']' .|> collect("julia") .|> '[' |> join # "[j][u][l][i][a]"
@aviatesk
aviatesk / collectgen.jl
Last active May 4, 2020 12:21
`@collect` and `@generator` macro -- might be useful in competitive programming, etc...
using MacroTools
function decompose_forblk(forblk)
spec, body = forblk.args
i, itr = spec.args
return i, itr, body
end
"""
@aviatesk
aviatesk / History|-1f87ef5b|entries.json
Last active June 3, 2022 09:49
Visual Studio Code Settings Sync Gist
{"version":1,"resource":"file:///Users/aviatesk/IoPLMaterials/textbook/interpreter/dune-project","entries":[{"id":"VJTx","timestamp":1652783352000},{"id":"6qkI","timestamp":1652783387886}]}
@aviatesk
aviatesk / linqplot.jl
Created April 22, 2020 13:35
plotting `@linq` chain
using DataFrames, DataFramesMeta, Plots, StatsPlots, StatsBase
# HACK:
# integrate StatsPlots.@df into @linq chain in a way data frame keeps to be passed even after plot
# but, the `names` part might be too dangerous
for n in names(StatsPlots)
function DataFramesMeta.linq(::DataFramesMeta.SymbolParameter{n}, d, args...)
plotcall = Expr(:call, n, args...)
return quote let d = $d
display(@df d $plotcall)
@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))
@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)