Skip to content

Instantly share code, notes, and snippets.

Avatar

John Myles White johnmyleswhite

View GitHub Profile
View expr_kinds.txt
│ Row │ expr_type │ count │ percentage │
│ │ Any │ Int64 │ Float64 │
├─────┼────────────────────────────────┼────────┼─────────────┤
│ 1 │ ExprKind{:outer} │ 1 │ 0.000226006 │
│ 2 │ ExprKind{:/=} │ 1 │ 0.000226006 │
│ 3 │ ExprKind{:typed_vcat} │ 1 │ 0.000226006 │
│ 4 │ ExprKind{:.+=} │ 1 │ 0.000226006 │
│ 5 │ ExprKind{:%=} │ 3 │ 0.000678017 │
│ 6 │ ExprKind{:⊻=} │ 7 │ 0.00158204 │
│ 7 │ ExprKind{:.=} │ 8 │ 0.00180804 │
@johnmyleswhite
johnmyleswhite / differentiate.jl
Last active Nov 19, 2021
Symbolic Differentiation in Julia
View differentiate.jl
differentiate(x::Number, target::Symbol) = 0
function differentiate(s::Symbol, target::Symbol)
if s == target
return 1
else
return 0
end
end
@johnmyleswhite
johnmyleswhite / gist:4195980
Created Dec 3, 2012
Imitating plyr and reshape in Julia
View gist:4195980
# A top priority for making DataFrames useful in Julia is the development of
# good documentation and a nice API for doing plyr+reshape style operations
# in Julia. This Gist is a draft of such documentation.
load("DataFrames")
using DataFrames
load("RDatasets")
baseball = RDatasets.data("plyr", "baseball")
View lift.jl
import MacroTools: postwalk
function missing_check(es)
if length(es) == 0
false
elseif length(es) == 1
Expr(:call, :ismissing, es[1])
elseif length(es) == 2
Expr(
:call,
View thunk.jl
struct ExpressionThunk
source::Any
thunk::Any
end
macro thunk(e)
quote
ExpressionThunk(
$(QuoteNode(e)),
() -> $(esc(e))
@johnmyleswhite
johnmyleswhite / bfs_dfs.jl
Last active Aug 29, 2020
BFS and DFS for DAG's in Julia
View bfs_dfs.jl
function bfs(start_node::Any,
next_nodes::Function,
at_node::Function)
to_process = Array(Any, 0)
depths = Array(Int, 0)
push!(to_process, start_node)
push!(depths, 0)
while !isempty(to_process)
View df_deep_copy.jl
x = [1, 2]
y = [3, 4]
z = [x, y]
z′ = copy(z)
z′[1] === x
import DataFrames: DataFrame
View example2.jl
import Plots
r = range(0.0, 1.0, length=512)
p = Plots.plot(
r,
x -> x^2 * (1 - x)^2,
)
Plots.png(p, "output2.png")
View example.R
#!/usr/bin/Rscript
png("output.png")
curve(x^2 * (1 - x)^2, from = 0, to = 1)
dev.off()
# time Rscript example.R
# null device
# 1
#
View logistic_comparisons.jl
julia> import BenchmarkTools: @btime
julia> @inline _logistic_bounds(x::Float16) = (Float16(-16.64), Float16(7.625))
_logistic_bounds (generic function with 1 method)
julia> @inline _logistic_bounds(x::Float32) = (-103.27893f0, 16.635532f0)
_logistic_bounds (generic function with 2 methods)
julia> @inline _logistic_bounds(x::Float64) = (-744.4400719213812, 36.7368005696771)
_logistic_bounds (generic function with 3 methods)