Skip to content

Instantly share code, notes, and snippets.

View tk3369's full-sized avatar
🐶
Published! Hands on design patterns and best practices with Julia.

Tom Kwong tk3369

🐶
Published! Hands on design patterns and best practices with Julia.
View GitHub Profile
@tk3369
tk3369 / cpp_builders.md
Last active February 22, 2023 01:18
C++ builders

Working with a hierarchy of builders that builds objects from a class hierarchy

I have a class hierarchy in which every class has some defined properties. I want to use builder pattern for all of these classes. Since the classes are set up in a hierachy, ideally I would do the same with the builders. The build function can validate its parts before constructing the concrete object. This guarantees that all necessary invariants are met.

Primary design

input() = """22243
11899
1696
2595
5331
6092
5274
5641
1345
Warning: Sending message failed
│ exception =
│ IOError(EOFError() during request(https://discord.com/api/v10/channels/997765767053459520/messages))
│ Stacktrace:
│ [1] read_to_buffer(t::HTTP.ConnectionPool.Transaction{MbedTLS.SSLContext}, sizehint::Int64)
│ @ HTTP.ConnectionPool ~/.julia/packages/HTTP/aTjcj/src/ConnectionPool.jl:275
│ [2] readuntil(t::HTTP.ConnectionPool.Transaction{MbedTLS.SSLContext}, f::Function, sizehint::Int64)
│ @ HTTP.ConnectionPool ~/.julia/packages/HTTP/aTjcj/src/ConnectionPool.jl:294
│ [3] readuntil
@tk3369
tk3369 / TimeZones.md
Created July 20, 2022 06:37
Time zone labels from TimeZones.jl as of 2022-07-19

The following are valid timezones that can be used for JuliaCon bot's jc command.

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui

Define a function such that it only executes its body once. The value from first execution is memoized at the module level.

module X

export once
let x = Ref{Any}()
    global function once(f::Function)
 isassigned(x) && return x[]
function stream_user_input(c::Channel)
while true
line = readline()
if line == ""
put!(c, ">>bye")
break
else
put!(c, line)
end
end
Hi SciML attendees,
We will use Discord as the primary chat platform during the conference.
The Humans of Julia community already has a server, so we will leverage the same server
and use a dedicated channel there (#scimlcon) for the SciML conference.
Please click on the link below to join the server:
https://discord.gg/PRqc3NehEr
For more information about the Discord platform, please visit their web site at https://discord.com/
@tk3369
tk3369 / gist:08b2a7dd7150a6330513aaf4c320b930
Created February 26, 2022 17:27
HoJBot lost connection to Discord 2022-02-24
HoJBot lost connection to Discord
┌ Info: Reconnecting
│ time = 2022-02-24T04:58:52.571
│ conn = 29
│ resume = true
└ zombie = true
┌ Error: Getting gateway URL failed
│ time = 2022-02-24T04:59:51.869
│ exception =
@tk3369
tk3369 / koch.jl
Last active February 21, 2022 05:48
# Modified from @frank's code at Discord
function koch_curve!(X, Y, x1, y1, x2, y2, level)
if level == 0
push!(X, x1)
push!(X, x2)
push!(Y, y1)
push!(Y, y2)
else
Δx = x2 - x1
using BenchmarkTools
function apply_filter_jl(E, wx)
Xest = 0.0 + 0.0im
@inbounds for j = 1:size(E, 2)
for i = 1:size(E, 1)
Xest += E[i, j] * wx[i, j]'
end
end
return Xest