Skip to content

Instantly share code, notes, and snippets.

View januszm's full-sized avatar

Janusz Mordarski januszm

View GitHub Profile
openapi: 3.0.1
info:
title: Webhooks API
version: '1.0'
description: API documentation for handling webhooks.
paths:
/api/webhooks/rently:
post:
summary: Handle Rently webhook events
description: Receives and processes webhook events from Rently.
@januszm
januszm / hash_array_to_csv.rb
Created March 19, 2024 21:37 — forked from christiangenco/hash_array_to_csv.rb
Ruby hash array to CSV
class Array
def to_csv(csv_filename="hash.csv")
require 'csv'
CSV.open(csv_filename, "wb") do |csv|
csv << first.keys # adds the attributes name on the first line
self.each do |hash|
csv << hash.values
end
end
end
```ruby
record = Model.where("data->'$.somearray[0].email' = ?", email).first
```
@januszm
januszm / mysql_table_size.sql
Created September 25, 2023 21:24
MySQL tables size
SELECT
TABLE_NAME AS `Table`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "mydatabase"
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
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;
SELECT
TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='Xxx';
#!/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
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 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
@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