This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# terminal 1 | |
eam@sprat:~$ ruby -e'puts $$; loop {}' | |
24358 | |
# terminal 2 | |
eam@sprat:~$ gdb -p 24358 | |
gdb> p rb_eval_string("puts 'hello world'") | |
$1 = 0x8 | |
# terminal 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Identity = Struct.new(:value) do | |
def fmap(*args) | |
-> (func) { | |
Identity.new(func.call(self.value)) | |
}.curry[*args] | |
end | |
end | |
Const = Struct.new(:value) do | |
def fmap(*args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@[Link("mruby")] | |
lib MRuby | |
type MRubyState = Void* | |
fun open = mrb_open : MRubyState | |
fun load_string = mrb_load_string(mrb : MRubyState, code : Pointer(UInt8)) | |
fun close = mrb_close(mrb : MRubyState) | |
end | |
CODE = <<-RUBY_CODE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works on Elixir 1.0.x | |
# Usage: just paste to `iex` shell, or run `elixir conway.ex` | |
defmodule Sum do | |
defstruct value: 0 | |
def value(%Sum{value: value}), do: value | |
def add(%Sum{value: value} = sum, x) do | |
%Sum{sum | value: value + x} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Life do | |
# Defaults to B3/S23 | |
defstruct cells: [[]], born: [3], stays: [2, 3], width: 10, height: 10, step: 0 | |
def run(file) do | |
file |> read_file |> loop | |
end | |
def loop(life) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Compiler | |
def initialize | |
@mruby_dir = '/Users/shannonskipper/.rubies/mruby' | |
sanity_check_argv | |
@file = ARGV.first.sub /.rb$/, '' | |
end | |
def run |