Skip to content

Instantly share code, notes, and snippets.

View januszm's full-sized avatar

Janusz Mordarski januszm

View GitHub Profile
{
"data": [
{
"id": 6,
"banner_image": null,
"created_at": "2009-04-08 10:43:22 -0400",
"description": "Distance from front to back of the wall as seen from above. Also referred to as the height.\n\n![diagram](/images/diagrams/glossary/depth.combi.en.png)",
"description_de": "Das ist der Abstand von der Vorderseite bis zu der Hinterseite der Wand, von oben gesehen. Also, auch Höhe genannt.\n\n![Diagramm](/images/diagrams/glossary/depth.combi.de.png)",
"description_es": "La distancia desde la parte delantera hasta la parte trasera del muro, visto desde arriba. También se le refiere como la altura.\n\n![diagram](/images/diagrams/glossary/depth.combi.en.png)\n\n\n",
"description_fr": "Distance de l'avant vers l'arrière du mur vue de dessus. Également appelée hauteur.\n\n![diagramme](/images/diagrams/glossary/depth.combi.en.png)",
@januszm
januszm / rails_model_to_csv_and_back.rb
Last active January 13, 2025 15:40
Rails Model to CSV and back
require "csv"
headers = %w[identifier address other]
model = Model
CSV.open("model_export.csv", "wb") do |csv|
csv << headers
model.select(*headers).find_each do |row|
csv << row.attributes.except("id").values
end
end
@januszm
januszm / change_eb_ruby_version.sh
Last active January 6, 2025 15:46
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_PROFILE=profile_from_credentials_file AWS_REGION=us-east-2 aws elasticbeanstalk update-environment \
--platform-arn "arn:aws:elasticbeanstalk:us-east-2::platform/Ruby 3.3 running on 64bit Amazon Linux 2023/4.3.0" \
--environment-name "myappenv1" --region us-east-2 \
--version-label "app-1234-210000_120123"
# older awscli using --solution-stack-name
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;
@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]
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';