Skip to content

Instantly share code, notes, and snippets.

View leonid-shevtsov's full-sized avatar
🇺🇦
Help Ukraine Win

Leonid Shevtsov leonid-shevtsov

🇺🇦
Help Ukraine Win
View GitHub Profile
require 'json'
canvas = JSON.parse(STDIN.read, symbolize_names: true)
all_ids = canvas[:nodes].map { |n| n[:id] }
dest_ids = canvas[:edges].map {|e| e[:toNode] }.uniq
root_ids = all_ids - dest_ids
nodes_by_id = canvas[:nodes].to_h {|n| [n[:id],n] }
graph = canvas[:edges].group_by {|e| e[:fromNode] }.transform_values { |vv| vv.map {|v| v[:toNode] }}
@leonid-shevtsov
leonid-shevtsov / README.md
Created June 20, 2024 08:44
Mindmap helpers for Obsidian Canvas Style Menu
  1. Install https://github.com/michaellw/Obsidian-Canvas-Style-Menu into your vault
  2. Copy mindmap_helpers.json to vault/.obsidian/plugins/canvas-style-menu/packages/mindmap_helpers.json
  3. Copy mindmap_helpers.css to `vault/.obsidian/snippets
  4. Enable "Mindmap Helpers" in Canvas Style Menu settings
  5. Enable snippets in Appearance settings
@leonid-shevtsov
leonid-shevtsov / chromium_pickle.imhex
Created June 13, 2024 08:39
ImHex protocol description for Chromium Pickle data
struct PickleString {
u32 length;
char16 chars[length];
char16 zeroChar;
};
struct PickleEntry {
PickleString key;
PickleString value;
};
@leonid-shevtsov
leonid-shevtsov / lines_to_canvas.rb
Created June 13, 2024 07:20
Convert a list of lines into Obsidian Canvas
# ruby lines_to_canvas.rb <items.txt >items.canvas
require 'random/formatter'
require 'json'
nodegap = 10
nodewidth = 300
nodeheight = 60
list = STDIN.readlines
package main
import (
"fmt"
"runtime"
)
func main() {
var stats runtime.MemStats
require 'json'
require 'strscan'
FILENAME = ARGV[0]
POOLSIZE = 6
BUFSIZE = 128 * 1024 * 1024
pool = Array.new(POOLSIZE) do |_idx| # rubocop:disable Metrics/BlockLength
outpipe_out, outpipe_in = IO.pipe(encoding: Encoding::BINARY)
cmdpipe_out, cmdpipe_in = IO.pipe(encoding: Encoding::BINARY)
require 'strscan'
stats = Hash.new { |h, k| h[k] = [10_000, -10_000, 0, 0] }
SEMI = String.new(';', encoding: Encoding::BINARY)
NEWLINE = String.new("\n", encoding: Encoding::BINARY)
BUFLEN = 128 * 1024 * 1024
buf = ' ' * BUFLEN
buf.force_encoding(Encoding::BINARY)
@leonid-shevtsov
leonid-shevtsov / 1_trivial.rb
Last active March 8, 2024 21:24
1 Billion Row Challenge... in Ruby?
stats = {}
File.open('measurements.txt') do |f|
f.each_line do |line|
city, temp_s = line.split(';')
temp = temp_s.to_f
stats[city] ||= {
min: 10_000,
max: -10_000,
sum: 0,
@leonid-shevtsov
leonid-shevtsov / monocsv.rb
Created February 9, 2024 20:07
Розбір CSV з Монобанку
require 'csv'
def parse_monocsv(csv_string)
columns = %i[
date
hour
debit_or_credit
details
counteragent
edrpou
enum DateIndex {
// All dates are integers counting from this date
static let zeroDate = Calendar.current.date(from: .init(year: 1970, month: 1, day: 1))!
static func fromDate(_ date: Date) -> Int {
Calendar.current.dateComponents([.day], from: zeroDate, to: date).day!
}
static func toDate(_ index: Int) -> Date {
Calendar.current.date(byAdding: .day, value: index, to: zeroDate)!