Skip to content

Instantly share code, notes, and snippets.

@Arkoniak
Arkoniak / parallel_randomwalk.jl
Last active October 22, 2020 08:38
Parallelization of random walk with ThreadsX
using BenchmarkTools
using StableRNGs
using Random
using ThreadsX
function randomwalk!(tbl, i; rng = rng)
len = size(tbl, 1)
tbl[1, i] = rand(rng)
@inbounds for j in 2:len
tbl[j, i] = (tbl[j - 1, i]) + rand(rng)
@Arkoniak
Arkoniak / turtle_bot.jl
Created June 16, 2020 14:39
simple telegram bot, which draws turtle graphics.
using Telegram
using Luxor
token = ENV["TELEGRAM_BOT"]
client = TelegramClient(token)
useglobally!(client)
function draw_turtle(angles)
d = Drawing(600, 400, :png)
@Arkoniak
Arkoniak / distances_predict.jl
Created April 16, 2020 09:40
Labeling algorithm evolution
using ParallelKMeans
using BenchmarkTools
using Distances
using Random
using UnsafeArrays
Random.seed!(2020)
X = rand(100, 1000) # 1000 points
locations = rand(100, 10) # 10 cluster
struct NeuralNet
NetDimensions::Array
LossFunction::String
params::Dict
end
function NeuralNet(dims, loss="someloss")
param = Dict()
for l=2:length(dims)
param["W_$(l-1)"] = rand(dims[l], dims[l-1]) * 0.1
@Arkoniak
Arkoniak / covid19.jl
Created March 7, 2020 18:32
Covid-19 julia reshape
using HTTP, DataFrames, CSV
confirmed_url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv"
deaths_url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv"
recovered_url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Recovered.csv"
confirmed_df = CSV.File(IOBuffer(HTTP.get(confirmed_url).body)) |> DataFrame
deaths_df = CSV.File(IOBuffer(HTTP.get(deaths_url).body)) |> DataFrame
recovered_df = CSV.File(IOBuffer(HTTP.get(recovered_url).body)) |> DataFrame
ncols = size(confirmed_df, 2)
using Primes
using DataFrames
using VegaLite
from_polar(t::Tuple) = (t[1]*cos(t[2]), t[1]*sin(t[2]))
dots = primes(100000) |> z -> map(x -> (x, x), z) |> x -> from_polar.(x)
DataFrame(dots) |> df -> rename!(df, [:x, :y]) |>
@vlplot(mark={
type=:circle,
size = 5, color = "gold"
}, encoding={x = {:x, axis={grid=false}}, y = {:y, axis={grid=false}}},
using BenchmarkTools
using Distributed
using Base.Threads
addprocs(4)
nworkers() # should be 4
function f1()
nheads = @distributed (+) for i = 1:200000000
Int(rand(Bool))
using PyCall
using LinearAlgebra
using Statistics
using StatsBase
using BenchmarkTools
using Distances
# import the same data
data = pyimport("sklearn.datasets")
@Arkoniak
Arkoniak / push_vs_direct.jl
Last active February 5, 2020 08:43
Comparison push! and direct access performance
using BenchmarkTools
using StatsBase: median
using DataFrames
using VegaLite
versioninfo()
# Julia Version 1.3.1
# Commit 2d5741174c (2019-12-30 21:36 UTC)
# Platform Info:
# OS: Linux (x86_64-pc-linux-gnu)
@Arkoniak
Arkoniak / atom_environment.txt
Created February 3, 2020 07:17
Atom environment
# Atom:
Version: 1.43.0
Dev Mode: false
Official Release: true
{
"http_parser": "2.8.0",
"node": "10.11.0",
"v8": "6.9.427.31-electron.0",
"uv": "1.23.0",
"zlib": "1.2.11",