Skip to content

Instantly share code, notes, and snippets.

View stevehenderson's full-sized avatar

Steve Henderson stevehenderson

View GitHub Profile
@stevehenderson
stevehenderson / collab_presto.py
Created July 29, 2022 12:14
Collab and Presto
# First run this in top cell: pip install pyhive
from pandas import read_sql
from pyhive import presto
presto_conn = presto.Connection(host="collab-cluster-hostname-m", schema="your_presto_schema", catalog="presto_catalog", port=8060, username ="presto")
presto_cursor = presto_conn.cursor()
# Query presto node
query = "select * FROM system.runtime.nodes"
query_result = read_sql(query, presto_conn)
@stevehenderson
stevehenderson / pg_graphql_150.patch
Created July 29, 2022 00:45
Patch pg-graphql 30 row limit (pg_graphql--0.3.3.sql)
diff --git a/pg_graphql--0.3.3.sql b/pg_graphql--0.3.3.sql
index 1c7e735..c35ca13 100644
--- a/pg_graphql--0.3.3.sql
+++ b/pg_graphql--0.3.3.sql
@@ -3226,19 +3226,19 @@ begin
order by
%s
limit
- least(%s, 30) + 1
+ least(%s, 150) + 1
@stevehenderson
stevehenderson / gist:35372794c838572e634a71790f05d515
Last active August 21, 2022 03:55
Cascade drop all tables in a SQL/PostgreSQL schema
-- You will need to remove some quotation marks
select 'drop table if exists "schema_name"."' || tablename || '" cascade;'
from pg_tables
where schemaname = 'schema_name';
@stevehenderson
stevehenderson / get_usage.sql
Created June 8, 2022 21:17
PostgreSQL get usage
WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
(select inhrelid, inhparent
FROM pg_inherits
UNION
SELECT child.inhrelid, parent.inhparent
FROM pg_inherit child, pg_inherits parent
WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
, TABLE_NAME
@stevehenderson
stevehenderson / cloudbuild_debugging.yaml
Created May 7, 2022 18:52
Google CloudBuild folder location debugging
# Add the following step to kick some helpful debugging about what's in your google cloud build container!
- id: "Read Values"
name: ubuntu
dir: '/workspace'
entrypoint: bash
args:
- -c
- |
# Read from "/workspace"
echo "Where am I " $(pwd)
@stevehenderson
stevehenderson / hostToIP.go
Created April 23, 2022 14:48
Replace K8s namespace with IP
//
// Looks up a host using the resolver and returns an IP.
// Utility function for testing against K8s over VPN.
// Resolver should be the POD ip of kube-dns
//
func hostToIP(host string, resolver string) string {
fmt.Printf("Looking up %s using resolver %s\n", host, resolver)
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
@stevehenderson
stevehenderson / install_elastic.sh
Created March 25, 2022 03:03
Install Elasticsearch Ubuntu 20
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt update
sudo apt install elasticsearch
@stevehenderson
stevehenderson / uptime_bot_heartbeat.py
Last active March 22, 2022 03:36
UptimeBot Heartbeat Script
import requests
import time
def contact_monitor():
print("Calling the monitor...")
r= requests.get("https://heartbeat.uptimerobot.com/m11111111-11111111111111111111111111")
while 1==1:
time.sleep(30)
try:
@stevehenderson
stevehenderson / StatefuleSetGetAll.go
Created March 18, 2022 14:37
Get K8s StatefulSet
import (
appsv1 "k8s.io/api/apps/v1"
)
// StatefulSetGetAll returns all STS for the managed cluster
func (mgr *manager) StatefulSetGetAll() *appsv1.StatefulSetList {
stslister, err := mgr.k8sclient.AppsV1().StatefulSets("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
fmt.Println("error getting StatefulSetGetAll: ", err)
}
@stevehenderson
stevehenderson / revprox.go
Created March 11, 2022 15:22 — forked from JalfResi/revprox.go
Simple reverse proxy in Go
package main
import(
"log"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {