Skip to content

Instantly share code, notes, and snippets.

View vkmagalhaes's full-sized avatar

Vinicius Magalhães vkmagalhaes

View GitHub Profile
{"lastUpload":"2020-06-11T16:44:59.232Z","extensionVersion":"v3.4.3"}
@vkmagalhaes
vkmagalhaes / postgres_queries_and_commands.sql
Created January 16, 2019 21:27 — 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%'
@vkmagalhaes
vkmagalhaes / set_vs_array.rb
Created March 7, 2018 17:19
Benchmarking processing string of ids using Array vs Set
require 'benchmark/ips' # gem install benchmark-ips
require 'set'
def process_array(param)
ids = []
param.split(',').each do |id|
id = id.strip.to_i
ids << id if id != 0 && !ids.include?(id)
end
ids
@vkmagalhaes
vkmagalhaes / read-access.sql
Created November 2, 2017 23:00 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@vkmagalhaes
vkmagalhaes / bash-cheatsheet.sh
Created January 24, 2017 20:36 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2015 Stefan Tatschner
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell