Skip to content

Instantly share code, notes, and snippets.

View ardiesaeidi's full-sized avatar

Ardalan Saeidi ardiesaeidi

View GitHub Profile
@ardiesaeidi
ardiesaeidi / pg_table_size.sql
Created August 27, 2020 16:54
postgres get table size
-- https://wiki.postgresql.org/wiki/Disk_Usage
-- get size of table
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS index
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS table
FROM (
SELECT *, total_bytes-index_bytes-coalesce(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS table_name
@ardiesaeidi
ardiesaeidi / fetch.js
Created August 17, 2020 16:44
using fetch api to make clientside requests
fetch('/api/v1/clients', {
method: 'post',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'x-csrf-token': 'bJYS4JDu-mmYxfO4Vrnqb8vruIC8Hh-uAvzk'
},
body: JSON.stringify({ "name": "test" })
}).then(function(res) {
res.json().then(function(data) {
@ardiesaeidi
ardiesaeidi / aws_ec2_wait.sh
Created April 28, 2020 21:58 — forked from sgnn7/aws_ec2_wait.sh
Wait for AWS EC2 snapshot or volume for longer than 20 mins
#!/bin/bash -e
EC2_REGION="us-west-1"
DEFAULT_PROGRESS_WAIT=5
# ========== SNAPSHOT WAIT ==============
snapshot_id="snap-testtesttest"
while [ "$snapshot_progress" != "100%" ]; do
sleep "$DEFAULT_PROGRESS_WAIT"
@ardiesaeidi
ardiesaeidi / logger.js
Created April 18, 2020 06:17 — forked from xeoncross/logger.js
Expressjs Server Monitoring with Winston + Morgan
const { createLogger, format, transports } = require("winston");
// https://github.com/winstonjs/winston#logging
// { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
const level = process.env.LOG_LEVEL || "debug";
function formatParams(info) {
const { timestamp, level, message, ...args } = info;
const ts = timestamp.slice(0, 19).replace("T", " ");
@ardiesaeidi
ardiesaeidi / 2019-https-localhost.md
Created March 19, 2020 07:16 — forked from cecilemuller/2019-https-localhost.md
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@ardiesaeidi
ardiesaeidi / update_jsonb.sql
Created December 4, 2019 18:05
Updates a specific jsonb property
-- https://www.db-fiddle.com/f/e8aeGk7cRNYnpjsqi1ncrs/24
create table tenants (id int, identities jsonb);
insert into tenants (id, identities) values (
1,
'[
{
"source": "my.edgecast.com",
"external_id": "77"
@ardiesaeidi
ardiesaeidi / jq_update.sh
Created November 27, 2019 02:16
Update json file using jq in bash shell
#!/bin/sh
updateAllowedHosts() {
if [ -n "$ECS_CONTAINER_METADATA_FILE" ]; then
echo "getting ecs container metadata file '$ECS_CONTAINER_METADATA_FILE'"
local appSettings='appsettings.json'
local currentHosts=
# check if env appsettings exist
@ardiesaeidi
ardiesaeidi / aws-ec2-redis-cli.md
Created April 18, 2019 07:59 — forked from paladini/aws-ec2-redis-cli.md
AWS redis-cli without redis server on AWS EC2

Setup redis-cli without the whole Redis Server on AWS EC2

This fast tutorial will teach you how to install redis-clion AWS EC2 without having to install the whole Redis Server. Firstly, SSH into your EC2 instance and run the following command:

$ sudo yum install gcc

This may return an "already installed" message, but that's OK. After that, just run:

$ wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make && sudo cp src/redis-cli /usr/local/bin/ && sudo chmod 755 /usr/local/bin/redis-cli

# create shell on running instance
docker exec -i -t container_name /bin/bash
#!/bin/sh
# certgen <days> <file_name>
if [ "$#" -ne 2 ]; then
echo "certgen <days> <file_name>"
exit 1
fi