Skip to content

Instantly share code, notes, and snippets.

View horacioibrahim's full-sized avatar

Horacio Ibrahim horacioibrahim

View GitHub Profile
@horacioibrahim
horacioibrahim / _c_document.painless.java
Last active December 11, 2024 17:32
Normalizar documento de usuário em índices e nomes diferentes
if (doc.containsKey('event_name.keyword') && doc['event_name.keyword'].size() > 0) {
String eventName = doc['event_name.keyword'].value;
String apenasNumeros = "";
if (doc.containsKey('user_id.keyword') && doc['user_id.keyword'].size() > 0) {
String userId = doc['user_id.keyword'].value;
if (userId != null && !userId.isEmpty()) {
for (int i = 0; i < userId.length(); i++) {
char c = userId.charAt(i);
if (Character.isDigit(c)) {
@horacioibrahim
horacioibrahim / sql-elastic-sample.bash
Last active November 19, 2024 09:26
Consulta SQL no ELASTIC
POST /_sql?format=txt
{
"query": """
SELECT payload_parsed.externalId, COUNT(*) as ocurrences FROM "TABLE" // "TABLE*"
WHERE payload_parsed.type.keyword = 'MESSAGE_STATUS'
AND event_data.source.keyword = 'ZENVIA'
AND payload_parsed.channel.keyword = 'email'
AND payload_parsed.messageStatus.code.keyword = 'SENT'
AND inserted_date >= NOW() - INTERVAL 48 HOUR
GROUP BY payload_parsed.externalId HAVING COUNT(*) > 2
@horacioibrahim
horacioibrahim / jwt_token_document.java
Last active December 18, 2024 15:00
AgnosticData + Elastic Insights: JWT introspected
String token = null;
// Primeiro, verificar em params._source['utm_case']['token']
if (params._source.containsKey('utm_case') && params._source['utm_case'] != null) {
if (params._source['utm_case'].containsKey('token')) {
token = params._source['utm_case']['token'];
// Processar o JWT se o token for encontrado
int firstDot = token.indexOf(".");
@horacioibrahim
horacioibrahim / POST_Elastic_Click__Aceitar.json
Last active November 1, 2024 19:33
Get user_id from Click from Elastic "Aceitar"
// POST /events_new-dedicated-01_click/_search
{
"sort": [
{
"inserted_date": {
"order": "desc",
"format": "strict_date_optional_time",
"unmapped_type": "boolean"
}
}
@horacioibrahim
horacioibrahim / POST_Elastic_Click__Cancelar_protesto.json
Last active November 1, 2024 19:33
Get user_id from Click from Elastic "Cancelar protesta"
// POST /events_new-dedicated-01_click/_search
{
"sort": [
{
"inserted_date": {
"order": "desc",
"format": "strict_date_optional_time",
"unmapped_type": "boolean"
}
}
@horacioibrahim
horacioibrahim / POST_Elastic_Click__Detalhes.json
Last active November 1, 2024 19:33
Get user_id from Click from Elastic "Detalhes"
// POST /events_new-dedicated-01_click/_search
{
"sort": [
{
"inserted_date": {
"order": "desc",
"format": "strict_date_optional_time",
"unmapped_type": "boolean"
}
}
const fs = require('fs');
const axios = require('axios');
const { Parser } = require('json2csv');
// Função para "achatar" o JSON
function flattenObject(obj, prefix = '') {
return Object.keys(obj).reduce((acc, k) => {
const pre = prefix.length ? `${prefix}_${k}` : k;
if (typeof obj[k] === 'object' && obj[k] !== null && !Array.isArray(obj[k])) {
Object.assign(acc, flattenObject(obj[k], pre));
/* `googleAppScriptAutoBackup.js` creates copy of files
* when is opened. This script check if file already exists
* so creates the backup file.
*/
var prefixBackupName = "MyFileXYZ"; // we're gonna to use as MyFileXYZ-
var folderId = "hashFolderIdFoundInURL"; // backup folder: where file to be placed it
var principalFileId = "hashFileIdFoundInURL" // principal file that it'll be copied
var workDir = DriveApp.getFolderById(folderId);
var myGMT = "GMT-3:00"
@horacioibrahim
horacioibrahim / calendar2sheet.js
Last active September 13, 2021 14:12
App Script to get events from Calendar API and insert to Spreadsheet
// Reference: https://www.youtube.com/watch?v=YDhln3ukH7Y&t=3s
function getEvents() {
var calId = "yourcalendar@yourbusiness.com"; // this is a Google Calendar Id
var startDate = "9/1/2021 12:00 AM" // Month/Day/Year
var endDate = "9/13/2021 11:59 PM" // Month/Day/Year
var nameOfSheet = "getEventsSheet" // You must have Filename and Sheet names (your tabs inner doc)
// spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
@horacioibrahim
horacioibrahim / discovery_highlights
Last active August 1, 2020 17:26
Discovery highlights
to harness
increasingly
affordable
advancing
rapidly
significant costs
delays
constrain*
time
spent