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 'sinatra' | |
| require 'sqlite3' | |
| require 'bcrypt' | |
| # initialize SQLite database | |
| DB = SQLite3::Database.new 'users.db' | |
| DB.results_as_hash = true | |
| # create users table if needed | |
| DB.execute <<-SQL |
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 'optparse' | |
| class Practice | |
| def initialize | |
| @fname = 'data.txt' | |
| # predefined key for the demo (32-byte) | |
| @key = "12345678901234567890123456789012" | |
| # prepage libraries in bg for faster start | |
| @libs_loading_thr = Thread.new do | |
| require 'openssl' |
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 'openssl' | |
| require 'base64' | |
| # AES256 encryption | |
| def aes_encrypt(text, key) | |
| cipher = get_cipher.tap { _1.encrypt; _1.key = key } | |
| iv = cipher.random_iv # 16 bytes | |
| cipher_text = cipher.update(text) + cipher.final | |
| # *ensure there is no newline char in the encoded text | |
| Base64.strict_encode64(iv + cipher_text) |
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
| # ц | |
| puts `chcp` | |
| p Encoding.default_external | |
| p file:__FILE__ | |
| p dir:__dir__ | |
| puts '-'*10 | |
| p LOAD_PATH:$LOAD_PATH[0] | |
| p start_with:$LOAD_PATH[0].start_with?(__dir__) |
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 'openssl' | |
| require 'base64' | |
| # calibrate numbers to get 1s or 10s in solo | |
| N = 48 | |
| DATA_SIZE = 600_000 | |
| workers_N = 2 | |
| # prepare static data set | |
| DATA_ARR = N.times.map do |n| |
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 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32] | |
| in the main thread | |
| Total: 2.092 | |
| in 2 ractors | |
| [=[<OBJ_INFO:gc_mark_ptr@../ruby-3.0.0/gc.c:6106> 0x00000000062f6920 [0 M ] T_NONE | |
| sha_test_big_data.rb:31: [BUG] try to mark T_NONE object | |
| ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32] |
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 'openssl' | |
| require 'base64' | |
| $VERBOSE = nil | |
| #GC.disable | |
| # N = 1_500_000 | |
| N = 100 | |
| class BaseEncryption | |
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 'digest/sha2' | |
| # GC.disable | |
| N = 1_500_000 | |
| #N = 500_000 | |
| def workload | |
| sha2 = Digest::SHA2.new | |
| N.times do |
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
| 1.1) Normal | |
| insert 500 (w:0) -- total: 0.207 s, item time = 0.413 ms ( 1.00x) (0.00) | |
| insert 500 (w:1) -- total: 3.786 s, item time = 7.571 ms ( 1.00x) (0.00) | |
| 500 times find all -- total: 14.368 s, item time = 28.735 ms ( 1.00x) (0.00) | |
| 500 times find first (full) -- total: 5.316 s, item time = 10.632 ms ( 1.00x) (0.00) | |
| 500 times find first (full by id) -- total: 4.185 s, item time = 8.370 ms ( 1.00x) (0.00) | |
| 500 times find first (only name) -- total: 4.954 s, item time = 9.907 ms ( 1.00x) (0.00) | |
| 500 times count() -- total: 2.740 s, item time = 5.479 ms ( 1.00x) (0.00) | |
| single find first (full) (0) -- total: 0.004 s, item time = 4.160 ms ( 1.00x) (0.00) | |
| single find first (full) (1) -- total: 0.014 s, item time = 13.738 ms ( 1.00x) (0.00) |
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
| puts 'start' | |
| require 'mongo' | |
| Mongo::Logger.level = Logger::FATAL | |
| $client = Mongo::Client.new('mongodb://127.0.0.1:15000/test', :connect => :direct, min_pool_size:1) | |
| @item_tyme_by_title = {} | |
| def watch(title:) | |
| ttime = nil | |
| _time_start = Time.now |
NewerOlder