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
begin | |
require 'flay_task' | |
FlayTask.new do |t| | |
t.dirs = ['lib'] | |
t.verbose = true | |
end | |
rescue LoadError | |
warn 'flay_task unavailable' | |
end |
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
module CompSci | |
# has a value and an array of children; allows child gaps | |
class Node | |
attr_accessor :value | |
attr_reader :children | |
def initialize(value, children: []) | |
@value = value | |
if children.is_a?(Integer) | |
@children = Array.new(children) |
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
group "cpu" do | |
File.readlines("/proc/stat").grep(/^cpu/).each do |l| | |
name, user, nice, csystem, idle, iowait, irq, softirq = l.split(/\s+/).map(&:to_i) | |
total = busy + idle | |
counter "busy", value: busy, mute: true | |
counter "total", value: total, mute: true | |
gauge "usage" do | |
value("busy") / value("total") * 100 | |
end |
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
vagrant@contrib-jessie:~/git/mruby-tools (master)$ ./util.rb hello_world.rb goodbye_world.rb -o myprog | |
compiling... | |
created binary executable: myprog | |
vagrant@contrib-jessie:~/git/mruby-tools (master)$ file myprog | |
myprog: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=bb9af8c7a3aaedcb51da5b6aca8e0ba68d1f27f2, not stripped | |
vagrant@contrib-jessie:~/git/mruby-tools (master)$ ./myprog |
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
RANDMAX = 1_000 | |
NUMBERWANG = 1_000 | |
NUMS = (0..(RANDMAX - 1)).to_a.shuffle | |
def number(num) | |
if num % NUMBERWANG == 0 | |
NUMS.shift | |
NUMS.push rand RANDMAX | |
end | |
NUMS[num % RANDMAX] |
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
module Foo | |
def print(msg) | |
p [msg, self] | |
end | |
end | |
class Bar | |
include Foo | |
def initialize |
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
vagrant@contrib-jessie:~/mruby/sleep_world$ cat build_config.rb | |
puts "BUILD CONFIG: #{__FILE__}" | |
MRuby::Build.new do |conf| | |
toolchain :gcc | |
conf.gem git: 'https://github.com/matsumotory/mruby-sleep' | |
end | |
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
prices = { | |
"tennis ball" => 4.99, | |
"beach ball" => 12.99, | |
"giraffe" => 93.86, | |
} | |
print "What is your name? " | |
name = gets.chomp |
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
require 'minitest/autorun' | |
def rock(other) | |
case other | |
when :rock then 0 | |
when :paper then :paper | |
when :scissors then :rock | |
else | |
raise "unknown value: #{other}" | |
end |
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
vagrant@contrib-jessie:~/git/mruby (master)$ echo $MRUBY_CONFIG | |
/home/vagrant/mruby/build_config.rb | |
vagrant@contrib-jessie:~/git/mruby (master)$ cat $MRUBY_CONFIG | |
puts "\n" * 20 | |
puts "HELLO WORLD" | |
puts "\n" * 5 | |
MRuby::Build.new do |conf| | |
toolchain :gcc |