Skip to content

Instantly share code, notes, and snippets.

Brian J. Cardiff bcardiff

Block or report user

Report or block bcardiff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bcardiff
bcardiff / local_variable_hle_check.cr
Created Nov 7, 2019
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 Nov 7, 2019
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 Oct 8, 2019
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 Sep 30, 2019
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 Apr 16, 2018
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
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
Last active Apr 11, 2018
Logger POC with binding context
View logger2.cr
abstract class Logger2
enum Severity
DEBUG
INFO
end
abstract def log(severity : Severity, message, context : String)
macro bind(*, context = nil, forward = nil)
struct LoggerBinding
View logger2.cr
module Logger2
enum Severity
DEBUG
INFO
end
abstract def log(severity, message, context)
macro using(context, forward = nil)
getter logger : Logger2?
@bcardiff
bcardiff / README.md
Created Nov 10, 2017
crystal-env preview
View README.md

crystal-env

This shard provides environment detection. The selected environment is configured using CRYSTAL_ENV environment variable.

Installation

Add this to your application's shard.yml:

dependencies:
You can’t perform that action at this time.