Skip to content

Instantly share code, notes, and snippets.

@mikhailov
mikhailov / qu.rb
Last active Sep 20, 2015
quick union
View qu.rb
class QU
attr_reader :array
def initialize(array)
@array = array
end
def union(p,q)
return if p == q
@array[root(p)] = root(q)
@mikhailov
mikhailov / uf.rb
Last active Sep 20, 2015
union find
View uf.rb
class UF
attr_reader :array
def initialize(array)
@array = array
end
def union(p,q)
return if p == q
@mikhailov
mikhailov / flattenizer.rb
Last active Aug 29, 2015
flatten an array of arbitrarily nested arrays of integers into a flat array of integers (can't use Array#flatten built-in method)
View flattenizer.rb
class Flattenizer
def initialize(params)
if params.empty?
raise ArgumentError, 'Data set is empty'
end
if !params.is_a?(Array)
raise TypeError, 'Data set is not an array'
end
@input_array = params
View vbox.sh
#!/bin/bash -e
curl -O http://ftp.heanet.ie/pub/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso
export VM="MASTER"
export VMDISK="$VM-disk"
export REDHAT_IMAGE="/Users/user/Downloads/CentOS-7.0-1406-x86_64-Minimal.iso"
VBoxManage hostonlyif create
VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.168.20.1
@mikhailov
mikhailov / gist:3fd58bd21ecc5f7220cc
Created Sep 26, 2014
Set specific Ruby version on CentOS
View gist:3fd58bd21ecc5f7220cc
#/bin/bash -e
RUBY_VERSION=2.0.0
if [ "$RUBY_VERSION" == '2.0.0' ]; then
yum -y install ruby20 rubygems20 ruby-devel
alternatives --set ruby /usr/bin/ruby2.0
elif [ "$RUBY_VERSION" == '1.9.3' ]; then
yum -y install ruby19 rubygems19 ruby19-devel
View tables_size.sql
SET @db_name = '***';
SELECT
TBname,
CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Data Size",
CONCAT(LPAD(REPLACE(FORMAT(B.ISize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Index Size",
CONCAT(ROUND(B.ISize * 100 / B.DSize), ' %') "Percentage",
CONCAT(LPAD(REPLACE(FORMAT(B.TSize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Table Size"
FROM
(SELECT table_name TBname, data_length DSize, index_length ISize, data_length+index_length TSize
@mikhailov
mikhailov / gist:9639593
Last active Jul 19, 2021
Nginx S3 Proxy with caching
View gist:9639593
events {
worker_connections 1024;
}
http {
default_type text/html;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;
@mikhailov
mikhailov / nginx.conf
Last active Oct 7, 2018
Jira connection optimised (Nio enabled, gzip disabled on Tomcat, but enabled on Reverse proxy side, Proxy with HTTP 1.1 keep-alive, SSL offload, SPDY). Nginx 1.5.10+ recommended.
View nginx.conf
echo 'events {
worker_connections 1024;
}
error_log /usr/local/Cellar/nginx/1.5.8/error.log;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
@mikhailov
mikhailov / sysctl.conf
Last active Jan 3, 2016
OS X Server TCP/IP tuning
View sysctl.conf
net.inet.tcp.sack=1
net.inet.tcp.rfc1323=1
net.inet.tcp.recvspace=1048576
net.inet.udp.recvspace=1048576
net.inet.tcp.sendspace=1048576
net.inet.tcp.mssdflt=1460
net.inet.tcp.win_scale_factor=8
@mikhailov
mikhailov / Vagrantless
Last active Oct 15, 2017
Vagrantless (draft), tested on OS X only.
View Vagrantless
# This the bash script to handle up-and-runnig VM created through Vagrant
#!/usr/bin/env bash
# PRIVATE: error level message
error_message () {
echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
}