Help us understand the problem. What is going on with this article?

横浜rb #75

More than 3 years have passed since last update.

レシピブック 240

mac で ruby で fiddle で cat

#MacOS で fiddle で cat
require "fiddle/import"

module Libc
  extend Fiddle::Importer
  dlload "/usr/lib/libSystem.B.dylib"
  extern "FILE * fopen( char *, char* )"
  extern "int fgetc(FILE*)"
  extern "int fclose(FILE*)"
  EOF=-1
end

def cat(path)
  fp=Libc.fopen( path, "r" )
  while( ( c=Libc.fgetc(fp)  ) !=  Libc::EOF ) do
    print c.chr
  end
  Libc.fclose(fp)
end

ARGV.each do |path|
  cat path
end

レシピブック 241

sleep の返戻値が無意味な感じ。
毎回違うけど、手元で動かしたらこんな感じ:

10.times.map{ sleep 0.4 } #=> [1, 0, 0, 1, 0, 1, 0, 0, 1, 0]

レシピブック 242

ベンチマークは Benchmark.bmbm がお勧め。

require 'benchmark'

M=10000
N=1000000

Benchmark.bmbm do |x|
  x.report("power") { M.times{ 2**N+2**(N+1)} }
  x.report("shift") { M.times{(1<<N)+(1<<(N+1))} }
end
Rehearsal -----------------------------------------
power   2.420000   1.020000   3.440000 (  3.450832)
shift   0.590000   0.340000   0.930000 (  0.921296)
-------------------------------- total: 4.370000sec

            user     system      total        real
power   2.350000   0.880000   3.230000 (  3.238570)
shift   0.540000   0.240000   0.780000 (  0.772868)

と、リハーサルが走ってから本番を測る。

意外と速度に差がある。

レシピブック 243

邪悪な open の使い方

open("|df -k", "r") do |s|
  p s.gets
end

open の引数の冒頭に | を書くと、コマンドの実行になる。こわい。

これを避けるために、 File.open と書くと安全。

それと。
Open3 は windows でも使える。いつからなのかは不明。

ペパボの研修

http://tech.pepabo.com/2016/12/08/pepabo-college-1st/

素晴らしい。羨ましい。

AWS

自分用メモ:Amazon Rekognition を調査する。

Load Average

辺りが参考になる。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away