Skip to content

Instantly share code, notes, and snippets.

View cb-v4s's full-sized avatar
🦄

Carlos L. Barrios cb-v4s

🦄
  • Caracas, Venezuela
View GitHub Profile
@cb-v4s
cb-v4s / gist:293e0dee218da1415c9288db6d2c8d03
Last active August 20, 2021 02:00
clone a private repo
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/foo
; then manually insert .pub key on the github account in settings > SSH and GPG keys > SSH keys
ssh-agent bash -c 'ssh-add ~/.ssh/foo; git clone [email protected]:username/repo_name.git'
@cb-v4s
cb-v4s / .js
Created July 16, 2021 21:11
non-blocking multiprocess express webserver for long time consuming tasks
const express = require('express')
const { fork } = require('child_process')
const app = express()
app.get('/', (req, res) => {
const name = req.query.name
const cp = fork('./greetings.js') // heavy task example
cp.send({ "name", name })
@cb-v4s
cb-v4s / .js
Last active July 16, 2021 21:20
express webserver rate limiting and more security measures
const limitter = require('express-rate-limit')
const helmet = require('helmet')
...
// middlewares
app.use(
limitter({
windowMs: 5000,
@cb-v4s
cb-v4s / .js
Last active July 16, 2021 21:21
multi-core server manager for an express webserver performance
const cluster = require('cluster')
const express = require('express')
// const compression = require('compression')
const os = require('os')
const app = express()
const port = 3000
const ncpus = os.cpus().length
@cb-v4s
cb-v4s / .js
Last active July 6, 2021 01:10
mediator pattern js
const mediator = (() => {
const events = {};
const subscribe = (event, fn) => {
if (!events[event]){
events[event] = [];
}
events[event].push(fn);
@cb-v4s
cb-v4s / gist:0305385a6ea1e5ee537406fc7bd3c392
Last active January 27, 2021 17:36
setup a replica set cluster for mongodb
; setup replica sets
mongod --port 27017 --dbpath ~/mongoc/db0 --replSet Replicante
mongod --port 27027 --dbpath ~/mongoc/db1 --replSet Replicante
mongod --port 27037 --dbpath ~/mongoc/db2 --replSet Replicante
; mongo --port 27017
rs.initiate()
rs.add("localhost:27027") ; add second member
rs.add("localhost:27037") ; add third member
; crear bot y grupo en telegram
agregar @BotFather en telegram para crear el bot, crea un grupo e invitalo
; consigue chatid desde la api de telegram usando el api token del bot
https://api.telegram.org/bot<TOKEN>/getUpdates
; enviar mensajes usando la api de telegram
https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<CHATID>&parse_mode=Markdown&text=<MESSAGE>'
; find all the files containing `topsykrettz` str in the current folder excluding `node_modules` dir
grep -iRl "topsykrettz" ./ | grep -v node_modules
; find all `mongodb+srv://` occurences in all git logs
git log|grep commit|cut -d' ' -f2|while read commit; do git show $commit; done| grep -i mongodb+srv://
; monitor logs in realtime
tail -f logfile
; copy file content to clipboard
@cb-v4s
cb-v4s / .py
Last active January 27, 2021 17:25
python script performance
import time, memory_profiler
i_mem = memory_profiler.memory_usage()
start = time.time()
myfunc()
end = time.time()
f_mem = memory_profiler.memory_usage()
elapsed = end - start
; csgofloat api
https://api.csgofloat.com/?url=steam://rungame/730/...........................
; query inicial
https://steamcommunity.com/market/search?appid=730&q=Case Hardened
https://steamcommunity.com/market/search/render/?query=Case Hardened&start=1&count=100&search_descriptions=0&sort_column=price&sort_dir=desc&appid=730&norender=1
; listings por cada resultado del query inicial
https://steamcommunity.com/market/listings/730/★ Bayonet | Case Hardened (Battle-Scarred)
https://steamcommunity.com/market/listings/730/★ Bayonet | Case Hardened (Battle-Scarred)/render/?query=&start=0&count=100&country=US&language=english&currency=1