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 |
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
$ chruby mruby | |
trace: | |
[0] -:1 | |
-:1:undefined method 'defined?' for main (NoMethodError) | |
$ |
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 'benchmark/ips' | |
def new_hash | |
{ foo: :bar, baz: :quux } | |
end | |
immutable = new_hash | |
Benchmark.ips do |b| | |
b.config time: 3, warmup: 0.5 |
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:~$ cd btest | |
vagrant@contrib-jessie:~/btest$ mkdir -p foo/bar/baz | |
vagrant@contrib-jessie:~/btest$ cd foo | |
vagrant@contrib-jessie:~/btest/foo$ echo "puts :hello_world" > test.rb | |
vagrant@contrib-jessie:~/btest/foo$ ruby test.rb | |
hello_world | |
vagrant@contrib-jessie:~/btest/foo$ bundle exec ruby test.rb | |
Could not locate Gemfile or .bundle/ directory | |
vagrant@contrib-jessie:~/btest/foo$ touch Gemfile | |
vagrant@contrib-jessie:~/btest/foo$ bundle exec ruby test.rb |
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
# frozen_string_literal: true | |
require 'rake/task' | |
require 'digest' | |
module Rake | |
class ChecksumTask < Task | |
# satisfying an API here; scope is purposely ignored | |
def self.scope_name(_scope, task_name) | |
Rake.from_pathname(task_name) | |
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
require 'rake' | |
require 'benchmark/ips' | |
existing = Dir['**/*'] | |
puts "known existing files: #{existing.size}" | |
nonexist = existing.map { [rand(9**9), rand(9**9)].join('.') } | |
def old_timestamp(name) | |
if File.exist?(name) |
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
[4.999999999999999, 5] | |
[9.999999999999998, 10] | |
[3.0000000000000004, 3] | |
[6.000000000000001, 6] | |
[3.0000000000000004, 3] | |
[6.000000000000001, 6] | |
[11.000000000000002, 11] | |
[5.000000000000001, 5] | |
[10.000000000000002, 10] | |
[7.000000000000001, 7] |
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
# Open one end of named pipe | |
# @argument pipe_path - path to fifo | |
# @argument flag - [r, w, w+, ... | |
# @argument wait_on_str - continue if can read] | |
# @returns named_pipe -handle | |
def named_pipe( pipe_path, flag, wait_on_str=nil ) | |
if File.exists? pipe_path | |
raise "bad #{pipe_path}" unless File.pipe? pipe_path | |
end | |
pipe_handle = File.mkfifo pipe_path |
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 'socket' | |
require 'thread' | |
host = ARGV.shift || 'localhost' | |
port = ARGV.shift || 9999 | |
num_sockets = ARGV.shift || 9999 | |
words = %w{lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua} | |
sockets = Array.new(num_sockets.to_i) { TCPSocket.new(host, port.to_i) } |
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
irb(main):027:0> xs | |
=> [1, 10, 100, 1000] | |
irb(main):028:0> ys = xs.map { |x| x**3 } | |
=> [1, 1000, 1000000, 1000000000] | |
irb(main):029:0> Fit.linear(xs, ys) | |
=> [-35636508, 1029295, 0.9916277794417635] |