Skip to content

Instantly share code, notes, and snippets.

const data1 = {
attributes: {
domain: 'from.attributes.com'
}
}
const data2 = {
attributes: {
unknownAttributes: {
domain: 'from.unknownAttributes.com'
@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
@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
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 / search.sh
Created November 21, 2018 16:52
Search all files in give directory
#! /bin/sh -
# that also works in any sh, so you don't even need to have or use bash
file_pattern="/Users/ondrej/Downloads/emails/*.dms"
# all uppercase variables should be reserved for environment variables
IFS='' # disable splitting
for f in $file_pattern # here we're not quoting the variable so
# we're invoking the split+glob operator.
@ondrej-kvasnovsky
ondrej-kvasnovsky / update.sh
Created December 28, 2018 17:23
Pull latest changes from all git repositories in a directory and call npm install for each project
#!/bin/bash
CUR_DIR=$(pwd)
echo "\n\033[1mPulling in latest changes for all repositories in $CUR_DIR directory\033[0m\n"
for i in $(find . -name ".git" | cut -c 3-); do
echo "";
echo "\033[33m"+$i+"\033[0m";
cd "$i";
@ondrej-kvasnovsky
ondrej-kvasnovsky / structjson.js
Created January 24, 2019 12:11
Struct to JSON in JavaScript
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ondrej-kvasnovsky
ondrej-kvasnovsky / gist:10213c32a50c2bcf8d6a3612adc0524e
Created November 26, 2019 02:47
How to test successful promise and rejected when a promis fails (async await)
async function doSomething() {
return 'some result'
}
async function doSomethingAndFail() {
throw new Error()
}
describe('promise testing', () => {
@ondrej-kvasnovsky
ondrej-kvasnovsky / encrypt.py
Created February 18, 2020 00:03
Encrypt string using NaCl in Python
import base64
payload = 'VKlNGb4mCR/5BBunW4d7jpwp/KI1pRcsW/DeuMzXThh+nz8HRMI54bmWLKjC3haJuBGZQmX/SfNIACU='
payloadEncoded = payload.encode("UTF-8")
payloadArray = base64.b64decode(payload)
nonceArray = payloadArray[0:24]
msgArray = payloadArray[24:len(payloadArray)]
from nacl.secret import SecretBox
@ondrej-kvasnovsky
ondrej-kvasnovsky / groups.js
Created July 7, 2020 20:14
JavaScript get Regex groups
const input = 'hi:ha:ho';
const matches = input.match(/(.*):(.*):(.*)/);
const firstGroup = matches[1];
const secondGroup = matches[2];
const thirdGroup = matches[3];
console.log(firstGroup, secondGroup, thirdGroup);
// prints out: hi ha ho