Skip to content

Instantly share code, notes, and snippets.

View caglarorhan's full-sized avatar
🤿
diving to the codes :)

Çağlar ORHAN caglarorhan

🤿
diving to the codes :)
View GitHub Profile
@caglarorhan
caglarorhan / twtterAdRemover.js
Created April 21, 2023 02:05
Removes twitter promoted ads with pageload and scroll events.
const removeAdTwt = ()=>{
document.querySelectorAll('[data-testid="placementTracking"]').forEach(oDiv=>{
if(oDiv.innerHTML.includes('Promoted</span>')){
oDiv.remove();
}
})
};
window.addEventListener("load", removeAdTwt);
@caglarorhan
caglarorhan / bind_in_js.js
Created December 19, 2022 22:08
Bind example in javascript
const main =function(){
this.name="The Main function"
helper.bind(this);
helper();
console.log("FROM MAIN:",this.name);
}
function helper(){
console.log("FROM HELPER:",this.name);
this.name = "The Helper Function";
@caglarorhan
caglarorhan / romanToInteger.js
Created July 28, 2022 02:03
convert Roman numbers to integer
var romanToInt = function(s) {
let num=0;
let romans ={
"I":1,
"V":5,
"X":10,
"L":50,
"C":100,
"D":500,
"M":1000
@caglarorhan
caglarorhan / integerToRoman.js
Created July 27, 2022 20:10
Convert integers (<4000) to Roman
var intToRoman = function(num) {
let romans={
"1": ["I","V"],
"2": ["X","L"],
"3": ["C","D"],
"4": ["M","M"]
}
let s = num.toString();
let converted="";
for(let i=0 ; i<s.length; i++){
@caglarorhan
caglarorhan / xmassTree.js
Created July 26, 2022 06:18
XmassTree Drawing
for(let i=1, x=0; i<40;i=i+2, x++){
let empty = " ".repeat(40-(x));
let rand = ()=>Math.floor(Math.random()*i);
let star = "*".repeat(i).split('');
star[rand()]="❆";
// star[rand()]="🎁";
// star[rand()]="🔔";
console.log(empty,star.join(''));
}
@caglarorhan
caglarorhan / longestCommonSubsequence.js
Created July 11, 2022 06:51
Find longest common subsequence between given two strings. Letter orders must be kept in strings.
// Top-down without memoization, kind of bruteforce. Time complexity is too bad.
var longestCommonSubsequence = function(text1, text2) {
if(text1.length===0 || text2.length===0) return 0;
let letter1 = text1[0];
let firstOccurance = text2.indexOf(letter1);
let case1 = longestCommonSubsequence(text1.substring(1), text2);
// text1 in ilk harfiyle olan kombinasyon cozumun parcasi degilse, ilk harfi haric text1 ile text2 recursive sokulur
let case2=0;
@caglarorhan
caglarorhan / parse_json_ld.js
Created June 30, 2022 03:00
Get and parse spesific JSON+ld data
let scripts = document.querySelectorAll('script[type="application/ld+json"]');
// you might wanna change filter criteria as you wish to get any information from json_ld data
sku = [...scripts].map(ingredient=>JSON.parse(ingredient.innerText)).filter(scr=>scr["@type"]==="Product")[0].sku;
@caglarorhan
caglarorhan / dec2bin.js
Created June 24, 2022 02:31
Converts decimal to binary
function dec2bin(dec){
if(dec<2){
return dec;
}
return dec2bin(((dec-(dec%2))/2)).toString()+(dec%2).toString();
}
console.log(dec2bin(642313587))
@caglarorhan
caglarorhan / bin2dec.js
Created June 24, 2022 02:12
Convert binary to decimal
function bin2dec(bin){
bin=bin.toString();
let binArr = bin.split('');
binArr = binArr.reverse();
let dec = 0;
binArr.forEach((count,index)=>{
dec+=count*Math.pow(2,index);
})
return dec;
}
@caglarorhan
caglarorhan / anagramWithFrequency.js
Created June 15, 2022 04:33
Solving a type of anagram problem with frequency
function isAnagramFunction (word_A, word_B){
let isAnagram=true;
let map_A=Object.create(null);
let map_B=Object.create(null);
let arr_A = word_A.split('');
let arr_B = word_B.split('');
arr_A.forEach(letter=>{
if(map_A[letter]){