Search This Blog

2026/10/19

GitHub: How to make all repository private in github in bulk



Install Github CLI first
    winget install --id GitHub.cli

Login to GitHub in CLI
    gh auth login

On github CLI list public repo
gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'


Run Code to make all repos private:
    $repos = gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'

    foreach ($repo in $repos) {
        if ($repo.Trim()) {
            Write-Host "Making private: $repo"

            gh repo edit $repo `
                --visibility private `
                --accept-visibility-change-consequences

            if ($LASTEXITCODE -eq 0) {
                Write-Host "SUCCESS: $repo" -ForegroundColor Green
            } else {
                Write-Host "FAILED: $repo" -ForegroundColor Red
            }
        }
    }



Verify listing all private
    gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'

2026/10/15

Javascript:Check numbers are co prime using divisor list

 



function getDivisor(num) {
    let divisor = [];

    for (let i = 2; i <= num; i++) {   // fixed: was i <= num - 1
        if (num % i === 0) {
            divisor.push(i);
        }
    }

    return divisor;
}

function areCoPrime(num1, num2) {
    console.log(`First Number:${num1} Second Number ${num2}`);

    let divisor1 = getDivisor(num1);
    let divisor2 = getDivisor(num2);

    console.log("Divisor", divisor1);
    console.log("Divisor", divisor2);

    let common = divisor1.filter(num => divisor2.includes(num));

    if (common.length > 0) {
        return "Pair is not co-prime";
    } else {
        return "Pair is co-prime";
    }
}

console.log(areCoPrime(6, 9));
// Pair is not co-prime

console.log(areCoPrime(8, 15));
// Pair is co-prime

console.log(areCoPrime(7, 11));
// Pair is co-prime

console.log(areCoPrime(5, 10));
// Pair is not co-prime (this one was wrong before)

console.log(areCoPrime(7, 7));
// Pair is not co-prime (this one was wrong before)

Javascript:Check numbers are co prime using gcd


function gcd(a, b) {
  a = Math.abs(a);
  b = Math.abs(b);
  while (b !== 0) {
    [a, b] = [b, a % b];
  }
  return a;
}

function areCoPrime(num1, num2) {
  if (!Number.isInteger(num1) || !Number.isInteger(num2)) {
    throw new TypeError("Both arguments must be integers");
  }
  return gcd(num1, num2) === 1;
}

console.log(areCoPrime(6, 9));   // false (gcd = 3)
console.log(areCoPrime(8, 15));  // true  (gcd = 1)
console.log(areCoPrime(7, 11));  // true  (gcd = 1)
console.log(areCoPrime(5, 10));  // false (gcd = 5, the case your old code got wrong)
console.log(areCoPrime(7, 7));   // false (gcd = 7)




EC2 vs Lambda

 


Feature                 EC2                                         Lambda
Server management       You manage it                               AWS manages it
Execution               Continuous or on demand                     Event/request triggered
Scaling                 Configure or use Auto Scaling               Automatic
Billing                 Instance running time, plus other charges   Requests and execution duration, plus other charges
Maximum                 execution time  No fixed                    Lambda-style limit  15 minutes per invocation
OS access               Full control over the VM                    No full underlying server access
Best for                Full backend applications                   Short-lived functions and event-driven workloads

Javascript:Fetch

 


Using fetch to make api call.

Code:

const link = "https://jsonplaceholder.typicode.com/posts/1"


fetch(link).then((res)=>{
   return res.json()
}).then((data)=>{
   console.log(data)
})



Output:
{
  userId: 1,
  id: 1,
  title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
  body: 'quia et suscipit\n' +
    'suscipit recusandae consequuntur expedita et cum\n' +
    'reprehenderit molestiae ut ut quas totam\n' +
    'nostrum rerum est autem sunt rem eveniet architecto'
}



Now lets explore how to make post request.

//post request

const linkPost = "https://jsonplaceholder.typicode.com/posts";


fetch(linkPost, {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        title: "JavaScript",
        body: "Learning fetch POST call",
        userId: 1
    })
}).then((res)=>{
   return res.json()
}).then((data)=>{
   console.log(data)
})

Output:
{
  title: 'JavaScript',
  body: 'Learning fetch POST call',
  userId: 1,
  id: 101
}

Javascript: delete Operator

 



Guess output of following code.



const name ="India"
capital = "New Delhi"

console.log(delete name);
console.log(delete capital);



Explanation:

delete operator delete property from global object,it will not delete variable
declaared by var ,let,const.so output will be

false
true

Javascript: Array Sorting Guess output of the Code




Guess output of code.


Code

let arr =[1,21,30,4]
arr.sort((a,b)=>{
 return b-a
})
console.log(arr)




Here sorting will be done element are treated as number & sorting is descending.
output will be [ 30, 21, 4, 1 ]


let arr =[1,21,30,4]
arr.sort()
console.log(arr)


Here sorting will be done in lexographic order ascending where each element is trated as string

output will be [1,21,30,4]

2026/09/22

Javascript:TrimLeft & TrimRight

function trimLeft(str) {
  if (typeof str !== 'string') {
    throw new TypeError('Expected a string');
  }
  return str.replace(/^\s+/, '');
}
function trimRight(str) {
  if (typeof str !== 'string') {
    throw new TypeError('Expected a string');
  }
return str.replace(/\s+$/, '');
}

let input = '   Hello, World!   ';
let trimmedLeft = trimLeft(input);
console.log("'" + trimmedLeft + "'"); // Output: 'Hello, World!   '

let trimmedRight = trimRight(input);
console.log("'" + trimmedRight + "'"); // Output: '   Hello, World!'

2026/08/21

Javascript:Leet Code -Find pair of number in array whose sum equal to target




Find a pair of number from array whose sum is equal to target


nums = [2, 7, 11, 15]
target = 9


function targetSumPair(nums, target) {
    arr = []
    for (let i = 0; i < nums.length; i++) {
        for (let j = i + 1; j < nums.length; j++) {
            if(nums[i]>target && nums[j] > target) continue
            if (nums[i] + nums[j] == target) {
                return [i, j]
            } else {
                console.log(`i=${nums[i]} j=${nums[j]}`)
            }
        }
    }
}

console.log(targetSumPair(nums,target))

Expected Optimized Way:

function targetSumPair(nums, target) {
    let obj = {};

    for (let i = 0; i < nums.length; i++) {
        let complement = target - nums[i];
        if (obj[complement] !== undefined) {
            return [obj[complement], i];
        }

        obj[nums[i]] = i;
    }
}

console.log(targetSumPair([2, 7, 11, 15], 9));{

 

Javascript:Array insert between the array


Here 16 is missing between 9 & 25 that we need to insert at that very place.

let arr = [1, 4, 9, 25, 36];
arr.splice(3, 0, 16);
console.log(arr);

Output:

    [1, 4, 9, 16, 25, 36]

splice(3, 0, 16) means:

3 → index where to insert
0 → don't remove anything if 1 remove one element,if 2 remove 2 element
16 → value to insert 

Here  Original array is mutated.


let arr = [1, 4, 9, 25, 36];
arr.splice(3, 0, 16,17,18);
console.log(arr);

Output:

   [
   1,  4,  9, 16,
  17, 18, 25, 36
]

splice(3, 0, 16) //means:

3 → index where to insert
0 → don't remove anything if 1 remove one element,if 2 remove 2 element
 16,17,18 → value to insert




Javascript:Array Slice

 



slice do not alter original array,array's some part is copied to destination copying is shallow
let languages = ["java","javascript","Go",{node:"javascript"}]
let firstLanguage = languages.slice(3,4)

firstLanguage[0]["node"] = "python" //this value being object is shallow copied hence changes witll in parent also

console.log(languages)
console.log(firstLanguage)


Output:
[ 'java', 'javascript', 'Go', { node: 'python' } ]
[ { node: 'python' } ]


primitive types are copies by value

Javascript Array:Shift & unshift

 



//shift -alter original array give first element of array after remving from original array
let languages = ["java","javascript","Go"]
let firstLanguage = languages.shift()

console.log(languages)
console.log(firstLanguage)



//unshfit
let cities = ["noida","delhi","pune","nagpur"]//
let new_cities = cities.unshift("mumbai")//return new length of array prior add new element to beginning of array

console.log(cities)
console.log(new_cities)


Output:
PS C:\Users\sangr\Practice> node .\unshift.sh
[ 'javascript', 'Go' ]
java
PS C:\Users\sangr\Practice> node .\unshift.sh
[ 'javascript', 'Go' ]
java
[ 'mumbai', 'noida', 'delhi', 'pune' ]
4
PS C:\Users\sangr\Practice> node .\unshift.sh
[ 'javascript', 'Go' ]
java
[ 'mumbai', 'noida', 'delhi', 'pune', 'nagpur' ]

Mysql:Find employee with same salary in employee table

 


Find employee with same salary from employee table

CREATE TABLE employee (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    age INT,
    city VARCHAR(100),
    salary DECIMAL(10, 2),
    doj DATE
);


INSERT INTO employee (name, age, city, salary, doj)
VALUES
('John', 28, 'Noida', 50000, '2022-06-15'),
('Jerry', 32, 'Delhi', 65000, '2020-03-10'),
('Bill', 25, 'Mumbai', 45000, '2023-01-20'),
('Siara', 30, 'Pune', 70000, '2019-08-05');

INSERT INTO employee (name, age, city, salary, doj)
VALUES
('Amit', 29, 'Delhi', 50000, '2021-04-12'),
('Rahul', 35, 'Noida', 65000, '2018-07-19'),
('Neha', 27, 'Mumbai', 45000, '2022-11-03'),
('Priya', 31, 'Pune', 70000, '2020-02-14'),
('Raj', 26, 'Delhi', 50000, '2023-05-22'),
('Ankit', 33, 'Noida', 75000, '2017-09-11'),
('Sneha', 28, 'Mumbai', 65000, '2021-12-01'),
('Vikas', 37, 'Pune', 80000, '2016-06-18'),
('Pooja', 29, 'Delhi', 75000, '2022-03-25'),
('Karan', 34, 'Noida', 80000, '2019-10-07');

Solution

SELECT salary,JSON_ARRAYAGG(name) AS employee_salary
FROM employee group by salary;

Output:
+----------+-----------------------------+
| salary   | employee_salary             |
+----------+-----------------------------+
| 45000.00 | ["Bill", "Neha"]            |
| 50000.00 | ["John", "Amit", "Raj"]     |
| 65000.00 | ["Jerry", "Rahul", "Sneha"] |
| 70000.00 | ["Siara", "Priya"]          |
| 75000.00 | ["Ankit", "Pooja"]          |
| 80000.00 | ["Vikas", "Karan"]          |
+----------+-----------------------------+
6 rows in set (0.00 sec)

SELECT salary,group_concat(name) AS employee_salary
FROM employee group by salary;

Output:
+----------+-------------------+
| salary   | employee_salary   |
+----------+-------------------+
| 45000.00 | Bill,Neha         |
| 50000.00 | John,Amit,Raj     |
| 65000.00 | Jerry,Rahul,Sneha |
| 70000.00 | Siara,Priya       |
| 75000.00 | Ankit,Pooja       |
| 80000.00 | Vikas,Karan       |
+----------+-------------------+
6 rows in set (0.00 sec)


SELECT salary, JSON_OBJECTAGG(name, city)  FROM employee GROUP BY salary;

Output:
+----------+---------------------------------------------------------+
| salary   | JSON_OBJECTAGG(name, city)                              |
+----------+---------------------------------------------------------+
| 45000.00 | {"Bill": "Mumbai", "Neha": "Mumbai"}                    |
| 50000.00 | {"Raj": "Delhi", "Amit": "Delhi", "John": "Noida"}      |
| 65000.00 | {"Jerry": "Delhi", "Rahul": "Noida", "Sneha": "Mumbai"} |
| 70000.00 | {"Priya": "Pune", "Siara": "Pune"}                      |
| 75000.00 | {"Ankit": "Noida", "Pooja": "Delhi"}                    |
| 80000.00 | {"Karan": "Noida", "Vikas": "Pune"}                     |
+----------+---------------------------------------------------------+

2026/08/11

Javascript:Guess output of given code

 



Guess Output of code.


let arr =[1,2,3];
let str="1,2,3";

if(arr==str){
    console.log("Equal")
}else{
    console.log("Not equal")
}

if(arr===str){
    console.log("Equal")
}else{
    console.log("Not equal")
}

if(Object.is(arr,str)){
    console.log("Equal")
}else{
    console.log("Not equal")
}

Output:
Equal
Not equal
Not equal

Note:
   [1,2,3].toString() is "1,2,3"

Javascript:Find nth fibonacci number

 



Find nth fibonacci number.


code:
function fibonacci(n){
   if(n==1 || n==2){
    return 1
   }else{
    return fibonacci(n-1) + fibonacci(n-2)
   }
}


let num = fibonacci(5)
console.log(num)

output:
5

Javascript:Remove falsy values from array



Remove falsy values in array:

Code:
const arr = [1, 0, false, "hello", "", null, undefined, NaN, 5];

const result = arr.filter((item)=>{
    return Boolean(item)
});

console.log(result);

Output:
[ 1, 'hello', 5 ]

 

Javascript:Find the maximum difference between any two elements in an input array

 


Find the maximum difference between any two elements in an input array?

Code:

let arr=[12,13,45,20,56,50,5]

function findMaxDifference(arr) {
   let min=arr[0];
   let max=arr[0];

   for(let i=0;i<arr.length;i++){
      if(min > arr[i]){
        min=arr[i]
      }
      if(max < arr[i]){
        max =arr[i]
      }
   }
   console.log(min,max)
   return max -min
}

let maxDiff = findMaxDifference(arr);
console.log(maxDiff)

Output:
5 56
51

Javascript:Capitalize first and last character in sentence

 



Capitalize first and last character in sentence.

Code:

let sentence = "hello john how do you do"

function firstCharCapital(sentence){
  return sentence.at(0).toUpperCase() + sentence.slice(1)
}

function lastCharCapital(sentence){
   return  sentence.slice(0,sentence.length -1 ) +  sentence.at(sentence.length -1).toUpperCase()
}

let firstCharCapitalized = firstCharCapital(sentence)
console.log(firstCharCapitalized)


let lastCharCapitalized = lastCharCapital(sentence)
console.log(lastCharCapitalized)

Output:
Hello john how do you do
hello john how do you dO

Explanation:I have written two functions to get desired result we can call them one
on other like firstCharCapital(lastCharCapital(sentence))

Javascript:bigint datatype



How to use large number in javascript?

Code:

let num1 =123456777867;
let num2 = 5324152355467563;
console.log(num1 *num2); //6.573026946790237e+26

let num3 =123456777867n;
let num4 = 5324152355467563n;
console.log(num3 *num4); //657302694679023748214828121n

output:
6.573026946790237e+26
657302694679023748214828121n

Explanation:
   when number are large there result is aproximated by default
   you can use n at end to declare it as bigint,bigint can store

   large number,if n is at end of number then it is bigint datatype.