Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Muhsin Keloth muhsin-k

🏠
Working from home
View GitHub Profile
@muhsin-k
muhsin-k / package.json
Created Feb 9, 2020
Electron basic package.json
View package.json
{
"name": "my-awesome-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
@muhsin-k
muhsin-k / electron.js
Created Feb 9, 2020
Electron basic config
View electron.js
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";
View FCM_message_single_device_curl_command.txt
curl -i -H 'Content-type: application/json' -H 'Authorization: key=<your_server_key>' -XPOST https://fcm.googleapis.com/fcm/send -d '{
"registration_ids":["registration_ids", "of the", "target", "devices as array"],
"notification": {
"title":"Title of your notification",
"body":"content of your notification"
},
"data": {
"key1" : "value1",
"key2" : "value2",
"key3" : 23.56565,
View urlshorten.js
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) {
View UrlShorten.js
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 Apr 11, 2018
URL-Shortener
View index.js
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;
View package.json
{
"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 Mar 18, 2018
Event Loop Example
View multitask.js
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 Mar 18, 2018
Nodejs event loop [One Tick Of Event Loop in NodeJS]
View loop.js
// 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() {
View mongoTransaction.js
var async = require('async'),
mongoose = require('mongoose');
var async = require('async');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/snapflick');
mongoose.Promise = global.Promise;
var models = require('../models/Name')
var Name = models.name;
mongoose.set('debug', true);