Skip to content

Instantly share code, notes, and snippets.

View rickhull's full-sized avatar

Rick Hull rickhull

View GitHub Profile
# 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
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)
@havenwood
havenwood / hello.cr
Created April 17, 2015 00:09
"Hello, world!" from MRuby embedded in Crystal
@[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
@sasa1977
sasa1977 / conway.ex
Last active November 12, 2017 14:31
Conway's Game of Life in Elixir
# 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}
@rob-brown
rob-brown / life.ex
Last active August 29, 2015 14:09
Conway's Game of Life
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
@havenwood
havenwood / compile.rb
Last active November 9, 2017 05:05
Little script using mruby to compile to self-executable
#!/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