Skip to content

Instantly share code, notes, and snippets.

require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "activerecord", require: "active_record"
gem "neighbor", github: "ankane/neighbor"
gem "pg"
end
# CREATE INDEX output omitted
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: l2_distance
psql:repro.sql:8: INFO: l2_distance
id
----
Machine: r7g.large
Dataset: gist-960
Lists: 1000
IP today
INFO: k-means: 46822.401 ms
INFO: assign tuples: 253000.270 ms
IP PR
@ankane
ankane / elasticsearch.rb
Last active March 27, 2024 13:42
searchkick-knn
require "active_record"
require "disco"
require "elasticsearch"
require "searchkick"
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define do
create_table :movies do |t|
t.string :name
<?php
require_once __DIR__ . '/../vendor/autoload.php';
function getPixels($img)
{
$pixels = [];
$width = imagesx($img);
$height = imagesy($img);
for ($y = 0; $y < $height; $y++) {
createdb pgsync_repro1
createdb pgsync_repro2
psql pgsync_repro1 << SQL
CREATE TABLE posts (
id BIGINT PRIMARY KEY,
linked_post_id BIGINT,
FOREIGN KEY (linked_post_id) REFERENCES posts (id)
);
INSERT INTO posts VALUES (1, NULL), (2, 1);
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "activerecord", require: "active_record"
gem "sqlite3"
gem "lockbox", git: "https://github.com/ankane/lockbox.git"
end
1 3.7 1.2 7.2 9
1 7.5 0.5 7.9 0
1 1.6 0.1 7.6 7
0 0.6 2.5 5.0 4
1 1.8 8.4 1.1 2
2 6.8 8.7 8.7 9
2 9.4 9.6 8.6 9
1 0.9 0.7 6.3 6
0 5.7 0.1 0.0 1
1 0.8 8.8 1.3 3
# Bootstrap AWS Deep Learning Base AMI (Ubuntu 18.04)
# install Ruby
sudo snap install ruby --classic
# install LibTorch
wget -O libtorch.zip https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.7.0.zip
unzip libtorch.zip
# download
# https://github.com/onnx/models/tree/master/vision/body_analysis/emotion_ferplus
require "onnxruntime"
require "mini_magick"
img = MiniMagick::Image.open("ranger.jpg")
img.crop "100x100+60+20", "-gravity", "center"
img.resize "64x64^", "-gravity", "center", "-extent", "64x64"
img.colorspace "Gray"
img.write("resized.jpg")