Skip to content

Instantly share code, notes, and snippets.

@lucasassisrosa
lucasassisrosa / strapi-content-api.ts
Last active January 18, 2025 21:34 — forked from Convly/strapi-content-api.ts
dynamic content API response types for Strapi v5
/**
* Snippet from https://gist.github.com/Convly/6cf1e6d143bb0a90c8de2242fdedda8e
* Ref: https://docs.strapi.io/dev-docs/typescript/development#generate-typings-for-content-types-schemas
*/
import type { Schema, Utils, UID } from "@strapi/types";
import type { Schema, Utils, UID } from '@strapi/types';
// https://github.com/microsoft/TypeScript/issues/50122
@lucasassisrosa
lucasassisrosa / consul_hosts_in_all_dcs.sh
Last active July 12, 2024 22:09
Obtain all hosts in all datacenters for a given service in Consul
# https://developer.hashicorp.com/consul/api-docs/catalog#list-datacenters
# https://developer.hashicorp.com/consul/api-docs/health#list-service-instances-for-service
# requires jq: https://jqlang.github.io/jq/
SERVICE=
CONSUL_HOST=
for DC in `curl -s "https://$CONSUL_HOST/v1/catalog/datacenters" | jq '.[]' | sed -e 's/"//g'`; do curl -s "https://$CONSUL_HOST/v1/health/service/$SERVICE?dc=$DC" | jq '.[] | "\(.Node.Node) \(.Service.ID)"' | sed -e 's/"//g'; done
@lucasassisrosa
lucasassisrosa / telnyx_texml_bin.xml
Created June 11, 2024 00:06
Telnyx TeXML Bin for Outbound Call with AI Assistance
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect>
<AIAssistant id="assistant-uuid">
<Greeting>Hi how can I help you today?</Greeting>
<Voice provider="telnyx">
<Telnyx voice_id="0" model_id="LibriTTS" phonemizer="gruut" voice_speed="1.333" diffusion_steps="5"/>
</Voice>
</AIAssistant>
</Connect>
@lucasassisrosa
lucasassisrosa / setup-env.sh
Created April 15, 2024 12:10
Read environment variables from .env file and export
if [ -f .env ]; then
export $(cat .env | xargs)
export CMS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "✅ Loaded envs"
else
echo ".env file Not Found"
fi
@lucasassisrosa
lucasassisrosa / threeDModelToPng.js
Last active March 18, 2024 22:06
Convert 3D model in three-js scene to png image -- saving the animation frames using `canvas.toBlob`
//
/**
* On browser load
* if using https://github.com/vasturiano/globe.gl#globe-layer
* call inside `animate()` function or `onGlobeReady`, or a react wrapper `onLoad` callback
*/
// after globe is loaded and animation started
const canvasElement = document.querySelector(
`canvas#canvas-id`
@lucasassisrosa
lucasassisrosa / rename_files_ext_perl.sh
Last active January 19, 2024 12:07
Rename folder all files extensions
# transform all files to .md, including nested. Use -n to preview changes
rename -p -e 's/(\/.*)\.php/$1\.md/' **/*.php
rename -p -e 's/(\/.*)\.py/$1\.md/' **/*.py
rename -p -e 's/(\/.*)\.rb/$1\.md/' **/*.rb
rename -p -e 's/(\/.*)\.java/$1\.md/' **/*.java
rename -p -e 's/(\/.*)\.cs/$1\.md/' **/*.cs
# It outputs something like "'php/outbound_voice_profiles/outbound_voice_profiles/get.php' would be renamed to 'php/outbound_voice_profiles/outbound_voice_profiles/get.md'"
@lucasassisrosa
lucasassisrosa / international_pricing_pages_check.js
Last active June 21, 2023 14:21
Telnyx Elastic SIP International Pricing pages fetch all
// check all pricing pages built locally at the same time to stress test rate limiting
// run this script with node >= 18.x
Promise.allSettled(
[
"http://127.0.0.1:3000/pricing/elastic-sip/al",
"http://127.0.0.1:3000/pricing/elastic-sip/am",
"http://127.0.0.1:3000/pricing/elastic-sip/ao",
"http://127.0.0.1:3000/pricing/elastic-sip/ar",
"http://127.0.0.1:3000/pricing/elastic-sip/at",
"http://127.0.0.1:3000/pricing/elastic-sip/au",
@lucasassisrosa
lucasassisrosa / gpg-setup.sh
Last active October 17, 2022 13:59
GPG Setup + Pinentry - MacOS
# set git global config to always sign commits
$ git config --global gpg.program gpg
$ git config --global commit.gpgsign true
# pinentry to read gpg passphrase from git user.signingKey
$ brew install pinentry-mac
# set pinentry-mac as the default program
$ echo "pinentry-program $(which pinentry-mac)" > ~/.gnupg/gpg-agent.conf
@lucasassisrosa
lucasassisrosa / server.js
Last active September 28, 2022 21:54
Node.js plain simple Server
const http = require('http');
const fs = require('fs');
const requestListener = function (req, res) {
req.on('error', (err) => {
console.error(err);
res.statusCode = 400;
res.end('400: Bad Request');
return;
});
@lucasassisrosa
lucasassisrosa / updateContentfulEntryFields.js
Created August 16, 2022 22:48
CMS Content Batch Update using Contentful Management API - Update target entries "Reference" Field to "Short Text" Field
const contentful = require('contentful-management');
const REFERENCE_FIELD = 'topic_ref';
const SHORT_TEXT_FIELD = 'topic';
const client = contentful.createClient({
accessToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN,
});
client