Skip to content

Instantly share code, notes, and snippets.

View Shaxadhere's full-sized avatar
my apps fast like a lightning of a thunder

Shehzad Ahmed Shaxadhere

my apps fast like a lightning of a thunder
View GitHub Profile
@Shaxadhere
Shaxadhere / statesWithCities.js
Created February 25, 2022 05:43
State names with cities javascript array
export const statesWithCities = [
{
stateName: "Islamabad",
cities: ["Islamabad"],
},
{
stateName: "Punjab",
cities: [
"Ahmed Nager Chatha",
"Ahmadpur East",
@Shaxadhere
Shaxadhere / reverseString.js
Last active April 28, 2022 06:30
Reverse words in sentence in JavaScript without using JS pre built functions
let string = "NodeJS is single threaded";
let array = [];
let ress = "";
let reversed = "";
let tempVal = "";
let str = string ;
for (let index = 0; index < str.length; index++) {
if (str[index] != " " || (index +1) === (str.length)) {
tempVal += str[index];
const asyncLocalStorage = {
setItem: function (key, value) {
return Promise.resolve().then(function () {
localStorage.setItem(key, value);
});
},
getItem: function (key) {
return Promise.resolve().then(function () {
return localStorage.getItem(key);
});
@Shaxadhere
Shaxadhere / uploadFileToDiskStorage.js
Last active June 7, 2022 06:45
upload file to disk storage via multer
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
req.body.image = uniqueSuffix + path.extname(file.originalname);
cb(null, uniqueSuffix + path.extname(file.originalname));
},
});
@Shaxadhere
Shaxadhere / uploadFileToAzure.js
Last active June 7, 2022 06:44
upload file to azure blob storage via multer and multer-azure-blob-storage
const path = require("path");
const multer = require("multer");
const MulterAzureStorage = require('multer-azure-blob-storage').MulterAzureStorage;
const { ApiResponse, generateString } = require("../helpers");
require("dotenv").config()
//upload to azure blob storage
const resolveBlobName = (req, file) => {
return new Promise((resolve, reject) => {
const blobName = generateString(20) + path.extname(file.originalname);
const categories = [
{id:1, name:"Web Design"},
{id:2, name:"Web Development"},
{id:3, name:"Logo Design"}
]
const data = [
{id:1, title:"Some title", category: "Web Design"},
{id:1, title:"Some title", category: "Some new"},
{id:1, title:"Some title", category: "Web Design"},
const calcMinutes = (time="12:30 AM-07:30 PM") => {
const _time = time.split("-")
const lastMeridian = _time[1].slice(-2)
let firstDate = "2022-01-01"
let lastDate = "2022-01-01"
if(lastMeridian=="AM"){
firstDate = "2022-01-02"
const QuestionsMarks =(str="acc?7??sss?3rr1??????5")=>{
numberCount = 0
markCount = 0
markUsed=0
numberSum = 0
lastAdded=0
result = false
str.split("").forEach((item) => {
if(!isNaN(item)) numberCount=1
if(numberCount>0){
@Shaxadhere
Shaxadhere / web.config
Created August 9, 2022 08:39
azure react app configuration file
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
const a = [1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
let count = 0
let _count = []
a.forEach((item, index)=> {
if(item==1){
count = count + 1
if(index==a.length-1) _count.push(count)
}
else{