Skip to content

Instantly share code, notes, and snippets.

View rickhull's full-sized avatar

Rick Hull rickhull

View GitHub Profile
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
$ chruby mruby
trace:
[0] -:1
-:1:undefined method 'defined?' for main (NoMethodError)
$
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
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
# 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
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)
[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]
@rickhull
rickhull / open_named_pipe.rb
Last active November 1, 2017 23:40
Opens a named pipe in given path, creates the named pipe -file if needed
# 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
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) }
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]