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
#=
The following works with Documenter.jl 0.24.
There seems to be a breaking change in Documenter.jl 0.25 to return
something different from the `deploy_folder` function.
=#
struct MyDeployConfig <: Documenter.DeployConfig
end
@tk3369
tk3369 / yabairc
Created January 28, 2021 22:18
mac tile manager - yabai settings
#!/usr/bin/env sh
# the scripting-addition must be loaded manually if
# you are running yabai on macOS Big Sur. Uncomment
# the following line to have the injection performed
# when the config is executed during startup.
#
# for this to work you must configure sudo such that
# it will be able to run the command without password
#
@tk3369
tk3369 / skhdrc
Created January 28, 2021 22:19
mac tile manager - skhd settings
# focus window
alt - h : yabai -m window --focus west
alt - j : yabai -m window --focus south
alt - k : yabai -m window --focus north
alt - l : yabai -m window --focus east
# rotate tree
alt - r : yabai -m space --rotate 90
# mirror tree y-axis
@tk3369
tk3369 / JavaScriptEmoji.jl
Created March 13, 2021 19:46
Generate javascript code for mapping emoji short name to unicode
module JavaScriptEmoji
export download_emojis, parse_emojis, gen_javascript
import JSON
function download_emojis()
url = "https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json"
return JSON.parsefile(download(url))
end
@tk3369
tk3369 / error.md
Created March 28, 2021 17:44
gRPC does not support streaming interfaces?

Error when calling transaction with a Channel argument:

julia> channel = Channel{GraknClient.grakn.protocol.Transaction_Client}(1)

julia> txn = GraknClient.transaction(client.core_stub.blockingStub, gRPCController(), channel)
ERROR: MethodError: no method matching meta(::Type{Channel{GraknClient.grakn.protocol.Transaction_Client}})
Closest candidates are:
  meta(::ProtoBuf.ProtoMeta, ::Type, ::Vector{Pair{Symbol, Union{String, Type}}}, ::Vector{Symbol}, ::Vector{Int64}, ::Dict{Symbol, Any}) at /Users/tomkwong/.julia/packages/ProtoBuf/NJbMU/src/codec.jl:576
  meta(::ProtoBuf.ProtoMeta, ::Type, ::Vector{Pair{Symbol, Union{String, Type}}}, ::Vector{Symbol}, ::Vector{Int64}, ::Dict{Symbol, Any}, ::Vector{Symbol}) at /Users/tomkwong/.julia/packages/ProtoBuf/NJbMU/src/codec.jl:576
@startuml
class Test
@enduml
@tk3369
tk3369 / grakn-error.md
Created April 18, 2021 01:20
grakn error - Invalid protobuf byte sequence

I ran this code:

using Revise, GraknClient, UUIDs
using GraknClient: CoreTransaction, Proto, GraknOptions, bytes

client = GraknClient.CoreClient("127.0.0.1", 1729)
session = GraknClient.CoreSession(client, "phone_calls", GraknClient.grakn.protocol.Session_Type.DATA, GraknClient.GraknOptions())
txn = CoreTransaction(session, session.sessionID, Proto.Transaction_Type.READ, GraknOptions())

I built a cache that invalidates based on expiration time but then I realized that ExpiringCaches.jl (and few others) exist :-p

Just capturing what I did:

"""
    TimedCache

A time-based cache. To construct a new cache, provie the types for key and value
and a retention period. It is lazy - when a cache entry expires, it is not removed

Set up test data

julia> bs = rand(Bool, 100000);

Using if/else:

julia> function foo(bs)

My test code:

using TypeDBClient
import TypeDBClient.grakn.protocol as P

client = TypeDBClient.CoreClient("127.0.0.1", 1729)
session = TypeDBClient.CoreSession(client, "social_network", P.Session_Type.DATA)
transaction = TypeDBClient.CoreTransaction(session, session.sessionID, P.Transaction_Type.READ, TypeDBClient.TypeDBOptions())
result = TypeDBClient.match(transaction, raw"""
    match $loc has name "French Lick";