Skip to content

Instantly share code, notes, and snippets.

@abdullahoguk
abdullahoguk / JS trigger input change event.js
Created April 5, 2022 11:58
JS trigger input change event when value modified programmatically
/*
JS ile input value değiştirildiğinde input için change eventini trigger et
JS trigger input change event when value modified programmatically
eg: input.value="bla bla"
*/
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(prevInput), 'value');
Object.defineProperty(prevInput, 'value', {
set: function(t) {
//return descriptor.set.apply(this, arguments);
@abdullahoguk
abdullahoguk / makePairs.js
Last active January 23, 2022 21:25
Split the array into pairs in JavaScript wit Array Reduce
var arr = [1,5,6,7,4,8,5];
arr.reduce((previous, current, index, array)=>{
return index%2==0 ? [...previous, array.slice(index,index+2)] : previous
},[])
//>[[1,5],[6,7],[4,8],[5]]
@abdullahoguk
abdullahoguk / fetch.js
Last active November 16, 2021 10:40
Fetch Js - Async and retry
const fetch = require("node-fetch");
async function fetchAsync (url, type) {
const init = {
headers: {
"content-type": "text/html;charset=UTF-8",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"
}
}
@abdullahoguk
abdullahoguk / fixTrChars.js
Created October 15, 2021 16:30
UTF-8 Display to Text (Turkish) with multiple replace in JavaScript
/*bozuk türkçe karakter düzeltme*/
function fixTrChars(str) {
var karakterler = [{'ı': 'ı'}, {'ç': 'ç'}, {'ÅŸ': 'ş'}, {'ö': 'ö'}, {'ü': 'ü'}, {'ÄŸ': 'ğ'}, { 'Ä°': 'İ'}, { 'Ç': 'Ç'}, { 'ÅŸ': 'Ş'},{'Ö':'Ö'}, {'Ãœ': 'Ü'}, {'ÄŸ': 'Ğ'}];
return karakterler.reduce(function (accum, t) {
return accum.replace(new RegExp(Object.keys(t)[0], 'g'), t[Object.keys(t)[0]]);
}, str);
}
@abdullahoguk
abdullahoguk / ago.js
Last active September 29, 2021 08:34
Time Ago JavaScript Function in Turkish
/*
Tiny time ago JS function localized into Turkish
SOURCE:
https://github.com/odyniec/tinyAgo-js
*/
/*------------- USAGE --------------------*/
ago(new Date("2021-09-26"))
/*3 gün önce*/
@abdullahoguk
abdullahoguk / commandset.md
Last active January 6, 2023 09:03
CommandSet

PDF REDUCE

  • gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
  • ps2pdf input.pdf output.pdf

Make gifs with imagemagick

convert -delay 100 -loop 0 *.jpeg animatedGIF.gif

@abdullahoguk
abdullahoguk / lazyload.js
Last active March 4, 2021 08:19
Vanilla Lazy Load
//source: https://www.merixstudio.com/blog/lazy-loading-pure-javascript/
function lazyLoadInit(){
let lazyImages = [].slice.call(document.querySelectorAll("img.lazy"));
let active = false;
var treshold = 100;
const lazyLoad = function() {
if (active === false) {
active = true;
setTimeout(function() {
@abdullahoguk
abdullahoguk / onLoadAdder.js
Created February 25, 2021 07:17
Append to "onload" function in JS
//source: https://ehikioya.com/working-with-javascript-onload-functions/
//Add function to onload without overriding previously defined onloads
AddOnLoadEvent(yourFunction);
function AddOnLoadEvent(functionX) {
var oldonloadevent = window.onload;
if (typeof window.onload != 'function') {
window.onload = functionX;
}
else {
@abdullahoguk
abdullahoguk / loadScript.js
Created February 25, 2021 06:52
Load scripts dynamically in JS
//Source: https://aaronsmith.online/easily-load-an-external-script-using-javascript/
//-------------------PROMISE METHOD --------------------------
/**
* Loads a JavaScript file and returns a Promise for when it is loaded
*/
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.type = 'text/javascript'
@abdullahoguk
abdullahoguk / my-componenet.js
Last active December 12, 2020 15:12
Web Componenets
const template = document.createElement("template");
template.innerHTML = `
<style>
:host{
--light: #b0ade0;
--main: #36308aff;
--dark: #686778ff;
--gr1:linear-gradient(90deg, var(--darker), var(--main));
font-family: 'Changa', sans-serif;
display:block;