Skip to content

Instantly share code, notes, and snippets.

@bcardiff
bcardiff / .gitignore
Last active August 29, 2015 14:23
Crystal spike of Haskell like data
.crystal
@bcardiff
bcardiff / for.cr
Last active September 5, 2019 18:09
for crystal
macro for(expr)
{{raise "invalid syntax. use for e in c." unless expr.args.first.name.stringify == "in"}}
{{expr.args.first.args.first}}.each do |{{expr.name.id}}|
{{expr.args.first.block.body}}
end
end
for e in 1..5 do
puts e
end
@bcardiff
bcardiff / ast_dump.cr
Created June 30, 2015 21:58
Crystal AST dump
require "compiler/crystal/**"
class Object
def dump_inspect(io, level)
io << " " * level
to_s(io)
io << " :: " << self.class
end
end
@bcardiff
bcardiff / 00-README.md
Last active August 29, 2015 14:24
fsm from a ruby way to a crystal way

This intent to show how Ruby practice can be addapted to Crystal. With a total different under the hood implementation, but keeping some of the greatest aspects.

The focus thou is not to stand on how a fsm should be modeled, or defined by a dsl, BUT how some common Ruby practices might be rethinked to take advantage of Crystal.

As an intermediate step, I sometimes like to think in a more plain type/classes design to have a nice compile time experience, but using macros in crystal to reach that from a nice dsl.

NB: There is consideration to name the examples a language way and not the language way .

@bcardiff
bcardiff / keybase.md
Created August 31, 2015 18:30
keybase.md

Keybase proof

I hereby claim:

  • I am bcardiff on github.
  • I am bcardiff (https://keybase.io/bcardiff) on keybase.
  • I have a public key whose fingerprint is A2BC 755E D6EE AC60 6C7E D13D 2BFD 635A 00D0 2045

To claim this, I am signing this object:

@bcardiff
bcardiff / repro331-228-2015-09-02.mba
Created September 2, 2015 15:33
mbuilder repro 331
{"tables":[{"name":"Trackers","guid":"bb1c463d-b35f-4fb0-a18b-78fab5f25963","kind":"local","fields":[{"name":"Phone","guid":"abf4aca1-502c-43f6-acad-0f88c33340fc","valid_values":""}],"protocol":["query","update","insert"]}],"message_triggers":[{"name":"track","enabled":true,"message":{"from":"+1-(234)-567-8912","pieces":[{"kind":"text","text":"track","guid":"815fa0f2-cfd7-4863-94d8-92fdb1430cdd"}],"pattern":"(?i-mx:\\A\\s*track\\s*\\Z)"},"kind":"message_trigger","actions":[{"kind":"create_entity","table":"bb1c463d-b35f-4fb0-a18b-78fab5f25963","field":"abf4aca1-502c-43f6-acad-0f88c33340fc","pill":{"kind":"placeholder","guid":"phone_number"}},{"kind":"send_message","message":[{"kind":"text","guid":"you are been tracked"}],"recipient":{"kind":"placeholder","guid":"phone_number"}}]},{"name":"all","enabled":true,"message":{"from":"+1-(234)-567-8912","pieces":[{"kind":"text","text":"all","guid":"0e2be89a-85dc-4eaf-b988-38f88ff0c9aa"},{"kind":"placeholder","text":"lorem ipsum","guid":"f02701b4-d99f-446b-aa90-39291f7
@bcardiff
bcardiff / README.md
Last active November 17, 2015 01:06
p5e1

INTRODUCTION TO PROGRAMMING FOR THE VISUAL ARTS WITH P5.JS

Assignment 1: Port an Image to Code

@bcardiff
bcardiff / README.md
Last active February 19, 2022 15:13
hex with alpha in p5js
@bcardiff
bcardiff / mtry.cr
Created February 18, 2016 14:58
mtry macro for crystal
# sample of a macro that flood the method calls with `#try`
# as a POC it does not support methods with arguments
macro mtry(expr)
{% if expr.is_a?(Call) %}
mtry({{expr.receiver}}).try(&.{{expr.name}})
{% else %}
{{expr}}
{% end %}
end
@bcardiff
bcardiff / triangles in logo
Created March 10, 2016 18:35
logo program to draw triangles. Use http://www.calormen.com/jslogo/