Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@virtualsafety
virtualsafety / pg_get_table_sizes.sql
Created October 8, 2023 13:04 — forked from hatarist/pg_get_table_sizes.sql
PostgreSQL: get table size (data & index & toast)
SELECT
*,
pg_size_pretty(table_bytes) AS table,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(total_bytes) AS total
FROM (
SELECT
*, total_bytes - index_bytes - COALESCE(toast_bytes, 0) AS table_bytes
FROM (
SELECT
@virtualsafety
virtualsafety / Postgres.md
Created March 15, 2023 05:49 — forked from mjf/Postgres.md
Postgres

⚠️ WARNING
The ordering of listed projects or documents is random and has no connection to relevance or maturity levels!

Postgres

Extensions

Extension Description
pgaudit Postgres auditing extension
pg_auto_failover Postgres extension for failover without distributed consensus (by Citus Data)
@virtualsafety
virtualsafety / Binary Search Tree.cpp
Created August 14, 2022 09:13 — forked from harish-r/Binary Search Tree.cpp
Binary Search Tree Implementation in C++
/*
** Binary Search Tree implementation in C++
** Harish R
*/
#include<iostream>
using namespace std;
class BST {
struct node {
@virtualsafety
virtualsafety / stacktrace.cxx
Created August 12, 2022 15:01 — forked from fmela/stacktrace.cxx
A C++ function that produces a stack backtrace with demangled function & method names.
/*
* Copyright (c) 2009-2017, Farooq Mela
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
//**********************************************************************
//** Easy Example for describing the usage of function pointer in C **
//**********************************************************************
#include<stdio.h>
//A simple funtion which return its parameter.
int p(int x){ return x ;}
typedef int (*functionPointer)(int x) ;
typedef struct _Interface {
@virtualsafety
virtualsafety / queue.h
Created July 20, 2022 14:43 — forked from chergert/queue.h
A thread-safe blocking LIFO or FIFO queue with maximum backlog.
#include <limits.h>
#include <pthread.h>
#include <stdlib.h>
typedef struct _queue_t queue_t;
typedef struct _queue_node_t queue_node_t;
struct _queue_node_t
package main
import (
"errors"
"sync"
)
func test(i int) (int, error) {
if i > 2 {
return 0, errors.New("test error")
/**
* @author sjalipar
*/
object myMain {
def main(args: Array[String]): Unit = {
println("test - start")
import scala.concurrent.Future
import scala.util.Success
import scala.util.Failure
@virtualsafety
virtualsafety / statistics.sql
Created March 10, 2021 06:54 — forked from ruckus/statistics.sql
Postgres statistics queries
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
@virtualsafety
virtualsafety / tcp_flags.txt
Created December 27, 2020 02:14 — forked from tuxfight3r/tcp_flags.txt
tcpdump - reading tcp flags
##TCP FLAGS##
Unskilled Attackers Pester Real Security Folks
==============================================
TCPDUMP FLAGS
Unskilled = URG = (Not Displayed in Flag Field, Displayed elsewhere)
Attackers = ACK = (Not Displayed in Flag Field, Displayed elsewhere)
Pester = PSH = [P] (Push Data)
Real = RST = [R] (Reset Connection)
Security = SYN = [S] (Start Connection)