Skip to content

Instantly share code, notes, and snippets.

Avatar

evalparse xiaodaigh

View GitHub Profile
@xiaodaigh
xiaodaigh / server.R
Last active Jul 29, 2021
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 / install-1.3-rc2.bash
Last active Jul 9, 2021
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 / server.R
Last active Jun 9, 2021
A gist of programatically changing panel tabs in Shiny
View server.R
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
@xiaodaigh
xiaodaigh / 0_get_data.jl
Created Jun 4, 2021
Tang Dynasty poetry
View 0_get_data.jl
using Gumbo, Cascadia, HTTP
using Serialization
urls= ["https://www.shicimingju.com/shicimark/tangshisanbaishou.html"]
urls = vcat(urls, ["https://www.shicimingju.com/shicimark/tangshisanbaishou_$(i)_0__0.html" for i in 2:16])
function get_chars(poem::Vector{<:AbstractString})::Set{Char}
mapreduce(Set, union, poem)
end
@xiaodaigh
xiaodaigh / nongshimcup.jl
Last active Feb 21, 2021
Nongshim Cup simulation
View nongshimcup.jl
using Revise
includet("utils.jl")
function remove_player!(team)
if length(team) == 1
team.players = []
else
team.players = team.players[2:end]
end
team
@xiaodaigh
xiaodaigh / gist:0326a03d97a0b7ded0aa88d4aeeef812
Last active Jan 17, 2021
2021 Chunlan Cup simulation from quarters
View gist:0326a03d97a0b7ded0aa88d4aeeef812
struct Player
name::String
rating::Int
end
struct Match
best_of::Int
end
@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 / 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 \