Skip to content

Instantly share code, notes, and snippets.

View patricktrainer's full-sized avatar
💭
🪠

Patrick patricktrainer

💭
🪠
View GitHub Profile
@patricktrainer
patricktrainer / dagster_dbt_utils.py
Created May 30, 2025 20:15 — forked from Taytay/dagster_dbt_utils.py
Dagster dbt utilities
import json
from typing import AbstractSet, Any, Generator, Mapping, Sequence, ValuesView
import dagster as dg
from dagster import (
AssetCheckResult,
AssetExecutionContext,
AssetKey,
AssetMaterialization,
AssetObservation,
@patricktrainer
patricktrainer / select_from_api.sql
Created October 12, 2024 01:39
DuckDB query authenticated api endpoint
CREATE SECRET http (
TYPE HTTP,
EXTRA_HTTP_HEADERS MAP {
'Authorization': 'Bearer sk_test_VePHdqKTYQjKNInc7u56JBrQ'
}
);
select unnest(data) as customers
from read_json('https://api.stripe.com/v1/customers');
@patricktrainer
patricktrainer / get_data_size.sh
Created September 8, 2024 04:27
the actual size of the data in a directory, not the size on disk.
find . -type f -print0 | xargs -0 stat -f "%z" | awk '{b+=$1} END {
if (b > 1073741824) {
printf "%.2f GB\n", b/1073741824
} else if (b > 1048576) {
printf "%.2f MB\n", b/1048576
} else if (b > 1024) {
printf "%.2f KB\n", b/1024
} else {
printf "%d bytes\n", b
}

Mermaid on Github Examples

All of these diagrams are dynamically rendered during html display by Github, the images generated from text inside the Github-Flavored Markdown. None are static images. Mermaid support was released for Github on 2022-02-14

Pros & Cons:

  • Pro: You don't need to care about the layout.
  • Con: You cannot control the layout.

Notes:

  • Not all the features of Mermaid (in particular symbols B-->C[fa:fa-ban forbidden], hyperlink and tooltips) are supported by Github.
@patricktrainer
patricktrainer / gen_dbt_yml.sql
Created March 1, 2024 04:44
generate dbt schema.yml
with "columns" as (
select ' - name: ' || column_name || '\n description: '|| lower(column_name) || ' (data type '|| lower(DATA_TYPE) || ')'
as column_statement,
table_name
from information_schema.columns
where table_schema = 'TABLE_NAME'
order by 1
),
tables as (
@patricktrainer
patricktrainer / makeRss.sh
Created February 24, 2024 21:54
Generate RSS
#!/bin/bash
# RSS feed header
echo '<?xml version="1.0" encoding="UTF-8" ?>' > blog.xml
echo '<rss version="2.0">' >> blog.xml
echo ' <channel>' >> blog.xml
echo ' <title>RSS feed title</title>' >> blog.xml
echo ' <link>https://example.com</link>' >> blog.xml
echo ' <description>Example RSS feed </description>' >> blog.xml
@patricktrainer
patricktrainer / learn.lua
Created October 29, 2023 04:39 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@patricktrainer
patricktrainer / GoogleDorking.md
Created July 3, 2023 21:53 — forked from sundowndev/GoogleDorking.md
Google dork cheatsheet

Google dork cheatsheet

Search filters

Filter Description Example
allintext Searches for occurrences of all the keywords given. allintext:"keyword"
intext Searches for the occurrences of keywords all at once or one at a time. intext:"keyword"
inurl Searches for a URL matching one of the keywords. inurl:"keyword"
allinurl Searches for a URL matching all the keywords in the query. allinurl:"keyword"
intitle Searches for occurrences of keywords in title all or one. intitle:"keyword"
@patricktrainer
patricktrainer / median_calculator.py
Created June 15, 2023 04:01
Calculate the median given a stream of integers from stdin
import heapq
class MedianCalculator:
def __init__(self):
self.heaps = [], []
def add_num(self, num):
small, large = self.heaps
heapq.heappush(small, -heapq.heappushpop(large, num))
if len(large) < len(small):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.