Skip to content

Instantly share code, notes, and snippets.

@xoxexxx
xoxexxx / index.js
Created October 3, 2025 13:13
resizeObserver React.js
function ShiftWindowTranslate() {
const parentRef = useRef(null);
const [parentWidth, setParentWidth] = useState(0);
const shiftCSSTranslate = (px) => {
return { transform: `translateX(${parentWidth - px}px)` };
};
useEffect(() => {
const parent = parentRef.current;
@xoxexxx
xoxexxx / index.js
Created July 23, 2025 14:51
Device Detect
function detectDevice(userAgent) {
const deviceInfo = {
platform: "Unknown",
device: "Unknown",
browser: "Unknown",
};
if (/iPhone/.test(userAgent)) {
deviceInfo.platform = "📱 iOS";
deviceInfo.device = "iPhone";
@xoxexxx
xoxexxx / insertSpaces
Created March 11, 2025 22:03
cindex.js
function insertSpaces(input) {
const rawValue = input.value.replace(/\D/g, '');
const formattedValue = rawValue.replace(/(.{4})/g, '$1 ');
input.value = formattedValue.trim();
}
@xoxexxx
xoxexxx / index.js
Last active February 4, 2025 22:21
telegraf
# inline keyboard button and send photo
const keyboard = Markup.inlineKeyboard([
[Markup.button.callback('first-value-column', 'first-key')],
[Markup.button.callback('second-value-column', 'second-key')],
[Markup.button.callback('first-value-row', 'first-key-row'), Markup.button.callback('second-value-row', 'second-key-row')],
]);
bot.telegram.sendMessage(chat_id, message, {
parse_mode: "HTML",
reply_markup: keyboard.reply_markup
@xoxexxx
xoxexxx / index.js
Last active February 2, 2025 17:37
js form scripts
# insert spaces cardnumber
function insertSpaces(input) {
const rawValue = input.value.replace(/\D/g, '');
const formattedValue = rawValue.replace(/(.{4})/g, '$1 ');
input.value = formattedValue.trim();
}
# input keypress only number
<input onkeypress="const isNumber = /^[0-9]$/.test(event.key); if (!isNumber) { event.preventDefault(); return}" />
@xoxexxx
xoxexxx / iso-image.sh
Created May 3, 2024 06:48
create iso image for USB Drive
read -p "Enter path to ISO: " iso
read -p "disk: " disk
sudo dd if=$iso of=/dev/$disk conv=fsync bs=4M
@xoxexxx
xoxexxx / format_usb-drive.sh
Last active May 3, 2024 06:49
format usb drive
read -p "disk: " disk
sudo dd if=/dev/zero of=/dev/$disk bs=1024k count=2048
@xoxexxx
xoxexxx / debounce.js
Last active January 17, 2024 22:28
debounce
function debounce(func, timeout = 300){
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
function saveInput(){
console.log('Saving data');
}
@xoxexxx
xoxexxx / dns.sh
Created October 26, 2023 19:02
change dns
#!/bin/bash
filename="/etc/resolv.conf"
sudo chmod 777 $filename
echo -n "" > $filename
echo "#Generated by NetworkManager" | tee -a $filename
echo "nameserver 208.67.222.222" | tee -a $filename
echo "nameserver 208.67.220.220" | tee -a $filename
sudo chmod +x $filename