Skip to content

Instantly share code, notes, and snippets.

View Hugoberry's full-sized avatar

Igor Cotruta Hugoberry

View GitHub Profile
@Hugoberry
Hugoberry / tsql_impact_lineage.py
Created October 7, 2024 19:08
Use `sqlfluff` to build a lineage tree in D2
import os
from typing import Any, Dict, Iterator, Union, List, Tuple
import sqlfluff
# Parses the given SQL file and returns the parsing result
def parse_sql_file(file_path: str) -> Dict[str, Any]:
try:
with open(file_path, 'r', encoding='utf-8-sig') as file:
sql_content = file.read()
parsed = sqlfluff.parse(sql_content, dialect="tsql")
@Hugoberry
Hugoberry / description.md
Created May 29, 2024 22:00 — forked from braden-w/description.md
Google Sheets Script for Fetching Data from Supabase

Google Sheets Script for Fetching Data from Supabase

This Google Sheets script fetches data from a Supabase database and writes the selected headers and data to the active sheet. The script first clears the sheet, writes the headers, then fetches the data from the Supabase API, and finally writes the data to the sheet. It is optimized and has anonymized variables for public use.

How to Use

  1. Create a new Google Sheet or open an existing one.
  2. Click on "Extensions" in the menu, then select "Apps Script." (If you don't see "Extensions," click on "Tools" and then "Script editor.")
  3. In the Apps Script editor, replace the default Code.gs content with the content of supabase_to_google_sheets.gs.
  4. Replace the SUPABASE_URL and SUPABASE_ANON_KEY variables with your actual Supabase URL and anon key.
@Hugoberry
Hugoberry / duckdb-RAG.py
Last active March 6, 2024 11:03
Bare-bones implementation of similarity search in DuckDB using Expression API
import duckdb
from duckdb import (
ConstantExpression,
ColumnExpression,
FunctionExpression,
StarExpression
)
conn = duckdb.connect(database='embed.ddb')
text="Wooden floor"
@Hugoberry
Hugoberry / KMeansClustering.dax
Created January 18, 2024 12:56
A worked example of using the undocumented DAX function KMeansClustering
evaluate
var sample =
{
("L", 5),
("N", 5),
("P", 7),
("E", 9),
("U", 11),
("Y", 11),
("V", 29),
@Hugoberry
Hugoberry / customEdge.html
Created January 17, 2024 09:22 — forked from davidjgraph/customEdge.html
Custom edge example for mxGraph
<!--
$Id: markers.html,v 1.4 2013/10/28 08:44:55 gaudenz Exp $
Copyright (c) 2006-2014, JGraph Ltd
Demonstrates creating a custom edge in mxGraph
-->
<html>
<head>
<title>Custom edge example for mxGraph</title>
// Function to wrangle data into the required format
function wrangle(data) {
let charactersMap = {};
// Helper function to get characters by ID
function characterById(id) {
if (!charactersMap[id]) {
charactersMap[id] = data.characters.find(character => character.id === id);
}
return charactersMap[id];
<head>
<script type="text/javascript">
mxBasePath = 'https://jgraph.github.io/mxgraph/javascript/src';
</script>
<script type="text/javascript" src="https://jgraph.github.io/mxgraph/javascript/src/js/mxClient.js"></script>
<script type="text/javascript">
function wrangle(data) {
var charactersMap = {};
return data.scenes.map(function(scene) {
return {
let
Source = {"B", "F", "T"},
n = List.Count(Source),
combinations = Number.Power(2,n)-1,
CreateCombination = (mask as number) as list =>
List.Select(List.Transform(List.Positions(Source), (position) =>
if Number.BitwiseAnd(mask, Number.Power(2, position)) <> 0 then Source{position} else null),
each _ <> null),
@Hugoberry
Hugoberry / ABF_tabular_file_types.md
Last active September 6, 2023 15:20
ABF structure of files located under a datamodel file in PBIX. #PowerBI #tabular

{Table} ({TableID}).tbl folders contains the following

  • #.{Table} ({TableID}).Column ({ColumnID}).dictionary file for all the HASH encoded columns
  • #.H${Table} ({TableID})${Column} ({ColumnID}).hidx hash index files for all the VALUE encoded columns
  • {PartitionID}.prt partition folder with:
    • #.{Table} ({TableID).{Column} ({ColumnID}).0.idf column data storage file
    • #.{Table} ({TableID).{Column} ({ColumnID}).0.idfmeta column data storage metadata file

H${Table} ({TableID})${Column} ({ColumnID})$({SystemTableID}).tbl hierarchy folders

  • {PartitionID}.prt
  • #.H${Table} ({TableID})$Column ({ColumnID}).{ID_TO_POS|POS_TO_ID}.0.idf Column Hierarchy Position–to–Identifier or Identifier–to–PositionFile
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"$id": {
"type": "string"
},
"DaxModelVersion": {
"type": "string"
},