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
[2] pry(main)> Pandas = PyCall.import_module('pandas') | |
/Users/mrkn/src/github.com/mrkn/pycall-next/lib/pycall/init.rb:20: warning: instance variable @handle not initialized | |
/Users/mrkn/src/github.com/mrkn/pycall-next/lib/pycall/init.rb:26: warning: loading in progress, circular require considered harmful - /Users/mrkn/src/github.com/mrkn/pycall-next/lib/pycall.bundle | |
from bin/console:10:in `<main>' | |
from /Users/mrkn/.rbenv/versions/2.4.1-o0/lib/ruby/gems/2.4.0/gems/pry-byebug-3.4.2/lib/pry-byebug/pry_ext.rb:11:in `start_with_pry_byebug' | |
from /Users/mrkn/.rbenv/versions/2.4.1-o0/lib/ruby/gems/2.4.0/gems/pry-0.10.4/lib/pry/pry_class.rb:169:in `start' | |
from /Users/mrkn/.rbenv/versions/2.4.1-o0/lib/ruby/gems/2.4.0/gems/pry-0.10.4/lib/pry/repl.rb:15:in `start' | |
from /Users/mrkn/.rbenv/versions/2.4.1-o0/lib/ruby/gems/2.4.0/gems/pry-0.10.4/lib/pry/repl.rb:38:in `start' | |
from /Users/mrkn/.rbenv/versions/2.4.1-o0/lib/ruby/gems/2.4.0/gems/pry-0.10.4/lib/pry/input_lock.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
require 'pycall/import' | |
include PyCall::Import | |
pyimport 'matplotlib.pyplot', as: 'plt' | |
plt[:plot].([1, 2, 3, 4, 5], 5.times.map { rand }) | |
plt[:show].() |
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
class Vocabulary | |
def initialize | |
@words = [] | |
@index = {} | |
end | |
def <<(word) | |
unless @index[word] | |
@index[word] = @words.length | |
@words << word |
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' | |
Benchmark.ips do |x| | |
rat = 123456789123456789/987654321r | |
flt = 123456789.123456789 | |
fix = 1234567890 | |
big = 12345678901234567890 | |
x.report('rat + fix') { rat + fix } | |
x.report('rat + big') { rat + big } |
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 'daru' | |
require 'tempfile' | |
require 'open-uri' | |
def read_as_dataframe(url) | |
Tempfile.open('hash_bench') do |tmpfile| | |
tmpfile.puts "category\tx\ty" | |
open(url) do |io| | |
io.each_line do |line| | |
next unless line =~ /^TABLE/ |
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
m = 0 | |
n = 5 | |
10_000_000.times do | |
xs = Array.new(n) { 1.0 + 1e-6 * (0.5 - rand) } | |
sq_mean = xs.map {|x| x**2 }.sum / n | |
mean_sq = (xs.sum / n)**2 | |
var = sq_mean - mean_sq | |
p [m += 1, var] if var.negative? | |
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
$ ./ruby -v -rbenchmark -e 'Benchmark.bmbm() {|x| x.report("even?") { 100_000_000.times { 1.even? } } } | |
' | |
ruby 2.4.0dev (2016-03-18 trunk 54163) [x86_64-darwin15] | |
Rehearsal ----------------------------------------- | |
even? 5.470000 0.020000 5.490000 ( 5.525505) | |
-------------------------------- total: 5.490000sec | |
user system total real | |
even? 5.590000 0.020000 5.610000 ( 5.668936) |
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
z='ズン';d='ドコ';loop.lazy.map{[z,d].sample.tap{|x|$><<x}}.each_cons(5){|x|break if x.join==z*4+d};puts'キ・ヨ・シ!' |
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
from PIL import Image, ImageCms | |
im = Image.open(image_path) | |
if im.mode != "RGB": | |
im = im.convert("RGB") | |
srgb_profile = ImageCms.createProfile("sRGB") | |
lab_profile = ImageCms.createProfile("LAB") | |
rgb2lab_transform = ImageCms.buildTransformFromOpenProfiles(srgb_profile, lab_profile, "RGB", "LAB") |
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
/* | |
* example.c | |
* | |
* This file illustrates how to use the IJG code as a subroutine library | |
* to read or write JPEG image files. You should look at this code in | |
* conjunction with the documentation file libjpeg.txt. | |
* | |
* This code will not do anything useful as-is, but it may be helpful as a | |
* skeleton for constructing routines that call the JPEG library. | |
* |