Skip to content

Instantly share code, notes, and snippets.

@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
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@AlexKalinin
AlexKalinin / 00_README.md
Created October 29, 2019 16:47 — forked from mikechau/00_README.md
Logging Rails 4 to Syslog, formatted w/ Logstash

Logging Rails 4 to Syslog, formatted w/ Logstash

Getting Started

Steps to get Rails 4 saving its output to Syslog via Rsyslog. This assumes you are on CentOS, but should be pretty adaptable to any other distribution. Ruby 2.0+ is also required.

  1. Add the gems lograge and logstash-event to your Gemfile. Feel free to remove from production if you'd like to test it in development as well or something.
  2. Update production.rb with the lograge settings and set the logger to Syslog::Logger.
  3. Add the conf files to /etc/rsyslog.d/. /etc/rsyslog.conf should have $IncludeConfig /etc/rsyslog.d/*.conf enabled, so it will load any additional configs from /etc/rsyslog.conf.
@AlexKalinin
AlexKalinin / example_multi_level_dsl.rb
Created February 8, 2019 08:42 — forked from ms-ati/example_multi_level_dsl.rb
Example of a recursive multi-level DSL in Ruby using Docile gem
require 'docile'
# Family tree node, mother and father are Person values as well
Person = Struct.new(:name, :mother, :father)
# Recursive dsl in a mutating builder using Docile
def person(&block)
Docile.dsl_eval(PersonBuilder.new, &block).build
end