Skip to content

Instantly share code, notes, and snippets.

View januszm's full-sized avatar

Janusz Mordarski januszm

View GitHub Profile
@januszm
januszm / elasticsearch_on_linux.sh
Last active March 19, 2021 09:33
Elasticsearch on Amazon Linux
# as root or with sudo
swapoff -a
sysctl -w vm.swappiness=1
sysctl -w fs.file-max=262144
sysctl -w vm.max_map_count=262144
yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum install mysql-devel redis-devel
amazon-linux-extras install redis4.0
@januszm
januszm / run_as_cron.sh
Created March 1, 2021 12:55
Run command as cron
# env - run a program in a modified environment
# envirotnment is read from crontab file, usually it's below and nothing else:
# SHELL=/bin/sh
# PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
env - `cat /etc/crontab | grep -v "#" | grep -v "^$" | grep -v /etc/cron` my_script.sh
@januszm
januszm / pipenv_locking.svg
Created February 23, 2021 19:09
pipenv lock flamegraph
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@januszm
januszm / install-python-ubuntu.sh
Created February 23, 2021 13:46 — forked from ytspar/install-python-ubuntu.sh
Install Python with Pyenv on Ubuntu (16.04)
sudo apt-get update
sudo apt-get install build-essential git libreadline-dev zlib1g-dev libssl-dev libbz2-dev libsqlite3-dev
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
# may need this, but install script above should handle it; and yeah, you can do multiline inserts with awk/sed or whatever
echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.6.0
@januszm
januszm / pg_dump_restore.sh
Last active March 13, 2023 18:02
Postgresql dump and load compressed
sudo amazon-linux-extras install postgresql12
pg_dump -Fc -O -h yyy-production.xxx.region.rds.amazonaws.com -p 5432 -U yyy yyy_production -f yyy.dump
# TRUNCATE TABLE tables ... RESTART IDENTITY
# rails db:migrate
pg_restore -Fc -O --disable-triggers --data-only -h yyy-staging.xxx.region.rds.amazonaws.com -d yyy_staging -U yyy yyy.dump
# both commands accept the --table option to specify which table to dump/restore
# select setval('TABLE_NAME_id_seq', (select max(id) from TABLE_NAME)); may be required after RESTART IDENTITY, +1
# In case of version mismatch between the server and pg_dump, add pgdgXX repo and install XX client
[pgdg14]
@januszm
januszm / gist:e25cc9fd7a1ce97fa10e36720c7589e2
Created August 23, 2020 22:21
Print stacktrace without site-packages in debugger
import traceback; [line for line in traceback.format_stack() if not 'site-packages' in line]
@januszm
januszm / ruby_benchmark.rb
Created July 9, 2020 10:46
Ruby quick benchmark
# alternatively use benchmark/ips
n = 100_000
data = "..."
Benchmark.ips do |benchmark|
benchmark.report("include?") do
n.times { data.to_s.downcase.include?('windows') }
end
benchmark.report("match?") do
@januszm
januszm / wait_until.rb
Created March 30, 2019 11:28 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: '[email protected]'
fill_in 'password', with: 'test'
@januszm
januszm / grafana.ini
Created August 7, 2018 18:17 — forked from xlson/grafana.ini
Modifying grafana.ini of a running docker container
[database]
log_queries = true
@januszm
januszm / convert_wkb_to_geojson.rb
Created March 15, 2018 15:00
Convert WKB data from PostGIS to GeoJSON
result = ActiveRecord::Base.connection.execute("select * from my_shapes_table limit 1;")
shape = parser.parse result.values.first.last # .first row , .last column
RGeo::GeoJSON.encode(shape).to_json
# => "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[...]]]]}"