Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Nakilon / slbsa.rb
Last active July 5, 2025 18:51
size-limited binary-search array
require "set"
class SLBSA
def initialize max_size, &block
@max_size = max_size
@values = []
@scores = []
@calculate = block
@set = Set.new
end
def to_a
@Nakilon
Nakilon / table_print.rb
Created July 4, 2025 20:07
table_print.rb
require "io/console"
def table_print target = ::STDOUT
sizes = transpose.map{ |col| col.map{ |_| _.to_s.size }.max }
sizes.max.then{ |max| sizes.map!{ |_| [max - 1, _].min } } while sizes.sum + sizes.size >= ::IO::console.winsize[1]
each{ |row| target.puts row.zip(sizes).map{ |str, size| "%-#{size}s" % ("%.#{size}s" % str) }.join(" ") }
end
@Nakilon
Nakilon / self-currying.rb
Created July 4, 2025 12:26
self-currying
Config = lambda do
dir = nil
lambda do |_dir = nil|
dir ||= _dir
p dir
end
end.call
Config.()
Config.("asd")
@Nakilon
Nakilon / gist:1d1a741ab29176ffa7873e5a10338347
Created May 11, 2025 15:37 — forked from larsthegeek/gist:4029012
Update RubyGems to a specific version (for legacy system installs)
How to update RubyGems to a specific version
RubyGems can update itself to the latest version:
gem update --system
However, you always get the newest version. This may be a problem if you’re trying to replicate a known-good environment: for example, the output format of `gem list` in RubyGems 1.3.7 breaks Chef 0.8.16 in certain circumstances. 1.3.6 is fine.
Here’s how to update to a specific version—in this case, 1.3.6:
gem install -v 1.3.6 rubygems-update && \
@Nakilon
Nakilon / code.rb
Created October 17, 2024 15:54
largest indentation
module Cainiao
...
def self.main login, password, month, from, to, log_bt = false
...
@mutex.synchronize do
...
[true, xlsx_string[
paginate.call ->{
YAML::Store.new("cache.yaml").transaction do |store|
table.tap{ |_| fail unless 1 <= _.size }.flat_map.with_index do |act, i|
docker
install
(https://stackoverflow.com/q/61401626/322020)
$ sudo apt-get update
$ sudo apt install -y docker.io
disable shutting down on Ubuntu's "daily upgrade"
$ sudo apt-mark hold docker.io
check autorun
$ sudo systemctl is-enabled docker.service
$ sudo systemctl is-enabled containerd.service

I have been an active user of Stack Overflow since 2010 and I can assure you that this place is not what it seems.

A group of inadequate rubyists teaming with SO moderators are stalking me and abusing their privileges to delete all my content for no reason. When I have managed to make one moderator to follow the rules, in revenge they randomly chose one old answer of mine and collectively downvoted it 5 times within minutes -- I flagged it but the moderators ignored it, just like they have ignored all the rest of my flags. Because they are the same team. Toxic community of ungrateful inadequate people who censor me and delete my content simply because I responsibly follow the official rules of SO that they don't follow. They blatantly violating multiple SO rules, they are collectively stalking, downvoting and deleting random answers of mine just to show that nothing can stop them because they are moderators. Such behavior is not professional, it is disgusting and shameful. They are such mean people that

2012 01
2012 02
2012 03
2012 04 ОТР
2012 05 ОТР
2012 06 ОТР
2012 07 ОТР
2012 08
2012 09
2012 10
@Nakilon
Nakilon / ubuntu.txt
Last active December 6, 2024 03:50
ubuntu
if configured openssh during installation with 'ubuntu' user:
edit dev:~/.ssh/config and then: ssh ubuntu@...
$ sudo useradd nakilon
$ adduser nakilon sudo
$ echo "nakilon ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/dont-prompt-nakilon-for-sudo-password && chmod 440 /etc/sudoers.d/dont-prompt-nakilon-for-sudo-password
$ mkdir -p /home/nakilon/.ssh
$ sudo cp ~/.ssh/authorized_keys /home/nakilon/.ssh/
$ sudo chmod 700 /home/nakilon/.ssh
$ sudo chmod 600 /home/nakilon/.ssh/authorized_keys
$ sudo chown -R nakilon:nakilon /home/nakilon
@Nakilon
Nakilon / main.c
Created January 7, 2023 23:03
вс, 16 мар. 2014 г., 08:49
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // memcpy
#include <math.h> // sin cos
struct scrimage {
int width, height;
unsigned** pixels;
};