Skip to content

Instantly share code, notes, and snippets.

View misha-krainik's full-sized avatar

Misha Krainik misha-krainik

View GitHub Profile
require 'openssl/cipher'
module Cipher
Algorithm = 'aes-256-cbc'
def encrypt(text, key)
cipher = OpenSSL::Cipher::Cipher.new(Cipher::Algorithm)
cipher.encrypt
cipher.pkcs5_keyivgen(key)
secret = cipher.update(text)
@misha-krainik
misha-krainik / insert_sort.rb
Created October 2, 2016 13:50
INSERT SORT ALGORITHM
# INSERT SORT ALGORITHM
# _____________________________________________________
# $ ruby insert_sort.rb.rb 1 8 7 2 3 0 -1 8 3 7 6 -1
# insert sort argorithm
# original data: [1, 8, 7, 2, 3, 0, -1, 8, 3, 7, 6, -1]
# sorted data: [-1, -1, 0, 1, 2, 3, 3, 6, 7, 7, 8, 8]
arr = ARGV.map(&:to_i)
puts <<DESC
@misha-krainik
misha-krainik / select_sort.rb
Created October 16, 2016 12:28
SELECT SORT ALGORITHM
array = [82, 20, -1, 92, 0, 28, 8, 10]
for i in -1..array.length
min = i
for j in i+1..array.length.pred
if array[j] < array[min]
min = j
end
end
if min != i
(5..10).reduce(-3, :+)
@misha-krainik
misha-krainik / render_statuses.rb
Last active April 1, 2017 14:06
Rails response statuses
100 = :continue
101 = :switching_protocols
102 = :processing
200 = :ok
201 = :created
202 = :accepted
203 = :non_authoritative_information
204 = :no_content
205 = :reset_content
206 = :partial_content
@misha-krainik
misha-krainik / gist:4d30b2ad9c19fd949a0bc3c6780fe52b
Created April 29, 2017 20:44 — forked from holms/gist:5005629
midnight commander dark color theme
Edit mc’s ini file (either ~/.mc/ini or ~/.config/mc/ini) and look for the line [Colors]. Then, change the line base_color to this:
[Colors]
base_color=linux:normal=white,black:marked=yellow,black:input=,green:menu=black:menusel=white:menuhot=red,:menuhotsel=black,red:dfocus=white,black:dhotnormal=white,black:dhotfocus=white,black:executable=,black:directory=white,black:link=white,black:device=white,black:special=white,black:core=,black:stalelink=red,black:editnormal=white,black
@misha-krainik
misha-krainik / docker-compose-daemon.sh
Created September 19, 2017 19:57 — forked from domachine/docker-compose-daemon.sh
run docker-compose in daemon mode and attach to web container
docker-compose up -d
docker attach myapp_web_1
@misha-krainik
misha-krainik / calculate.el
Created January 31, 2018 12:04
Simple elist runner
#! /bin/sh
":"; exec emacs --no-site-file --script "$0" -- "$@" # -*-emacs-lisp-*-
(print (+ 2 2))
@misha-krainik
misha-krainik / reverse.js
Created March 5, 2018 16:06
String reverse.
arr = Array.from("Hello world!");
arrLen = arr.length;
arrMidLen = Math.floor(arrLen / 2);
arr.forEach(function(v, i) {
if (arrMidLen > i) { return }
var f = arr[i];
var e = arr[arrLen - i - 1];
arr[i] = e;
arr[arrLen - i - 1] = f;
});
@misha-krainik
misha-krainik / rust-rr-dbg.sh
Created July 1, 2018 10:23
Debugging Rust program via rr + rustgdb
#!/bin/bash
if [[ -z $1 ]]; then
echo 'Set ./target/debug/<programm_name> as argument'
else
sudo rr record -n $1
sudo rr replay -d rust-gdb ~/.local/share/rr/latest-trace
fi