Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / .gitignore
Last active August 29, 2015 14:23
Crystal spike of Haskell like data
.crystal
@bcardiff
bcardiff / README.md
Created June 19, 2015 08:24
Autocode metaprogramming POC in Crystal

Compiling

crystal build main.cr

will change Settings declaration in main.cr from

class Settings
@bcardiff
bcardiff / README.md
Last active November 21, 2017 16:39
wkhtmltopdf binding for crystal

Experiment for wkhtmltopdf

brew install wkhtmltopdf
crystal wkhtmltopdf.cr

known issue: althout conversion succeeds the wkhtmltopdf process seems to hanging in the very end :-(

@bcardiff
bcardiff / todos.rb
Last active August 29, 2015 14:14
List of TODOs in ./app/ decorated with blame sorted by time git grep blame
require 'date'
target = ARGV[1] || "."
files = %x(git grep -n 'TODO*' #{target})
lines = []
length_author = 0
length_file = 0
@bcardiff
bcardiff / base.cr
Created June 18, 2014 20:36
file system abstraction for crystal
macro collect_alias_method(method, type)
def {{method}}
res = [] of {{type}}
{{method}} do |e|
res << e
end
res
end
end
@bcardiff
bcardiff / README.rdoc
Created July 17, 2013 15:09
Render views as angular text/ng-template in rails

Usage

1) Drop views and partials anywhere in app/views

|-- app
|   `-- views
|       `-- shared
|           `-- angular_views
|               |-- foo
|               |   `-- view3.html.haml