Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
yarliganfatih / ObjToArr.js
Created May 21, 2022 18:28
Convert JSON Object ( Multi Dimensional ) Values to 1D Array
function ObjToArr(Obj){
if(typeof(Obj)=="object"){
let Arr = Object.keys(Obj).map(function(key) {
return " "+ObjToArr(Obj[key]); //join with comma separator
});
return Arr;
}else{
return Obj;
}
}
import random
#regular random
print("".join(["s","j"]*10))
#random random
print("".join([random.choice(["s","j"]) for i in range(20)]))
@yarliganfatih
yarliganfatih / Scroll_Loop.js
Created June 13, 2022 21:07
Auto Scroll Infinity Loop
function scrollLoop(delay=5000){ // delay for a animation duration
$('html, body').on('down', function () {
$(this).animate({ scrollTop: $(document).height() - $(window).height() }, delay);
$(this).trigger('up');
});
$('html, body').on('up', function () {
$(this).animate({ scrollTop: 0 }, delay);
$(this).trigger('down');
});
$('html, body').trigger('down'); // start with scroll down
@yarliganfatih
yarliganfatih / blockInputInjectionXSS.js
Last active November 6, 2022 11:23
a function to render data from harmful form inputs harmless (XSS)
const blockInputInjection = (input) => {
return input.replace(/<\/[^>]*>/g, "</div>").replace(/<[^>]*>/g, "<div hidden>");
}
// Sample Usage
harmfulInput = 'Hi, <b>Listen Me Now</b><br></br><img src="x"><br/><img src="y"/><script>alert("You have been hacked.");fetch("POST url datas");</script>';
harmlessInput = blockInputInjection(harmfulInput);
// Result
'Hi, <div hidden>Listen Me Now<div hidden><div hidden><div hidden><div hidden><div hidden><div hidden><div hidden>alert("You have been hacked.");fetch("POST url datas");<div hidden>'
@yarliganfatih
yarliganfatih / ucfirstTurkish.php
Last active November 7, 2022 13:25
ucfirst function with utf-8 turkish chars
<?
function iConverterTurkish($str, $dir="upper"){
$low = array('ı','i','ğ','ü','ş','ö','ç');
$up = array('I','İ','Ğ','Ü','Ş','Ö','Ç');
return $dir=="upper" ?
str_replace($low, $up, $str) :
str_replace($up, $low, $str) ;
}
function ucfirstTurkish($str) {
@yarliganfatih
yarliganfatih / deletedWpMsgFlood.js
Last active June 23, 2024 12:13
Resend the last deleted message
let reMessage = "You deleted that message but you cannot delete this message";
let controlLastNMessage = 5;
let msgSelector = "#main > div._amm9 > div > div._ajyl > div.x3psx0u.xwib8y2.xkhd6sd.xrmvbpv";
function isThereReMessageLast(num) {
if(num==0) return false;
if(document.querySelector(msgSelector + " > div:nth-last-child("+num+")").innerHTML.includes(reMessage)) {
return true;
}
return isThereReMessageLast(num-1);
@yarliganfatih
yarliganfatih / primitiveFunctionCSS.html
Created February 18, 2023 22:25
function structure with pure CSS
<style>
/* define a function */
.myFunction {
border: 3px solid rgba(var(--baseColorRGB));
background-color: rgba(var(--baseColorRGB), 0.2);
}
/* Global Variables (Default Parameters) */
:root {
--baseColorRGB: 255, 0, 0;
@yarliganfatih
yarliganfatih / inheritance.sql
Created February 24, 2023 17:09
Inheritance like at OOP with RDBMS
CREATE TABLE parentTable (
id int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
name varchar(50) NOT NULL,
createdAt datetime DEFAULT CURRENT_TIMESTAMP,
-- Dynamic Columns : own datas
visible tinyint(1) NOT NULL DEFAULT 1, -- default is required
expiredAt datetime DEFAULT NULL
);
@yarliganfatih
yarliganfatih / externalLinkTargetter.js
Created March 19, 2023 16:52
open all external links in new tab with jQuery
$("a[href*=http]").attr("target","_blank");
@yarliganfatih
yarliganfatih / showArrayAsTable.php
Last active April 3, 2023 12:10
showArrayAsTable
<?php
function showArrayAsTable($array, $parent=1) {
if ($parent) {
echo "<table>";
echo "<tr>";
foreach ($array[0] as $key => $value) {
echo "<td>{$key}</td>";
}
echo "</tr>";
}