Skip to content

Instantly share code, notes, and snippets.

View HallexCosta's full-sized avatar
:octocat:
Learning on-demand!

Hállex da Silva Costa HallexCosta

:octocat:
Learning on-demand!
View GitHub Profile
@HallexCosta
HallexCosta / Pessimistic Lock with Atomicity: A Pragmatic Approach.md
Last active November 4, 2024 18:51
Pessimistic Lock with Atomicity: A Pragmatic Approach

Pessimistic Lock with Atomicity: A Pragmatic Approach

I want to remind you that this post does not follow a chronological order, in the future I may make two new posts, one about an optimistic lock in MongoDB and another about a comparison between the two locking models.

I will use the NoSQL database (MongoDB) together Node.js and Mongoose to explain how to work with a document lock

Enjoy reading! 😃

Summary

  • What is atomic?
  • Explain use case
@HallexCosta
HallexCosta / app.js
Last active September 4, 2024 21:05
Simple Dynamic Render List similiar to React Declarative Programming using Proxy Object in Vanilla.js
const list = document.getElementById('list')
const createCard = ({img: url, username}) => {
const div = document.createElement('div')
div.classList.add('card')
const img = document.createElement('img')
img.src = url
const span = document.createElement('span')
@HallexCosta
HallexCosta / README.md
Last active September 1, 2024 17:15
Rspack Configs for build react app from scratch (support js, jsx, ts and tsx)

Overiew

The @babel/preset-flow, animate.css, wow.js and http-server are depends not required.

Required dependencies

pnpm add -D babel-loader @babel/core @babel/preset-env @babel/preset-react @rspack/cli @rspack/core @rspack/dev-server @rspack/plugin-react-refresh react-refresh css-loader sass-loader style-loader react react-dom
@HallexCosta
HallexCosta / biome.json
Created September 1, 2024 07:42
BiomeJS configs
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
@HallexCosta
HallexCosta / App.js
Last active October 7, 2023 16:26
Awesome Timer
import React, { useState, useRef } from 'react';
import {
SafeAreaView,
StyleSheet,
Text,
View,
TouchableHighlight,
} from 'react-native';
@HallexCosta
HallexCosta / atalhos-ij.md
Created September 6, 2023 20:57 — forked from boaglio/atalhos-ij.md
Atalhos do IntelliJ - para quem veio do Eclipse

Atalhos do IntelliJ

Principais

Caiu no IntelliJ agora?

Aprenda só esses:

Tipo de Atalho IntelliJ IDEA
@HallexCosta
HallexCosta / problem.js
Created June 15, 2023 14:06
Simulando conflito entre timezones do EUA e BRASIL atráves de ordenação por data
const items = []
// simulate request add item using api
function api(id, date, country) {
const item = {
id,
date,
timestamp: Date.parse(date), // timestamp
country
}
items.push(item)
@HallexCosta
HallexCosta / CheckoutService.php
Last active May 8, 2023 23:43
CheckoutService.php
<?php
namespace app\modules\api\services\pagarme\orders;
class CheckoutService
{
private string $SECRET_API_KEY = '';
private array $headers;
public function __construct()
{
$username = $this->SECRET_API_KEY;
@HallexCosta
HallexCosta / gist:2490587b61a130c90f611ea942cf990e
Created April 25, 2023 17:54
Como ativar php7.4 no ec2 da amazon
https://linux.how2shout.com/how-to-install-php-7-4-on-amazon-linux-2/
@HallexCosta
HallexCosta / calculateHourlyRate.js
Created March 28, 2023 00:17
Calculate Hourly Rate
function isTimeFormatValid(timeString) {
const timeRegex = /^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/;
const dateTimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
return timeRegex.test(timeString) || dateTimeRegex.test(timeString);
}
function calculateHourlyRate({ startTime, endTime, pricePerHour }) {
// Check if start time and end time are in a valid format
if (!isTimeFormatValid(startTime) || !isTimeFormatValid(endTime)) {