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 / geospatialMYSQL.sql
Created March 8, 2018 16:20
Geospatial query that search properties nearby to a point
SELECT
prom.id, p.id, p.direccion, p.latitud, p.longitud,
(
6371 *
ACOS(
COS( RADIANS( 6.250020 ) ) *
COS( RADIANS( `latitud` ) ) *
COS(
RADIANS( `longitud` ) - RADIANS( -75.568510 )
) +
@RanKey1496
RanKey1496 / socket-cheatsheet.js
Created October 16, 2018 04:40 — forked from alexpchin/socket-cheatsheet.js
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
@RanKey1496
RanKey1496 / gist:223bd1e4f6853bd1c3c9f23dba3de7e8
Created October 16, 2018 04:40 — forked from yunghoy/gist:a425f91824d26461bb2e3653bc56ebbf
AMQP library (RabbitMQ) - async/await
alias babel-node='babel-node --presets stage-0'
------ RECV ------
// babel-node recv2.js "#"
// babel-node recv2.js "kern.*"
const amqp = require('amqplib');
const args = process.argv.slice(2);
if (args.length == 0) {
@RanKey1496
RanKey1496 / docker-letsencrypt
Created October 22, 2018 21:32
Generate wildcard certificates with Docker
docker run -it --rm --name letsencrypt \
-v /letsencrypt/etc/letsencrypt:/etc/letsencrypt \
-v /letsencrypt/var/lib/letsencrypt:/var/lib/letsencrypt \
quay.io/letsencrypt/letsencrypt:latest \
certonly \
-d domain.com \
-d *.domain.com \
--manual \
--preferred-challenges dns \
--server https://acme-v02.api.letsencrypt.org/directory
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://host:5432/database
username: 123
password: 123
hikari:
minimum-idle: 9
@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
@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 / 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 / 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 / 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'