Skip to content

Instantly share code, notes, and snippets.

View charles-dr's full-sized avatar
🏠
Working from home

Charles Ramos charles-dr

🏠
Working from home
View GitHub Profile
@charles-dr
charles-dr / AssetService.js
Created May 18, 2023 09:35
Node.js example
const path = require("path");
const fs = require("fs");
const os = require("os");
const request = require("request");
const sizeOf = require("image-size");
const resizeImg = require("resize-img");
const uuid = require("uuid/v4");
const repository = require(path.resolve("src/repository"));
@charles-dr
charles-dr / callback2promise.js
Created July 7, 2021 13:20
code revamped using promise from callback functions
const DataModel = require('./DataModel'); // let's say the target model is 'DataModel', it's based on mongoose.
return DataModel.findOne({ "conditionKey": "conditionValue" }) // read data from db
.then((data) => { // here update the data
data.a = "test";
data.b = 1111;
return processData(data); // do some processing with data, let's suppose it returns (processed) data again.
})
.then((data) => {
return data.save();
from flask import request
from flask_socketio import SocketIO
# main app
from application import app
clients = {}
socketio = SocketIO(app)
## this is the function to notify the user through socket.
@charles-dr
charles-dr / checkTimeout.js
Last active May 24, 2021 16:37
MongoDBConnectionTimeout
const NodeCache = require('node-cache');
const axios = require('axios');
const { exec } = require('child_process');
const cache = new NodeCache();
const cacheId = 'MONGODB_TIMEDOUT_MONITOR';
const discordWebhook = 'WEBOOK_URL';
const regExp = new RegExp('Server selection timed out after (.*) ms', 'gi');
const activity = {
import Axios from './index'
const ROUTES = {
GET_LESSONS: '/lessons'
}
export const getLessons = async ({ page = 0 }) => {
const response = await Axios.get(ROUTES.GET_LESSONS, {
params: {
page: page