Skip to content

Instantly share code, notes, and snippets.

View j3ck's full-sized avatar
🏠
Working from home

Eugene j3ck

🏠
Working from home
View GitHub Profile
@j3ck
j3ck / gist:570754c337288cd6f8361dc2c51eadf1
Created July 12, 2022 07:41
pg installation errrors
gem install pg -v '0.18.1' -- --with-cflags="-Wno-error=implicit-function-declaration"
@j3ck
j3ck / 1.rb
Created December 27, 2021 19:28
#routes.rb
Rails.application.routes.draw do
get 'fresh_updates', to: 'home#fresh_updates', constraints: { format: :xml }
end
#home_controller.rb
class HomeController < ApplicationController
def fresh_updates
updater = Updater.new
updater.call # updates fresh_updates file
# https://www.codewars.com/kata/52b7ed099cdc285c300001cd/train/ruby
require 'pry'
def sum_of_intervals(intervals)
res = intervals
del = []
new_res = []
stop = false
require 'open-uri'
@files =
[
'file_example_JPG_1MB.jpg',
'file_example_GIF_1MB.gif',
'file_example_PNG_1MB.png'
]
def sync
@j3ck
j3ck / README.md
Created July 15, 2021 20:55 — forked from wvengen/README.md
Ruby memory analysis over time

Finding a Ruby memory leak using a time analysis

When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.

There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the

MacBook-Pro-Eugene:parimatch_rus-back j3ck$ ruby -v
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin18]
MacBook-Pro-Eugene:back j3ck$ irb
2.3.5 :001 > order = []
=> []
2.3.5 :002 > columns = [
2.3.5 :003 > {:name=>:id},
2.3.5 :004 > {:name=>:em},
2.3.5 :005 > {:name=>:na},
2.3.5 :006 > {:name=>:si},
При возникновении проблем с отображением кириллических символов можно попробовать
отключить передачу переменных окружения LC* и LANG через ssh сессию.
Для этого необходимо закомментировать SendEnv LANG LC_* в файле/etc/ssh/ssh_config.
@j3ck
j3ck / t.rb
Created December 7, 2020 16:43
def export
favorites = Favorite.all
@products = Product.where(id: favorites.map(&:product_id).uniq)
count = favorites.group_by(&:product_id).map do |product_id, favorites|
[@products.find { |product| product.id == product_id }, favorites.length]
end
@favorite_count = count.sort_by { |arr| arr.last }.reverse.to_h
end
@j3ck
j3ck / gist:4cb04b708f9f2abe59d4c9f29f3b1d9e
Created September 22, 2020 10:24
docker localhost mac
host.docker.internal:port
@j3ck
j3ck / qwe.sh
Created January 9, 2020 10:25
show mem usage by process in mb sorted grouped
echo "%CPU %MEM MEM PROCESS"
ps aux | awk '{mem[$11]+=int($6/1024)}; {cpuper[$11]+=$3};{memper[$11]+=$4}; END {for (i in mem) {print cpuper[i]"% ",memper[i]"% ",mem[i]" MB ",i}}' | sort -k3nr | head -n 5