Skip to content

Instantly share code, notes, and snippets.

Avatar

Janusz Mordarski januszm

View GitHub Profile
View sqlserver_show_defaults.sql
SELECT
TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='Xxx';
View mysqldump_restore.sh
#!/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
View non-mimetype.rb
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
@januszm
januszm / grafana_upgrade.sh
Last active Mar 19, 2021
Grafana upgrade
View grafana_upgrade.sh
# 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
@januszm
januszm / elasticsearch_on_linux.sh
Last active Mar 19, 2021
Elasticsearch on Amazon Linux
View elasticsearch_on_linux.sh
# 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 Mar 1, 2021
Run command as cron
View run_as_cron.sh
# 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 Feb 23, 2021
pipenv lock flamegraph
View pipenv_locking.svg
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 Feb 23, 2021 — forked from ytspar/install-python-ubuntu.sh
Install Python with Pyenv on Ubuntu (16.04)
View install-python-ubuntu.sh
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 Jul 25, 2022
Postgresql dump and load compressed
View pg_dump_restore.sh
sudo amazon-linux-extras install postgresql12
pg_dump -Fc -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 --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
@januszm
januszm / gist:e25cc9fd7a1ce97fa10e36720c7589e2
Created Aug 23, 2020
Print stacktrace without site-packages in debugger
View gist:e25cc9fd7a1ce97fa10e36720c7589e2
import traceback; [line for line in traceback.format_stack() if not 'site-packages' in line]