Skip to content

Instantly share code, notes, and snippets.

@Prottoy2938
Prottoy2938 / Chattogram Collegiate School Annual Study Tour 2020 Markdown.md
Created Dec 3, 2020
Chattogram Collegiate School Annual Study Tour 2020 Markdown
View Chattogram Collegiate School Annual Study Tour 2020 Markdown.md

Chattogram Collegiate School Annual Study Tour 2020

Visit to the National Liberation War Museum, Dhaka on 14th January, 2021


Students of Grade 6, 7, and 8,

@Prottoy2938
Prottoy2938 / change-svg-color-code-demo-medium.js
Created Nov 19, 2020
Change SVG Color application code demo medium
View change-svg-color-code-demo-medium.js
//Suppose you have an svg element defined in html like this:
<img src="/profile.svg" alt="some svg" id="my-svg"/>
//to change its color, you can do this in the css:
#my-svg {
filter: invert(19%) sepia(48%) saturate(1556%) hue-rotate(223deg) brightness(91%) contrast(123%);
}
@Prottoy2938
Prottoy2938 / rgba-to-css-filter.js
Last active Nov 5, 2020
RGBA To CSS Filter Converter. This code is a slightly modified version of this stackoverflow answer: https://stackoverflow.com/a/43960991/604861
View rgba-to-css-filter.js
"use strict";
class Color {
constructor(r, g, b) {
this.set(r, g, b);
}
toString() {
return `rgb(${Math.round(this.r)}, ${Math.round(this.g)}, ${Math.round(
this.b
)})`;
@Prottoy2938
Prottoy2938 / substitution-ciper.js
Last active Nov 2, 2020
Cipher Delta letter substitution algorithm (only English letters)
View substitution-ciper.js
function reverse(s) {
return s.split("").reverse().join("");
}
const engAlphabets = "abcdefghijklmnopqrstuvwxyz".repeat(3);
const reverseEngAlphabets = reverse("abcdefghijklmnopqrstuvwxyz").repeat(3);
const engAlIndexes = {
a: 0,
b: 1,
c: 2,
d: 3,
@Prottoy2938
Prottoy2938 / ch-key-generation.js
Created Nov 2, 2020
Cipher Delta key generation code
View ch-key-generation.js
function makeId(length) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
View asdfadf.js
//get the nth number in fibonacci sequence, base case is 0 and 1.
//solution 1, easier to understand but it's not good. It has a time complexity of O(2^n).
function fib(num) {
if (num === 2) return 1;
if (num === 1) return 0;
return fib(num - 1) + fib(num - 2);
}
fib(6) //returns 5
@Prottoy2938
Prottoy2938 / device-data-placeholder.js
Created May 10, 2020
Front-end demo JSON api with comments
View device-data-placeholder.js
{
"Status": "Connected",
"Adminstration Control": {
"Connection": "stable",
//Total number 100. 70 means adminstration can control most of stuff of that device, but he is restricted on some of the part.
//will need to think more about it
"Permission": "70" //rank system. 70 out of 100
},
"Device": {
View get-fibonacci.js
//get the nth number in fibonacci sequence, base case is 0 and 1.
//solution 1, easier to understand but it's not good. It has a time complexity of O(2^n).
function fib(num) {
if (num === 2) return 1;
if (num === 1) return 0;
return fib(num - 1) + fib(num - 2);
}
fib(6) //returns 5
@Prottoy2938
Prottoy2938 / fibonacci-sequence.js
Created Mar 19, 2020
Generates Fibonacci Sequence and returns it in an Array, base case is 0 and 1.
View fibonacci-sequence.js
// Get Fibonacci Sequence in an Array, base case is 0 and 1.
const fibSequence = (num) => {
if(num === 0) return 0;
const arr=[0,1];
let counter=2;
while(counter <=num){
arr[counter]=arr[counter -1] + arr[counter -2]
counter ++
}
@Prottoy2938
Prottoy2938 / Binary Search Tree Validation.js
Created Mar 18, 2020
Binary Search Tree Validation in JavaScript
View Binary Search Tree Validation.js
//Solution 1
const isValidBST = function(root, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
if(root == null) return true
if(root.val >= max || root.val <= min) return false
return isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max)
};