Skip to content

Instantly share code, notes, and snippets.

View vitalyp's full-sized avatar
💭
HaPpY

Vitaly Pestov ua vitalyp

💭
HaPpY
View GitHub Profile
class ApplicationController < ActionController::Base
after_filter :allow_iframe
protect_from_forgery with: :exception
private
def current_user
User.first
#@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
@vitalyp
vitalyp / http.js
Created March 13, 2020 19:49
How to use axios interceptors to patch cookies
var http = axios.create()
http.interceptors.request.use(function(request) {
let csrfToken = sessionStorage.csrf
request.headers.post['X-CSRF-Token'] = csrfToken
request.headers.patch['X-CSRF-Token'] = csrfToken
request.headers.delete['X-CSRF-Token'] = csrfToken
}
@vitalyp
vitalyp / cook.rb
Last active March 13, 2020 19:45
Set req cookies from resp
@authentication_cookie = response.env[:response_headers]["set-cookie"]
response = conn.get do |req|
req.headers ['cookie'] = @authentication_cookie
req.url, params
end
@vitalyp
vitalyp / test.rb
Last active June 24, 2019 15:19
Draft benchmark code for testing speed of db records updating with commit transaction per each record, and without it
# $ rails c
# > require "#{Rails.root}/test.rb"
# > TestTb.new.test1; TestTb.new.test2
# * Results: 27252 records processed in: 56 sec (within Transaction), 107 sec (without Transaction)
class TestTb
TRANSACTION_SCOPE = -> (func) { Book.transaction { func.call } }
WHERE_QUERY = -> { { autor_id: @value == 0 ? 1 : 0 } }
def initialize; @percent_count = @percents = @count = 0 end
@vitalyp
vitalyp / lines_numbers.html
Last active June 24, 2019 15:29
MAGIC_HTML_TEST (see line numbers on each row)
<!-- HTML generated using hilite.me --><div style="background: #000000; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><table><tr><td><pre style="margin: 0; line-height: 125%"> 1
2
3
4
5
6
7
8
9
10
@vitalyp
vitalyp / getDiff.sh
Created January 30, 2018 10:28
Get diff Files since last 5 commits
git archive -o update.zip HEAD $(git diff --name-only HEAD~5)
@vitalyp
vitalyp / heroku midnight commander
Created June 29, 2017 08:58
Midnight Commander for Heroku
At `heroku run bash` session:
wget -O - https://gist.githubusercontent.com/vitalyp/b7ee6db012c33709f7f8de5e58dd05b5/raw/846999eb9896ae4b3280422561cb1d510cefdb53/heroku_mc.sh | bash
@vitalyp
vitalyp / heroku_mc.sh
Created June 29, 2017 08:51
How to setup midnight-commander file manager to heroku
#!/bin/bash
# Create file:
# cat > heroku_mc.sh <<- "EOF"
# this file contents
# EOF
mkdir -p /tmp
McDIR="/tmp/mc";McBinDIR="$McDIR/bin";mkdir -p $McDIR;cd $McDIR;TmpDIR="/temp_deb";mkdir -p $McDIR/$TmpDIR;cd $McDIR/$TmpDIR;wget http://security.ubuntu.com/ubuntu/pool/universe/m/mc/mc_4.8.1-2ubuntu1_amd64.deb;ar -x mc_4.8.1-2ubuntu1_amd64.deb;tar -xvf data.tar.gz;
mv usr/* $McDIR;mkdir $McDIR/etc;mv ./etc/mc/* $McDIR/etc;cd $McDIR;rm -rf $TmpDIR;
@vitalyp
vitalyp / seneca.md
Last active June 24, 2019 15:31
SenecaJS - A microservices toolkit for Node.js
# with comments
def get_random_bytes count
random = `dd if=/dev/urandom | head -c #{count}`
puts "random data is:\n#{random}\n\r-----length is: #{random.length}"
random
end
def clip_encoded_with data_str, encoding
encoded = data_str.encode(encoding, invalid: :replace, undef: :replace, replace: '')