Skip to content

Instantly share code, notes, and snippets.

View bishoymelek-zz's full-sized avatar
🎯
Focusing

Bishoy Melek bishoymelek-zz

🎯
Focusing
  • Cairo,Egypt
View GitHub Profile
@bishoymelek-zz
bishoymelek-zz / rename_js_files.sh
Created October 6, 2019 08:54 — forked from afternoon/rename_js_files.sh
Rename .js files to .ts
find app/src -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
@bishoymelek-zz
bishoymelek-zz / sortOrGetAverageRank.js
Created July 30, 2019 09:03
Sort by Rank Or Get Average Rank
const arr = [
{
name: 'Sydney',
rank: 1392
},
{
name: 'London',
rank: 1992
},
{
@bishoymelek-zz
bishoymelek-zz / get_with_pagination.js
Created April 27, 2019 20:29
example for get data from mongodb with mongoose in express app with pagination( without additional npm packages)
app.get('/:pageNum', function (req, res) {
try {
// how many to items to load everytime
const perPage = 12;
// which page is current?
const page = req.params.pageNum || 1;
// find all
ClientModel.find({})
// skip number of items (number of pages we passed * number of items per page) minus one of that number of
// items per page (to get the current one we get as param)
@bishoymelek-zz
bishoymelek-zz / CyclicRotation.js
Last active July 22, 2020 14:56
CyclicRotation(Javascript) - codility.com
// An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).
// The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.
// Write a function:
// function solution(A, K);
// that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.
@bishoymelek-zz
bishoymelek-zz / server.js
Created March 16, 2018 21:24
a snippet to use in your expressJS app if it keep logging you out while reloading the app in the development
var connect = require('connect');
var cookieParser = require('cookie-parser');
var cookieSession = require('cookie-session')
app.use(connect()).use(cookieParser());
app.use(cookieSession({
name: 'session',
keys: ['key1', 'key2'],
// Cookie Options
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}));