Skip to content

Instantly share code, notes, and snippets.

View mirajehossain's full-sized avatar
🧨
DO NOT DISTURBED

Md. Alamin (Miraje) mirajehossain

🧨
DO NOT DISTURBED
View GitHub Profile

Inspired by this article. Neat tricks for speeding up integer computations.

Note: cin.sync_with_stdio(false); disables synchronous IO and gives you a performance boost. If used, you should only use cin for reading input (don't use both cin and scanf when sync is disabled, for example) or you will get unexpected results.

Multiply by a power of 2

x = x << 1; // x = x * 2

@mirajehossain
mirajehossain / nginx-stat-failed-13-permission-denied.md
Created October 28, 2022 16:54 — forked from windsting/nginx-stat-failed-13-permission-denied.md
fix: Nginx: stat() failed (13: permission denied)

Nginx: stat() failed (13: permission denied)

from https://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied

Nginx operates within the directory, so if you can't cd to that directory from the nginx user then it will fail (as does the stat command in your log). Make sure the www-user can cd all the way to the /username/test/static. You can confirm that the stat will fail or succeed by running

sudo -u www-data stat /username/test/static
@mirajehossain
mirajehossain / System Design.md
Created July 10, 2022 19:30 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree'
"Plug 'tsony-tsonev/nerdtree-git-plugin'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
@mirajehossain
mirajehossain / cluster_availability.js
Last active September 11, 2021 19:45
increase availability of node application
// to increase the availability of the application
// we create new worker using fork() method if the worker is crushed.
// so that we can increase our applications availability.
if (code !== 0 && !worker.exitedAfterDisconnect) {
console.log(`Worker ${worker.id} crashed. \nStarting a new worker...`);
cluster.fork();
}
@mirajehossain
mirajehossain / cluster.js
Last active September 11, 2021 19:46
Uses of cluster module and for multicore cpu
const cluster = require('cluster');
const http = require('http');
// number of cpu cores
const numberOfCPU = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master is running: ${process.pid}`);
// Fork workers.
@mirajehossain
mirajehossain / sequelizeBulkInsert.js
Created October 28, 2020 12:50 — forked from evansiroky/sequelizeBulkInsert.js
Insert CSV using sequelize bulk insert
var fs = require('fs'),
async = require('async'),
csv = require('csv');
var input = fs.createReadStream(filename);
var parser = csv.parse({
columns: true,
relax: true
});
@mirajehossain
mirajehossain / ubuntu-server-hardening.md
Last active April 4, 2024 13:07
ubuntu-server-hardening checklist

Ubuntu-Server-Hardening

1. Secure Shared Memory

What is shared memory?

Shared memory is an efficient means of passing data between programs. Because two or more processes can use the same memory space, it has been discovered that, since shared memory is, by default, mounted as read/write, the /run/shm space can be easily exploited. That translates to a weakened state of security.

If you’re unaware, shared memory can be used in an attack against a running service. Because of this, you’ll want to secure that portion of system memory.

@mirajehossain
mirajehossain / otpverify.js
Created October 5, 2019 17:16 — forked from theanam/otpverify.js
OTP verification without database, full sample source code
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp
{
"board": [{
"title": "Barisal board",
"boardDistricts": {
"districts": [
{
"title": "Barisal",
"thana": ["Muladi Upazila", "Babuganj Upazila", "Agailjhara Upazila", "Barisal Sadar Upazila", "Bakerganj Upazila", "Banaripara Upazila", "Gaurnadi Upazila", "Hizla Upazila", "Mehendiganj Upazila", "Wazirpur Upazila"]
},
{