Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@virtualsafety
virtualsafety / blocked.sql
Created December 4, 2020 06:50 — forked from chmarr/blocked.sql
PostgreSQL query to display blocked and blocking queries. Updated from PG Wiki.
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
now() - blocked_activity.query_start
AS blocked_duration,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
now() - blocking_activity.query_start
AS blocking_duration,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS blocking_statement
@virtualsafety
virtualsafety / read-access.sql
Created October 22, 2020 07:52 — 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;
@virtualsafety
virtualsafety / gist:574dc62bbdeee46bb3f431a20dfc2f33
Created October 9, 2020 06:21 — forked from jpetitcolas/gist:5967887
Encode/decode a base64 encoded string in PostGreSQL
-- Decoding
SELECT CONVERT_FROM(DECODE(field, 'BASE64'), 'UTF-8') FROM table;
-- Encoding
SELECT ENCODE(CONVERT_TO(field, 'UTF-8'), 'base64') FROM table;
@virtualsafety
virtualsafety / psql_useful_stat_queries.sql
Created September 17, 2020 04:40 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
package main
import (
"io/ioutil"
"log"
"strings"
)
func main() {
input, err := ioutil.ReadFile("myfile")
@virtualsafety
virtualsafety / aes_encryption.go
Created June 26, 2020 02:01 — forked from stupidbodo/aes_encryption.go
AES Encryption Example in Golang
// Playbook - http://play.golang.org/p/3wFl4lacjX
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
@virtualsafety
virtualsafety / KotlinReflection.kt
Created September 17, 2019 14:48 — forked from DavidSanf0rd/KotlinReflection.kt
Using kotlin reflection to get the name, type and values of any class properties
import kotlin.reflect.full.declaredMemberProperties
/**
* Created by sanf0rd on 19/06/17.
*/
fun readProperties(instance: Any) {
val clazz = instance.javaClass.kotlin
clazz.declaredMemberProperties.forEach {
println("${it.name} --[${it.returnType}]---> ${it.get(instance)}")
@virtualsafety
virtualsafety / cx_oracle.md
Created April 29, 2019 16:02 — forked from kimus/cx_oracle.md
Installing python cx_oracle on Ubuntu

First of all, it just seems like doing anything with Oracle is obnoxiously painful for no good reason. It's the nature of the beast I suppose. cx_oracle is a python module that allows you to connect to an Oracle Database and issue queries, inserts, updates..usual jazz.

Linux

Step 1:

sudo apt-get install build-essential unzip python-dev libaio-dev

Step 2. Click here to download the appropriate zip files required for this. You'll need:

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
fun main(args: Array<String>) {
val jsonString : String = """
{
"authors" : [
{
"name" : "Kalle Jönsson",
@virtualsafety
virtualsafety / elasticsearch.md
Created November 21, 2017 08:12 — forked from kkc/elasticsearch.md
Elasticsearch performance tuning

##TUNING##

Configuration

System: set file descriptors to 32K or 64K

vim /etc/security/limit.conf