Skip to content

Instantly share code, notes, and snippets.

@AlexKalinin
AlexKalinin / ._README.md
Last active February 15, 2023 05:57
Checking that the folder was continuesly mounted while the long operation was being performed.

Checking that the folder was continuesly mounted while the long operation was being performed.

Why?

I have external hard-drive where I store backups created by MacOS TimeMachine. This hard drive is connected by usb dock-station, which is not protected from power failure. I just wanted to be sure, that, first TimeMachine backup (which is quite a lengthy operation) was not interrapted.

Usage:

# assume that you already have ruby on your computer

if no, go to https://rvm.io/

@AlexKalinin
AlexKalinin / ftp.rb
Created June 24, 2022 06:29 — forked from KarimP/ftp.rb
Using Ruby's Net FTP to upload a stream of partial chunks
# Simple extension of Net::FTP to allow uploading a stream instead of a file
# This allows for transferring of files between servers without downloading entire file first
# The code below is a modification of the storbinary method in Net::FTP
# https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L686
# It goes without saying that the code may break at anytime and may or may not work with other
# features of Net::FTP such as using Resume.
require 'net/ftp'
@AlexKalinin
AlexKalinin / README.md
Created May 17, 2022 17:32 — forked from EugeneKay/README.md
Winode Instructions

NOTE: This Gist concerns the old Linode KVM Beta, NOT the current Manager. Please see linode/docs#501 (comment) for more up-to-date instructions.

You will need:

On the KVM source, run the following to create a VM:

@AlexKalinin
AlexKalinin / sshd_gitbash.sh
Created February 28, 2022 10:50 — forked from fengli320/sshd_gitbash.sh
How to setup SSHD in Git Bash
# Precondition: Git for Windows 2.9.0 + Windows 7, other version of Git for Windows & Windows XP and Windows 10 should also be supported
# In /etc/ssh/sshd_config, set UsePrivilegeSeparation to no
# You can also change other settings of SSHD like port in this file
# Generate key pairs
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N ""
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -q -N ""
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -q -N ""
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -q -N ""
@AlexKalinin
AlexKalinin / hash_deep_diff.rb
Created February 9, 2022 13:39 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@AlexKalinin
AlexKalinin / shards.rb
Last active December 25, 2021 06:12 — forked from ronin/shards.rb
Simple example showing how to monkey patch ActiveRecord to allow database switching
# got from here: https://stackoverflow.com/a/43819672
# Define some required dependencies
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "activerecord", "~> 4.2.8"
gem "sqlite3"
@AlexKalinin
AlexKalinin / gen_keys.sh
Created October 27, 2020 22:20 — forked from hvasconcelos/gen_keys.sh
Create an Sinatra SSL Server
# Generate a self-signed Certificate and a Private Key
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout pkey.pem -out cert.crt
@AlexKalinin
AlexKalinin / rabbitmq-cluster.md
Created May 16, 2020 06:55 — forked from pobsuwan/rabbitmq-cluster.md
How to config rabbitmq server cluster [3 nodes]

How to config rabbitmq server cluster [3 nodes]

Edit /etc/hosts

vi /etc/hosts
192.168.10.157  rabbitmq-1
192.168.10.159  rabbitmq-2
192.168.10.161  rabbitmq-3
@AlexKalinin
AlexKalinin / init_db.rb
Last active May 10, 2020 04:17
MediumArticle: Implementing rake db:* tasks in Non-Rails script (postgres, activerecord) https://medium.com/@AlexKalininHedin/rake-db-tasks-in-non-rails-application-95aa65509448
#!/usr/bin/env ruby
require 'bundler'
Bundler.require(:default)
require 'active_support'
require 'active_record'
require 'pry'
@root_path = File.expand_path File.dirname(__FILE__)
@config = YAML.load_file(File.join(@root_path, 'config.yml'))
def foo(p1:, p2:, p3:)
puts "p1: #{p1}"
puts "p2: #{p2}"
puts "p3: #{p3}"
end
def bar
h1 = { p1: 11, p2: 22, p3: 33 }
foo h1
end