Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
yarliganfatih / printAllMethodsOfClass.java
Created May 31, 2024 21:43
print all methods, including inherited methods for testing
public class Main {
public static void printMethodNames(Class<?> clazz) {
// Get all methods of the class including inherited methods
Method[] methods = clazz.getMethods();
// Print method names and parameter types
for (Method method : methods) {
System.out.print(method.getName() + "(");
Class<?>[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
@yarliganfatih
yarliganfatih / writer.py
Last active December 17, 2023 19:31
printing codes in blocks with commands
import keyboard
import time
def readFile(path):
with open(path, 'r') as file:
arr = file.readlines()
return arr
codeLines = readFile("main.js")
@yarliganfatih
yarliganfatih / populate.sql
Created April 11, 2023 02:11
populate on SQL like NoSQL (with joined table)
SELECT
pt.*,
CONCAT(
'[',
GROUP_CONCAT(
JSON_OBJECT(
'id', ct.id,
'name', ct.name
)
),
@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>";
}
@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 / 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 / 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 / deletedWpMsgFlood.js
Last active December 4, 2022 22:06
Resend the last deleted message
let deletedQuery = "deleted";
let reMessage = "You deleted that message but you cannot delete this message";
function controlLoop(){
try {
// If last message is deleted
if(document.querySelector("#main > div._2gzeB > div > div._33LGR > div.n5hs2j7m.oq31bsqd.gx1rr48f.qh5tioqs > div:nth-last-child(1) > div > div.ItfyB._3nbHh > div._22Msk > div.p357zi0d.ktfrpxia.nu7pwgvd.fhf7t426.sap93d0t.r15c9g6i > div.tvf2evcx.m0h2a7mj.lb5m6g5c.j7l1k36l.ktfrpxia.nu7pwgvd.gjuq5ydh.kiiy14zj.j4enbv94 > div").innerHTML.includes(deletedQuery)){
sendMessage(reMessage);
console.log("resent message");
}
}catch(err) {
@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 / 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>'