Skip to content

Instantly share code, notes, and snippets.

View TeTiRoss's full-sized avatar

Rostyslav Semanyshyn TeTiRoss

View GitHub Profile
@TeTiRoss
TeTiRoss / miinto_auth.rb
Created July 1, 2020 07:00
authenticated Miinto orders requested
shop_id = SHOP_ID
channel_response_id = CHANNEL_RESPONSE_ID
channel_response_token = CHANNEL_RESPONSE_TOKEN
time = Time.now.to_i.to_s
seed = rand(1..99)
resourceSig = Digest::SHA256.hexdigest('GET' + "\n" + 'api-order.miinto.net' + "\n" + "/shops/#{shop_id}/orders" + "\n")
headerSig = Digest::SHA256.hexdigest(channel_response_id + "\n" + time + "\n" + seed + "\n" + 'MNT-HMAC-SHA256-1-0')
payloadSig = Digest::SHA256.hexdigest('')
@TeTiRoss
TeTiRoss / config.ru
Last active August 22, 2019 11:13
rack app Sidekiq UI
require 'sidekiq/web'
run Rack::URLMap.new \
'/' => SomeRackApp,
'/sidekiq' => Sidekiq::Web
@TeTiRoss
TeTiRoss / pre_commit_v2
Last active May 13, 2019 13:38
pre commit git hook for Ruby on Rails projects (rubocop & reek required to be installed)
#!/bin/bash
failed=false
ruby_files_modified=`git diff --staged --name-only --diff-filter=ACRM | grep -E '(\.rb|\.ruby|\.rake)' | xargs`
if ! [ -z "$ruby_files_modified" ]; then
printf '\e[1m\e[34m========= reek ============\n\e[0m'
bundle exec reek $ruby_files_modified
if [ $? != 0 ]; then
@TeTiRoss
TeTiRoss / rename_files.rb
Created January 17, 2019 08:26
rename files with ruby
require 'fileutils'
FileUtils.cd('/users/username/pictures') do
files = Dir['cats/*']
files.each do |file_path|
filename = File.basename(file_path)
FileUtils.mv(filename, "cat_#{filename}")
end
@TeTiRoss
TeTiRoss / copy_files.rb
Created January 17, 2019 08:24
copy files from one dir to another with ruby
require 'fileutils'
dirs = Dir["/users/username/pictures/categories/*"]
dest_folder = "/users/username/pictures/pets/"
dirs.each do |dir|
pics = Dir["#{dir}/*"]
pics.each do |pic|
@TeTiRoss
TeTiRoss / schedule.rb
Created January 17, 2019 08:00
whenever respecting app time zone
# config/schedule.rb
require_relative './environment'
def timezoned time
Time.zone.parse(time).utc
end
every :monday, at: timezoned('12am') do
rake 'some:task'
@TeTiRoss
TeTiRoss / pre_commit V1
Last active May 9, 2019 09:46
Rails git pre commit hook
#!/bin/sh
FILES='(js|css|rb)'
FORBIDDEN='(<<<<<<<|=======|>>>>>>>|binding.pry|throw|debugger|console.log|\!important)'
GREP_COLOR='4;5;37;41'
if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then
git diff --cached --name-only | grep -E $FILES | \
xargs grep --color --with-filename -n -E $FORBIDDEN && \
echo "Looks like you are trying to commit something you shouldn't. Please fix your diff, or run 'git commit --no-verify' to skip this check, if you must." && \
exit 1
require 'csv'
CSV.foreach(filename, :headers => true) do |row|
User.create!(row.to_hash)
end