Skip to content

Instantly share code, notes, and snippets.

View issue-13010.md
$ ./bin/crystal --version
Using compiled compiler at .build/crystal
Crystal 1.8.0-dev [58fb584cb87] (2023-01-21)

LLVM: 14.0.1
Default target: aarch64-apple-darwin21.6.0
@bcardiff
bcardiff / README.md
Created April 17, 2020 20:08
VSCode CodeLLDB Crystal Configuration
View README.md

These configuration will let you use CodeLLDB extension to debug Crystal programs.

Store them as .vscode/tasks.json and .vscode/launch.json in your project.

When starting the debugging the current file will be built in the bin/ folder (as in shards build).

jMvTWMvPdD

Note: You will need to set the crystal binary path in tasks.json "command" field and the whole path in launch.json "initCommands". Read more at #8538

@bcardiff
bcardiff / Dockerfile
Created January 22, 2020 13:45
Generate rails-assets packages
View Dockerfile
FROM ruby:2.2
RUN \
# node
curl -sL https://deb.nodesource.com/setup_5.x | bash - && \
apt-get install -y nodejs && \
# cleanup
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@bcardiff
bcardiff / local_variable_hle_check.cr
Created November 7, 2019 18:55
Sample to use FileCheck with Crystal
View local_variable_hle_check.cr
# The lock is at the end of the unions
#
# CHECK: %"(Bool | Int32)" = type { i32, [1 x i64], i32 }
local_var = uninitialized Int32 | Bool
# After the alloca the lock is initialized as free (1)
#
# CHECK: %local_var = alloca %"(Bool | Int32)"
# CHECK: %0 = getelementptr inbounds %"(Bool | Int32)", %"(Bool | Int32)"* %local_var, i32 0, i32 2
@bcardiff
bcardiff / local_variable_hle_check.cr
Created November 7, 2019 18:55
Sample to use FileCheck with Crystal
View local_variable_hle_check.cr
# The lock is at the end of the unions
#
# CHECK: %"(Bool | Int32)" = type { i32, [1 x i64], i32 }
local_var = uninitialized Int32 | Bool
# After the alloca the lock is initialized as free (1)
#
# CHECK: %local_var = alloca %"(Bool | Int32)"
# CHECK: %0 = getelementptr inbounds %"(Bool | Int32)", %"(Bool | Int32)"* %local_var, i32 0, i32 2
@bcardiff
bcardiff / channel-select.md
Created October 8, 2019 20:11
Blocking and non-blocking channel actions
View channel-select.md

Blocking and non-blocking channel actions

Channel#receive vs Channel#receive? differs on their behavior for closed channels. Using them directly is always blocking.

Performing an operation over a closed and closing the channel during the operation must behave in the same way.

Channel#receive

@bcardiff
bcardiff / synchronized.cr
Created September 30, 2019 20:01
Synchronized shameless wrapped for Crystal
View synchronized.cr
# $ crystal run -Dpreview_mt synchronized.cr
struct Synchronized(T)
@lock = Mutex.new
getter inner : T
def initialize(@inner : T)
end
@bcardiff
bcardiff / logger2.cr
Created April 16, 2018 17:36
Logger POC with lazy init
View logger2.cr
# A Logger allow sending logging information to a stream.
# Each logger instance is built and binded to a specific
# context that is sent on each entry.
#
# When requesting a logger via `Logger#get` a context needs to be
# specified. Context are meant to be dot seperated path as:
# `"http.client"`. Class names and modules are translated into that format.
#
# ```
# class HTTP::Client
@bcardiff
bcardiff / logger2.cr
Created April 16, 2018 17:05
Logger POC
View logger2.cr
# A Logger allow sending logging information to a stream.
# Each logger instance is built and binded to a specific
# context that is sent on each entry.
#
# When requesting a logger via `Logger#get` a context needs to be
# specified. Context are meant to be dot seperated path as:
# `"http.client"`. Class names and modules are translated into that format.
#
# ```
# class HTTP::Client