Skip to content

Instantly share code, notes, and snippets.

View januszm's full-sized avatar

Janusz Mordarski januszm

View GitHub Profile
@januszm
januszm / pipenv_locking.svg
Created February 23, 2021 19:09
pipenv lock flamegraph
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / grafana_upgrade.sh
Last active March 19, 2021 11:10
Grafana upgrade
# first, backup running config
docker exec -it -u 0 grafana bash
cat /etc/grafana/grafana.ini
# copy output and paste to backup file somewhere or use docker cp
docker cp grafana:/etc/grafana/grafana.ini grafana.ini.bak
docker pull grafana/grafana:latest
docker stop grafana
docker rm grafana
docker run --name grafana --detach=true --publish 80:3000 --link graphite:graphite --volumes-from grafana-storage grafana/grafana
rails_version = '6.1.3'
# Include rails specific gems
# We need this until https://github.com/rails/rails/issues/41750 is resolved
gem 'actioncable', rails_version
gem 'actionmailer', rails_version
gem 'actionpack', rails_version
gem 'actionview', rails_version
gem 'activejob', rails_version
gem 'activemodel', rails_version
gem 'activerecord', rails_version
#!/bin/bash
# -d for no data, just structure
# -t for no create, just data
# --ignore-table=name1 --ignore-table=name2
# --skip-comments
# include table names after DATABASE
mysqldump -u USER -h HOST -p DATABASE | gzip > DATABASE.sql.gz
# load
SELECT
TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='Xxx';
@januszm
januszm / change_eb_ruby_version.sh
Last active October 17, 2022 20:16
Change Ruby minor version in AWS Elastic Beanstalk
# Currently (2017/2018) it's not possible to change the Ruby 'minor' version (eg. 2.3 => 2.4) using the web console
# However, it's possible using the 'awscli' tool.
brew install awscli # pip install awscli
aws elasticbeanstalk update-environment \
--solution-stack-name "64bit Amazon Linux 2017.09 v2.6.1 running Ruby 2.4 (Puma)" \
--environment-name "myappenv1" --region "us-east-2" \
--version-label "app-1234-210000_120123"
# For Amazon Linux 2
DROP extension postgis CASCADE;
/*
drop cascades to column shape of table MYTABLE_points
drop cascades to column shape of table MYTABLE_areas
*/
/* Upgrade PostgreSQL */
CREATE extension postgis;
@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]