Skip to content

Instantly share code, notes, and snippets.

View puuble's full-sized avatar

marian ivanov puuble

  • full stack backend
  • Bulgaria
View GitHub Profile
@puuble
puuble / MongoSessionHandler.php
Last active December 23, 2020 15:36
E11000 duplicate key error collection Laravel mongoDB sessions
<?php
namespace App\Session;
use Illuminate\Session\DatabaseSessionHandler;
class MongoSessionHandler extends DatabaseSessionHandler
{
/**
@puuble
puuble / .env
Created October 16, 2022 09:53
nodejs mongodb queue. Create your job on mongodb for send and receive.
QUEUE_DB_HOST=
QUEUE_DB_PORT=27017
QUEUE_DB_USER=root
QUEUE_DB_PASS=12345678
QUEUE_DB_NAME=test
QUEUE_DB_COLL=queue
@puuble
puuble / package.json
Created December 25, 2022 22:11
(Uncaught Options object must provide a cluster)
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"@tailwindcss/typography": "^0.5.0",
"alpinejs": "^3.0.6",
@puuble
puuble / table.php
Created January 12, 2023 12:41
php table stdClass
<?php
// Lemmod - Couldn't be bothered to make my own class as this works as well
/**
* STable - Generate HTML Tables
*
* @package STable
* @category STable
* @name STable
* @version 1.0
@puuble
puuble / f1_event_bus.py
Last active January 17, 2023 13:58
python event bus
from collections import defaultdict
from threading import Lock
class EventBus:
def __init__(self):
self.events = defaultdict(list)
self.lock = Lock()
def subscribe(self, event, callback):
with self.lock:
@puuble
puuble / f1_event-bus.js
Last active January 17, 2023 13:30
event handler and chunk file for send with event.emit
const EventEmitter = require('events');
const eventBus = new EventEmitter();
module.exports = eventBus;
@puuble
puuble / f1_server.js
Last active January 18, 2023 22:38
web socket handle on nodejs for big concurrent
const WebSocket = require('ws');
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.Console()
]
});
@puuble
puuble / f1_mongodb_catch_logs_and_bounce.js
Last active January 18, 2023 22:50
adding mongodb websocket erorr logs with polling
//https://gist.github.com/puuble/d501bcdc03fb43499e09553458827c42 part 2
const MongoClient = require('mongodb').MongoClient;
const AWS = require('aws-sdk');
const sqs = new AWS.SQS({
region: 'us-west-2',
accessKeyId: 'ACCESS_KEY',
secretAccessKey: 'SECRET_KEY'
});
const queueUrl = 'https://sqs.us-west-2.amazonaws.com/1234567890/my-queue';
@puuble
puuble / f1_worker.js
Created January 18, 2023 23:15
working on worker for websocket queue SQS how to multiple thread p4
const { Worker, isMainThread, parentPort } = require('worker_threads');
const WebSocket = require('ws');
const AWS = require('aws-sdk');
const sqs = new AWS.SQS({
region: 'us-west-2',
accessKeyId: 'ACCESS_KEY',
secretAccessKey: 'SECRET_KEY'
});
const queueUrl = 'https://sqs.us-west-2.amazonaws.com/1234567890/my-queue';
@puuble
puuble / f1_eventEmitter.py
Created January 18, 2023 23:19
python event emitter with SQS
import threading
from queue import Queue
import boto3
from pymongo import MongoClient
class LogService:
def __init__(self):
self.client = MongoClient('mongodb://localhost:27017/')
self.db = self.client['logs']