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 / 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 / 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
#
#=
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 / .screenrc
Last active October 18, 2020 06:06
screenrc
termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l
wall Welcome to screen
# See http://www.gnu.org/software/screen/manual/html_node/String-Escapes.html
hardstatus alwayslastline
# #hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
hardstatus string '%{= wr}[%{B}%S%{r}][%= %{= wr}%?%-Lw%?%{b}(%{B}%n*%f%t%?(%u)%?%{b})%{b}%?%+Lw%?%?%= %{r}][%{B} %Y-%m-%d %c %{r}]'
@tk3369
tk3369 / bounce.jl
Created September 8, 2020 05:59
Bounce text in a terminal!
using TerminalUserInterfaces
const TUI = TerminalUserInterfaces
function bounce(str; delay = 0.08)
TUI.initialize()
try
terminal = TUI.Terminal()
width, height = TUI.terminal_size()
len = length(str)
@tk3369
tk3369 / df_separate_func.jl
Created August 29, 2020 17:25
Sample implementation of `separate` function for DataFrames.jl
using DataFrames
using Test
# Tidyr match-up
abstract type FillStrategy end
struct FillMissing <: FillStrategy end
struct FillRight <: FillStrategy end
struct FillLeft <: FillStrategy end
@tk3369
tk3369 / channel_play.jl
Created May 10, 2020 00:30
Composing with channels
# sum worker
function sum_worker(source)
target = Channel()
task = @async while true
args = take!(source)
args === nothing && break
result = sum(args)
push!(target, result)
end
return (output = target, task = task)
@tk3369
tk3369 / capture.md
Created February 16, 2020 20:50
How to use `@capture` with variable expression

How to use @capture with variable expression

The @capture macro from MacroTools expects one to pass the pattern directly when the macro is called. From Slack, someone asked if the pattern can be stored in a variable and then passed to the macro. I could make it work with the following "hack":

julia> code
:(foo(bar + xyz))

julia> pattern
:(phi1_(x_ + y_))

Suppose that we have an array of bytes that comes from a binary file. For simplicity sake, let's say we have just 8 64-bit integers loaded into memory, so we should have 64 bytes in the array.

Here's how we can generate a sample byte array:

julia> x = rand(1:100, 8)
8-element Array{Int64,1}:
  3
@tk3369
tk3369 / JMG.md
Last active December 9, 2019 00:20
Julian Master Game

The Julian Master Game

The following is a set of problems that I organized with some friends at work in 2018.

Day 1 - π

This is an interesting one because the infinite sequence below converges to a number that relates to π. There are several ways to prove that although I like this one the most https://www.youtube.com/watch?v=d-o3eB9sfls.

1/1 + 1/4 + 1/9 + 1/16 + … = π / 6