Skip to content

Instantly share code, notes, and snippets.

Avatar

evalparse xiaodaigh

View GitHub Profile
@xiaodaigh
xiaodaigh / 0_code.jl
Last active Aug 30, 2020
Fast implementation of `nuniuqe` in a SORTED vector
View 0_code.jl
x = rand(1:1_000_000, 1_000_000_000)
using SortingLab
fsort!(x)
function unroll_loop(x)
count = 0
@inbounds count += x[1] != x[2]
@inbounds count += x[2] != x[3]
@xiaodaigh
xiaodaigh / code.jl
Created Aug 30, 2020
df1[B] = df2[B] where df1 and df2 are DataFrames B is boolean array
View code.jl
using DataFrames
df1 = DataFrame(a = repeat([1], 100), b = "a")
df2 = DataFrame(a = repeat([2], 100), b = "b")
B = Array{Bool, 2}(undef, 100, 2)
df1[B] # doesn't work
# Let's overload get index get index
@xiaodaigh
xiaodaigh / julia-slow-serialization.jl
Created Sep 13, 2019
Julia serialization is dog-slow
View julia-slow-serialization.jl
using JDF
using CSV, DataFrames
using Serialization:serialize,deserialize
using BufferedStreams
@time a = CSV.read("C:/Users/ZJ.DAI/Documents/git/format-wars/data/Performance_2016Q4.txt", delim = '|', header = false);
io = BufferedOutputStream(open("c:/data/bin.bin","w"))
@time serialize(io, a)
close(io)
@xiaodaigh
xiaodaigh / server.R
Last active Jan 25, 2020
Shiny: Disable Button
View server.R
library(shiny)
disableActionButton <- function(id,session) {
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('disabled',true)"
,sep="")))
}
shinyServer(function(input, output,session) {
@xiaodaigh
xiaodaigh / Dockerfile
Created Dec 30, 2019
Dockerfile for minimal r and python docker with arrow
View Dockerfile
FROM python:3.7-alpine3.10
RUN apk add --no-cache \
build-base \
cmake \
bash \
boost-dev \
autoconf \
zlib-dev \
flex \
@xiaodaigh
xiaodaigh / install-1.3-rc2.bash
Last active Oct 1, 2019
Install Julia Andriod
View install-1.3-rc2.bash
apt-get update && apt-get upgrade -y
apt-get install wget -y
apt-get install proot -y
apt-get install git -y
cd ~
git clone https://github.com/MFDGaming/ubuntu-in-termux.git
cd ubuntu-in-termux
chmod +x ubuntu.sh
./ubuntu.sh
cp ~/ubuntu-in-termux/resolv.conf ~/ubuntu-in-termux/ubuntu-fs/etc/
@xiaodaigh
xiaodaigh / data.table_vs_disk.frame.r
Created Sep 22, 2019
Benchmarking data.table vs disk.frame
View data.table_vs_disk.frame.r
library(data.table)
library(disk.frame)
setup_disk.frame()
bench_disk.frame_data.table_group_by <- function(data1,n) {
setDT(data1)
a.sharded.df = as.disk.frame(data1, shardby = c("year", "month", "day"))
a.not_sharded.df = as.disk.frame(data1)
@xiaodaigh
xiaodaigh / benchmarks.jl
Created Sep 17, 2019
Benchmark R vs Julia dataframe on disk format
View benchmarks.jl
using CSV, Feather
#using JLD2
#using JLD#, JLSO
using JDF, FileIO, Blosc, StatsPlots, RCall
using DataFrames, WeakRefStrings # required for JLD2, JDF
Blosc.set_num_threads(6)
gen_benchmark(dirpath, largest_file, outpath, data_label; delim = ',', header=true) = begin
if !isdir(outpath)
mkpath(outpath)
@xiaodaigh
xiaodaigh / 0-benchmarks.jl
Last active Sep 15, 2019
Julia On-disk formats for saving DataFrames
View 0-benchmarks.jl
using CSV, Feather, JLD2, JLSO, JDF, FileIO, Blosc, StatsPlots
using DataFrames, WeakRefStrings # required for JLD2, JDF
Blosc.set_num_threads(6)
gen_benchmark(dirpath, largest_file, outpath, data_label; delim = ',', header=true) = begin
if !isdir(outpath)
mkpath(outpath)
end
View example_rayshader_4walls_hole.r
library(rayshader)
library(av)
library(future)
plan(multiprocess)
# set up an elevation matrix with a wall around the outside and a gap on each of
# the walls.
elmat1 = matrix(0, 500, 500)
elmat1[1:100, 1:200] = 3000
You can’t perform that action at this time.