Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Muhsin.K muhzi4u

🏠
Working from home
Block or report user

Report or block muhzi4u

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View temp.js
const typeform = async (req, res, next) => {
const { id: uuid } = req.params;
try {
const integration = await db.OrganizationVendor.findOne({
uuid,
})
.populate('vendor')
.populate('organization');
if (integration) {
const { vendor, organization, authParams } = integration;
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);
@muhzi4u
muhzi4u / 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",
@muhzi4u
muhzi4u / index.js
Created Mar 20, 2018
You Might Not Need Lodash
View index.js
const _ = require('lodash');
//1._.toArray: Object.values + Array.from
const postAuthors = {
'Antonin Januska': { id: 1, name: 'Antonin Januska', role: 'author' },
'JK Rowling': { id: 2, name: 'JK Rowling', role: 'real author' },
};
//lodash
console.log('postAuthorsArray',_.toArray(postAuthors))
//ES6
const postAuthorsArray = Object.values(postAuthors);
@muhzi4u
muhzi4u / 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 => {
@muhzi4u
muhzi4u / 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);
You can’t perform that action at this time.