Skip to content

Instantly share code, notes, and snippets.

const fs = require('mz/fs');
const read = async() => {
const root = '/Users/testing-s3-2/'
let html = `<html><table style="width:100%" border="1">`
const folders = await fs.readdir(root);
for (const folder of folders) {
if (!fs.lstatSync(folder).isDirectory()) continue;
if (folder.startsWith('.') || folder.startsWith('node_modules')) continue;
html += '<tr>'
@ondrej-kvasnovsky
ondrej-kvasnovsky / reinstall-postgres.sh
Created November 8, 2018 20:28
Remove Postgres and start it in docker
brew doctor
brew update
brew services list
brew services stop postgres
brew uninstall postgres
rm -rf /usr/local/var/postgres
rm -rf /usr/local/opt/postgresql
rm -rf .psql_history .psqlrc .psql.local .pgpass .psqlrc.local
# then use docker to start local postgres to avoid all these issues with running postgres on your local
@ondrej-kvasnovsky
ondrej-kvasnovsky / debugging.sql
Last active November 1, 2018 18:49
Find out biggest databases and tables in Postgres
-- find biggest database
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
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
const data1 = {
attributes: {
domain: 'from.attributes.com'
}
}
const data2 = {
attributes: {
unknownAttributes: {
domain: 'from.unknownAttributes.com'
@ondrej-kvasnovsky
ondrej-kvasnovsky / index.js
Created April 17, 2018 18:27
snowflake udf to extract domain from json or url
const data1 = {
attributes: {
domain: 'from.attributes.com'
}
}
const data2 = {
attributes: {
unknownAttributes: {
domain: 'from.unknownAttributes.com'
@ondrej-kvasnovsky
ondrej-kvasnovsky / index.js
Created April 17, 2018 17:20
extract domain from json and url
const data1 = {
attributes: {
domain: 'from.attributes.com'
}
}
const data2 = {
attributes: {
unknownAttributes: {
domain: 'from.unknownAttributes.com'
# List existing mongo process
pgrep mongo
# Kill existing process if has.
pkill mongo
# Clear old folder if has.
rm -rf rs0 && rm -rf rs1 && rm -rf rs2
# Create log folder.
mkdir -p ./var/log/mongodb
# Create replica set 0
. rs.sh 0
#!/bin/bash
RS_INDEX=$1
RS_NAME="rs"$1
mkdir $RS_NAME
PORT=$((27017+$RS_INDEX))
cat <<EOF > $RS_NAME.conf
systemLog:
destination: file
path: "var/log/mongodb/mongod.log"
logAppend: true
@ondrej-kvasnovsky
ondrej-kvasnovsky / test.js
Created March 19, 2018 23:16
Mock AWS S3 in JavaScript using Mocha and Sinon
const SomeService = require('some/service')
const AWS = require('aws-sdk')
describe('someService', async function() {
let someService
beforeEach(async function() {
someService = new SomeService()
})
@ondrej-kvasnovsky
ondrej-kvasnovsky / myservice.tf
Last active March 5, 2018 22:14
Create Auto Scaling Group Policy - using Average Network Out metric type
resource "aws_autoscaling_policy" "myservice-asg-policy" {
name = "myservice-asg-policy"
policy_type = "TargetTrackingScaling"
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageNetworkOut"
}
target_value = 800000000
}
autoscaling_group_name = "${module.myservice.asg_name}"