Skip to content

Instantly share code, notes, and snippets.

View renatocron's full-sized avatar

Renato Santos renatocron

  • eokoe
  • Sao Paulo, Brazil
View GitHub Profile
@renatocron
renatocron / docs.md
Created December 11, 2024 00:50
Multiple Repository Deploy Key Generator for Github

Multiple Repository Deploy Key Generator

A shell script for managing GitHub repository-specific SSH keys

This tool helps system administrators and developers safely manage multiple GitHub repository access keys on a single machine. Perfect for CI/CD pipelines, deployment servers, and development environments requiring specific repository access controls.

Key Features

  • Generates unique SSH keys for individual GitHub repositories
  • Automatically configures SSH settings for repository separation
  • Prevents key conflicts when accessing multiple repositories
# app.pl
use Mojolicious::Lite -signatures;
use Mojo::Redis;
use Mojo::JSON qw(encode_json decode_json);
use Mojo::IOLoop;
# Initialize Redis with explicit connection handling
my $redis = Mojo::Redis->new('redis://127.0.0.1:6379');
$redis->on(error => sub ($redis, $error) {
app->log->error("Redis error: $error");
import * as fs from 'fs';
import * as path from 'path';
import * as crypto from 'crypto';
import { PrismaClient } from '@prisma/client';
import { Logger } from '@nestjs/common';
const prisma = new PrismaClient();
const logger = new Logger('PgsqlMigrate');
async function main() {

Pagination Strategies & Resources

  1. Offset-based Pagination: How it works: You request a specific number of records (limit) starting at a particular position (offset). Advantages: Simple to implement. Disadvantages: Performance: Can be slow for large offsets as the database needs to skip over many records. Data Inconsistency: New records added during pagination can lead to skipping or repeating data. Resources: REST API Design Guide: https://cloud.google.com/apis/design/design_patterns#list_pagination (Focuses on REST APIs but provides good general guidelines).
  2. Cursor-based Pagination:
generator client {
provider = "prisma-client-js"
previewFeatures = ["views", "relationJoins"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

Title: Batching requests and processing in parallel using NestJS

Hello, I have a use case where I want to batch incoming requests from multiple users in my NestJS application to reduce network usage, database queries, and optimize processing. Ideally, I'd like to store the requests and their response objects in an in-memory queue within the same process.

My requirements are:

  • Group incoming requests into a single transaction (e.g., 1000 requests within a second).
  • Perform batch operations in parallel to reduce the number of database queries.
  • Wait for a quorum to be reached for successful operations before sending responses.
  • Handle errors and timeouts without affecting other users' requests.
[druid-gl-brokers-0] 2022-06-09T01:22:09,157 WARN [sql[a8e73b73-b187-4046-9e57-485f16da18bc]] org.apache.druid.sql.http.SqlResource - Failed to handle query: SqlQuery{query='SELECT
[druid-gl-brokers-0] MAX("added") as last_added,
[druid-gl-brokers-0] case when cityName IN ('Abbotsford','Aglayan' ) then '-1' else 0 end as MyFavCitiesFirst
[druid-gl-brokers-0] FROM wikipedia
[druid-gl-brokers-0] WHERE
[druid-gl-brokers-0] __time >= CURRENT_TIMESTAMP - INTERVAL '7' YEAR
[druid-gl-brokers-0] AND
[druid-gl-brokers-0] (
[druid-gl-brokers-0] cityName IN ('Abbotsford', 'Aglayan')
[druid-gl-brokers-0] )
apiVersion: "druid.apache.org/v1alpha1"
kind: "Druid"
metadata:
name: druid-cluster
spec:
image: apache/druid:0.21.1
# Optionally specify image for all nodes. Can be specify on nodes also
# imagePullSecrets:
# - name: tutu
startScript: /druid.sh
@renatocron
renatocron / sample.pl
Created January 19, 2021 23:25
Send SMS Transactional using Amazon::SNS (perl)
use strict;
use Amazon::SNS;
use LWP::ConsoleLogger::Everywhere ();
my $message = 'test' . time;
my $phonenumber = '+55119000000';
$ENV{AWS_SNS_KEY} = 'xxxxx';
$ENV{AWS_SNS_SECRET} = 'yyy';
$ENV{AWS_SNS_ENDPOINT} = '';
SELECT
p.name,
c.id as cliente_id,
coalesce(cp.value, p.initial_value) as value
FROM preferences p
CROSS JOIN clientes c
LEFT JOIN clientes_preferences cp ON cp.cliente_id = c.id AND cp.preference_id = p.id
where c.id=180 and p.name='NOTIFY_COMMENTS_POSTS_CREATED';
/*