Skip to content

Instantly share code, notes, and snippets.

View muhsin-k's full-sized avatar
🏠
Working from home

Muhsin Keloth muhsin-k

🏠
Working from home
View GitHub Profile
@muhsin-k
muhsin-k / electron.js
Created February 9, 2020 15:21
Electron basic config
const electron = require("electron");
const { app, BrowserWindow } = electron;
const path = require("path");
const url = require("url");
const isDev = require("electron-is-dev");
let mainWindow;
const localUrl = "http://localhost:3000";
@muhsin-k
muhsin-k / urlshorten.js
Created April 11, 2018 08:16
URL-Shortener
const mongoose = require("mongoose");
const validUrl = require("valid-url");
const UrlShorten = mongoose.model("UrlShorten");
const shortid = require("shortid");
const errorUrl='http://localhost/error';
module.exports = app => {
app.get("/api/item/:code", async (req, res) => {
const urlCode = req.params.code;
const item = await UrlShorten.findOne({ urlCode: urlCode });
if (item) {
@muhsin-k
muhsin-k / UrlShorten.js
Created April 11, 2018 08:15
URL-Shortener
const mongoose = require("mongoose");
const { Schema } = mongoose;
const urlShortenSchema = new Schema({
originalUrl: String,
urlCode: String,
shortUrl: String,
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now }
});
mongoose.model("UrlShorten", urlShortenSchema);
@muhsin-k
muhsin-k / index.js
Created April 11, 2018 05:50
URL-Shortener
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const mongoURI = "mongodb://localhost/url-shortner";
const connectOptions = {
keepAlive: true,
reconnectTries: Number.MAX_VALUE
};
//Connect to MongoDB
mongoose.Promise = global.Promise;
@muhsin-k
muhsin-k / package.json
Created April 8, 2018 09:56
URL-Shortener
{
"name": "server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "nodemon index.js "
},
"dependencies": {
"express": "^4.16.3",
@muhsin-k
muhsin-k / multitask.js
Created March 18, 2018 07:59
Event Loop Example
process.env.UV_THREADPOOL_SIZE = 5;
const https = require("https");
const crypto = require("crypto");
const fs = require("fs");
const start = Date.now();
function doRequest() {
https
.request("https://www.google.com", res => {
@muhsin-k
muhsin-k / loop.js
Last active March 18, 2018 04:36
Nodejs event loop [One Tick Of Event Loop in NodeJS]
// Suppose we are running ,node myFile.js
const pendingTimers = [];
const pendingOSTasks = [];
const pendingOperations = [];
// New timers, tasks, operations are recorded from myFile running [We are pretending here]
myFile.runContents();
function shouldContinue() {
@muhsin-k
muhsin-k / sortarray.js
Last active June 10, 2017 16:18
Sort Array Object with Multiple Keys[Date and String] [Javascript ,Nodejs]
var moment = require('moment');
var result = [{
"rank": 1,
"u_total_price": 10,
"user": {
"_id": "59381ca1d48d69e140518ea3",
"u_firstname": "Abin",
"u_created_at": "2017-06-07T15:32:49.240Z"
}
}, {