Skip to content

Instantly share code, notes, and snippets.

View ricardolsmendes's full-sized avatar

Ricardo Mendes ricardolsmendes

View GitHub Profile
@ricardolsmendes
ricardolsmendes / export-private-key-env-var.sh
Created December 7, 2022 19:11
Helpful shell commands to store a private key into an environment variable
# Get the private key from a JSON file using `jq`
# and store it into the `PRIVATE_KEY` environment variable:
export PRIVATE_KEY=$(jq -r '.private_key' service-account.json)
# Print a suitable value for GitHub secrets:
echo $PRIVATE_KEY
create or replace view finservam.prod.position (
symbol, exchange, date, trader, pm, num_shares_cumulative, cash_cumulative, close,
market_value, pnl comment 'Profit and Loss: Demonstrate comment on view column'
)
comment = 'what assets owned; demo Window Function running sum'
as
with cte as (
select t.symbol, exchange, t.date, trader, pm,
sum(num_shares) over(
partition by t.symbol, exchange, trader
@ricardolsmendes
ricardolsmendes / pyproject.toml
Last active December 18, 2022 06:38
pyproject.toml cheat sheet - initial version
[build-system]
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.8.0,<4"]
[project]
name = "pyproject-toml-cheat-sheet"
version = "1.0.0"
authors = [
{name = "Your Name", email = "you@yourdomain.com"},
]
@ricardolsmendes
ricardolsmendes / datacatalog-make-tag-template-sisense-dashboard.py
Created January 3, 2022 21:04
Make a Tag Template in Data Catalog to annotate Sisense Dashboard-related entries
def make_tag_template_for_dashboard(self) -> TagTemplate:
tag_template = datacatalog.TagTemplate()
tag_template.display_name = 'Sisense Dashboard Metadata'
add_field(tag_template, 'id', STRING, 'Id')
add_field(tag_template, 'owner_username', STRING, 'Owner username')
add_field(tag_template, 'owner_name', STRING, 'Owner name')
add_field(tag_template, 'folder_id', STRING, 'Folder Id')
add_field(tag_template, 'folder_name', STRING, 'Folder Name')
add_field(tag_template, 'folder_entry', STRING, 'Data Catalog Entry for the Folder')
@ricardolsmendes
ricardolsmendes / docker-dind.gitlab-ci.yaml
Created October 27, 2021 00:46
Docker dind setup for GitLab CI
image: docker:19.03.12
services:
- docker:19.03.12-dind
@ricardolsmendes
ricardolsmendes / docker-with-gcloud.gitlab-ci.yaml
Created October 27, 2021 00:42
GitLab CI step to test the Docker + Cloud SDK image
Test Docker with Cloud SDK image:
stage: test-custom-image
image: $CI_REGISTRY_IMAGE/docker-gcloud:latest
services:
- docker:19.03.12-dind
script:
- gcloud --version
- docker --version
- docker run hello-world
@ricardolsmendes
ricardolsmendes / docker-with-gcloud.Dockerfile
Last active October 26, 2021 22:10
Dockerfile for a Docker + Cloud SDK image
FROM docker:19.03.12
# --------------------------------------------------------------------------
# Install and configure gcloud.
# https://github.com/GoogleCloudPlatform/cloud-sdk-docker/blob/a1754f1ccfa47c4cc5bd218a592d7df1051aaad6/alpine/Dockerfile
# for reference.
# --------------------------------------------------------------------------
ARG CLOUD_SDK_VERSION=361.0.0
ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION
ENV PATH /google-cloud-sdk/bin:$PATH
@ricardolsmendes
ricardolsmendes / durable-functions-handle-exception.py
Last active April 18, 2021 04:58
Exception handling for Azure Durable Functions in Python
try:
# Orchestration code here...
except Exception as e:
# Any exception that is raised by a function is re-raised by its enclosing
# activity task. The original error message is part of the new exception
# message, formatted as "Activity function '<function_name>' failed:
# <exception_type>: <exception_message>", so a regex is used to extract the
# original message and generate a friendlier output.
function_name = None
function_exception_type = None
@ricardolsmendes
ricardolsmendes / durable-functions-chain.py
Last active April 18, 2021 01:25
Chaining Azure Functions with Durable Functions in Python
def orchestrator_function(context: df.DurableOrchestrationContext):
output = []
request_body = context.get_input()
data = yield context.call_activity('get-funds-transfer-data', request_body)
output.append('Get funds transfer data: DONE')
yield context.call_activity('validate-input', data)
output.append('Validate input: DONE')
@ricardolsmendes
ricardolsmendes / durable-functions-raise-exception.py
Last active April 18, 2021 01:04
Raising exceptions with Azure Durable Functions in Python
def main(data: Dict[str, Any]) -> Dict[str, Any]:
if not data:
raise Exception('The funds transfer data is mandatory')
if not data.get('sourceAccount'):
raise Exception('The Source Account is mandatory')
if not data.get('targetAccount'):
raise Exception('The Target Account is mandatory')