Skip to content

Instantly share code, notes, and snippets.

@xlazex
xlazex / json.stringify.js
Last active March 26, 2019 08:28
JSON.stringify for object comparsion
/**
*
* The Example of using custom replacer function for JSON.stringify:
*
* 1. Imagine, You have to store some amount of UNIQUE Objects in a Map or an Array. [or just compare two objects].
* Stringified object (or some hash function applied to) could be used as a key to store Object.
* 2. The order of Elements Inside Object or Array (FOR THIS PARTICULAR CASE) does not matter. E.g: [1,3,2] equals [1,2,3].
*
*/
@xlazex
xlazex / postgres_queries_and_commands.sql
Created November 28, 2018 15:18 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@xlazex
xlazex / Postgres Index Usage.sql
Created November 16, 2018 13:07 — forked from next2you/Postgres Index Usage.sql
Postgres: Determine table/index size
SELECT idx.relname as table,
idx.indexrelname as index,
pg_relation_size( idx.indexrelname::text )/1024/1024 as bytes,
cls.relpages as pages,
cls.reltuples as tuples,
idx.idx_scan as scanned,
idx.idx_tup_read as read,
idx.idx_tup_fetch as fetched
FROM pg_stat_user_indexes idx,
pg_class cls ,
@xlazex
xlazex / string-to-capitalized-case.js
Last active September 1, 2018 08:40 — forked from jacks0n/string-to-pascal-case.js
Convert a string in JavaScript to Capitalized Case
/**
* Convert a string to Capitalized Case.
*
* @example
* 'hello_world'.toCapitalizedCase() // Will return `Hello World`.
* 'fOO BAR'.toCapitalizedCase() // Will return `Foo Bar`.
* 'asdsaads sadasd "2123asd-asd-as"'.toPascalLikeCase() // Will return `Asdsaads Sadasd "2123asd-Asd-As"`
*
* @returns {string}
* The Pascal-like Cased string.
@xlazex
xlazex / Promise.allRecursive.js
Last active November 4, 2022 15:46 — forked from voxpelli/main.js
A recursive Promise.all() that works both on arrays and objects (with nested arrays too)
/**
*
* Universal recursive Promise.all for Arrays and Objects
*
*
* Example Inputs:
* {
* test1: 1,
* test2: someAsyncFunctionReturnsArray(),
@xlazex
xlazex / ChildComponent.vue
Last active May 12, 2018 18:05 — forked from sproogen/ChildComponent.vue
Vee Validate - Child Component Example
<template>
<div>
<input v-validate data-rules="required" :class="{'has-error': errors.has("textInput")}" id="textInput" name="textInput" type="text">
<span class="error" v-show="errors.has("textInput")">{{ errors.first("textInput") }}</span>
</div>
</template>
<script>
import { find, propEq } from 'ramda'
import bus from './bus'