Skip to content

Instantly share code, notes, and snippets.

View bcardiff's full-sized avatar
💭
OOO

Brian J. Cardiff bcardiff

💭
OOO
View GitHub Profile
@bcardiff
bcardiff / script.js
Created May 21, 2017 16:55
Send eventbrite.com notifications to Slack via webscript.io
local action = json.parse(request.body).config.action
http.request {
url = 'https://hooks.slack.com/services/...',
method = 'POST',
data = json.stringify({text = 'Action: '..action})
}
return 200
struct NamedTuple
macro map_keys(tuple, properties)
{% begin %}
%tuple = {{tuple}}
NamedTuple.new(
{% for key, value in properties %}
{{value.id}}: %tuple[{{key.symbolize}}],
{% end %}
)
{% end %}
@bcardiff
bcardiff / README.md
Created November 10, 2017 03:23
crystal-env preview

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:
@bcardiff
bcardiff / logger2.cr
Created April 11, 2018 14:38
Logger POC
module Logger2
enum Severity
DEBUG
INFO
end
abstract def log(severity, message, context)
macro using(context, forward = nil)
getter logger : Logger2?
@bcardiff
bcardiff / logger2.cr
Last active April 11, 2018 23:12
Logger POC with binding context
abstract class Logger2
enum Severity
DEBUG
INFO
end
abstract def log(severity : Severity, message, context : String)
macro bind(*, context = nil, forward = nil)
struct LoggerBinding
@bcardiff
bcardiff / logger2.cr
Created April 16, 2018 17:05
Logger POC
# 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:36
Logger POC with lazy init
# 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 / README.md
Last active September 21, 2018 18:02
JSON schema sample
@bcardiff
bcardiff / synchronized.cr
Created September 30, 2019 20:01
Synchronized shameless wrapped for Crystal
# $ crystal run -Dpreview_mt synchronized.cr
struct Synchronized(T)
@lock = Mutex.new
getter inner : T
def initialize(@inner : T)
end
@bcardiff
bcardiff / channel-select.md
Created October 8, 2019 20:11
Blocking and non-blocking channel actions

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