Skip to content

Instantly share code, notes, and snippets.

@belsrc
belsrc / gist:451921b27eadfa4479e1
Last active December 6, 2019 00:36
touch command in Powershell
# Type 'notepad $profile' to open your profile ps1 file and add
# This will add the file if it doesn't exist or update the
# last write time if it does
# If you get some message about not being able to run scripts then you need to type the following command and restart powershell
# Set-ExecutionPolicy Bypass
Function touch {
$file = $args[0]
if($file -eq $null) {
const isString = value => typeof value === 'string' || value instanceof String;
/*
camelCase('camel case'); // camelCase
camelCase('camel_case'); // camelCase
camelCase('camel-case'); // camelCase
*/
const camelCase = str => {
if(!isString(str)) {
return '';
@belsrc
belsrc / app.vue
Created February 20, 2017 13:16
Vue 2 Event Bus
<template>
</template>
<script>
import { mapState, mapGetters, mapActions } from 'vuex';
import * as types from './../store/action_types';
export default {
components: { },
@belsrc
belsrc / gist:8623ba3da74f855ac13b32ee2941b1de
Last active May 24, 2017 15:47
Mongo Unique Created At Days
db.getCollection('collection').aggregate([
{ $match: { $and: [
{ created_at: { $exists: true } },
{ created_at: { $ne: null } }
] } },
{ $project: {
month: { $month: "$created_at" },
year: { $year: "$created_at" },
day: { $dayOfMonth: "$created_at" } } },
{ $group: { _id: { "year": "$year", "month": "$month", "day": "$day" } } },
@belsrc
belsrc / performance_check.js
Last active December 5, 2016 14:01
Check Mongo query performance
/*
db.setProfilingLevel(2) Needs to be ran first
0 - Off
1 - Only slow
2 - all
This enables query profiling, after enabling profiling, run the application for a bit to get some data.
*/
db.getCollection('system.profile')
.find({
@belsrc
belsrc / gist:4132373
Created November 22, 2012 17:55
Apple Touch Icon Links - HTML
<!-- From Mathias Bynens' blog post 'Everything you always wanted to know about touch icons' (http://mathiasbynens.be/notes/touch-icons) -->
<!-- For third-generation iPad with high-resolution Retina display: -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144-precomposed.png">
<!-- For iPhone with high-resolution Retina display: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<!-- For first- and second-generation iPad: -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
-- Line 9 equals indexes
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind = 'i'
AND nspname !~ '^pg_toast'
-- Line 9 ignores indexes
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind != 'i'
AND nspname !~ '^pg_toast'
@belsrc
belsrc / postgres_relation_size.sql
Last active January 12, 2016 15:47
Show relation size in Postgres
-- Relations, as in, tables and indexes
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_relation_size(PC.oid)) AS "size"
FROM pg_class PC
LEFT JOIN pg_namespace NS ON (NS.oid = PC.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND nspname !~ '^pg_toast'
ORDER BY pg_relation_size(PC.oid) DESC
@belsrc
belsrc / postgres_database_size.sql
Created January 12, 2016 15:43
Size of databases in cluster (Postgres)
SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS SIZE
FROM pg_catalog.pg_database d
ORDER BY
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_database_size(d.datname)
ELSE NULL