Skip to content

Instantly share code, notes, and snippets.

View RanKey1496's full-sized avatar
🎯
Focusing

Jhon Gil Sepulveda RanKey1496

🎯
Focusing
  • Medellín - Colombia
View GitHub Profile
@RanKey1496
RanKey1496 / onion-demo.md
Created January 31, 2023 17:24 — forked from cdiaz/onion-demo.md
Arquitectura cebolla

Node.js y la arquitectura en capas de cebolla con InversifyJS

Este ejemplo demuestra cómo integrar InversifyJS con Express y como implementar aplicaciones que se adhieren a la arquitectura en capas de cebolla. Esta arquitectura de capas puede representarse en un diagrama como sigue:

onion

La principal diferencia entre una arquitectura de n-capas tradicional y la arquitectura cebolla es la dirección de las dependencias entre capas.

En la arquitectura cebolla aplicamos el principio de inversión de dependencias. Los detalles de la implementación (infraestructura) depende de las abstracciones (dominio):

@RanKey1496
RanKey1496 / Utils.java
Created May 6, 2019 04:16
Convert String to LineString or Point written in Java
public class Utils {
private static final int GEOMETRY_PRECISION = 4326;
public static Point convertStringToPoint(String encode) {
try {
if (encode == null || encode.length() <= 0)
return null;
String[] coordinates = encode.replaceFirst("POINT ?\\(", "").replaceFirst("\\)", "").split(" ");
@RanKey1496
RanKey1496 / Utils.java
Created May 6, 2019 04:15
Google polyline decoder written in Java
import org.locationtech.jts.geom.*;
public class Utils {
private static final double DEFAULT_PRECISION = 1E5;
public static LineString decodePolyline(String encoded) {
return decodePolyline(encoded, DEFAULT_PRECISION);
}
@RanKey1496
RanKey1496 / Utils.java
Created May 6, 2019 04:14
Google Polyline encoder written in Java
public class Utils {
private static final double DEFAULT_PRECISION = 1E5;
private static String encodeDiff(int diff) {
StringBuilder str = new StringBuilder();
int shifted = diff << 1;
if (diff < 0) {
shifted = ~shifted;
}
{
"value":700000,
"status":"PROMOCION",
"property":{
"type":"CASA",
"neighborhood":"CAMPO VALDES",
"sector":"NORORIENTE",
"city":"MEDELLIN",
"latitude":6.275141,
"longitude":-75.554989,
@RanKey1496
RanKey1496 / mysql_backup
Created April 3, 2019 19:34
Backup a dockerized MySQL and upload to S3
#!/bin/bash
# Configuration
CONTAINER="mysql"
FILENAME="databasename-`date +%Y-%m-%d`.sql"
MYSQL_USER='user'
MYSQL_PASSWORD='password'
DATABASE_NAME='databasename'
S3_BUCKET_NAME='bucket'
S3_BUCKET_PATH='backups'
@RanKey1496
RanKey1496 / mongo_backup
Created April 3, 2019 19:32
Backup a dockerized MongoDB and upload to S3
#!/bin/bash
# Configuration
CONTAINER="mongo"
FILENAME="databasename-`date +%Y-%m-%d`"
MONGO_USER='user'
MONGO_PASSWORD='pass'
DATABASE_NAME='databasename'
S3_BUCKET_NAME='bucket'
S3_BUCKET_PATH='backups/database'
@RanKey1496
RanKey1496 / rocket
Created March 26, 2019 18:49
View channels messages in Rocket.Chat
You can already do this by connecting to your Mongo database.
List the rooms with db.rocketchat_room.find({}), grab the ID of the room you want the history for.
Then you can see that room's history with db.rocketchat_message.find({"rid": "your_chatroom_id"}, {"u.username": 1, "msg": 1, "_id": 0}).sort({ts: 1}).map(function (d) {return d.u.username + ": " + d.msg})
It's not as intuitive as a web interface, but auditing your users' chat logs should seldom be done therefore this is a viable workaround in the meantime.
This topic attracts a great deal of controversy, as it should. That being said, this method is a workaround until there is a corresponding UI. This also means that you are already being recorded when chatting using RocketChat since your messages are saved in the database unencrypted (unless you use OTR). If you allow your users to edit/delete their messages, they are indeed modified/deleted from the database, so take that into account.
@RanKey1496
RanKey1496 / benchmark.txt
Created March 7, 2019 04:24
Express vs Fastify vs Nest vs Nest-Fastify
-----------------------
express
-----------------------
Running 10s test @ http://localhost:3000
8 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 47.78ms 19.09ms 212.47ms 66.94%
Req/Sec 1.31k 268.90 2.07k 72.38%
104687 requests in 10.02s, 21.47MB read
Socket errors: connect 0, read 877, write 0, timeout 0
@RanKey1496
RanKey1496 / tricks.txt
Created March 7, 2019 00:22
Docker swarm tricks
# error from daemon in stream: Error grabbing logs: rpc error: code = Unknown desc = warning: incomplete log stream. some logs could not be retrieved for the following reasons: node xxx is not available
docker swarm ca --rotate
# list docker swarm nodes with labels
docker node ls -q | xargs docker node inspect \
-f '{{ .ID }} [{{ .Description.Hostname }}]: {{ .Spec.Labels }}'
# list docker swarm nodes with IPs
for NODE in $(docker node ls --format '{{.Hostname}}'); \
do echo -e "${NODE} - $(docker node inspect --format '{{.Status.Addr}}' "${NODE}")"; done