Skip to content

Instantly share code, notes, and snippets.

@jordansinger
jordansinger / iPod.swift
Created July 27, 2020 21:19
Swift Playgrounds iPod Classic
import SwiftUI
import PlaygroundSupport
struct iPod: View {
var body: some View {
VStack(spacing: 40) {
Screen()
ClickWheel()
Spacer()
}
@veteran29
veteran29 / arma-launcher-script.js
Last active May 10, 2024 00:34
Arma Launcher HMTL Modlist to JS
function getWorkshopIdFromUrl(url) {
return url.split('id=')[1];
};
function getNodeType(node) {
return node.getAttribute('data-type')
};
function getNodeDataValue(node) {
switch(getNodeType(node)) {
@veteran29
veteran29 / array_functions.js
Last active May 10, 2024 00:34
ES2015 Snippets
const createRange = (start, amount) =>
Array.from(Array(amount), (_, idx) => start + idx);
/**
* @param {array} array
*/
const uniqueArray = array => [...new Set(array)];
/**
* @param {array} array
@nijikokun
nijikokun / doc.md
Last active May 10, 2024 00:33
Building Javascript Frontend / Backend Applications

Document for the best design choices you can make for your software.

Terminology

  • DDD - [Domain Driven Design][ddd-wikipedia]
  • FF or FTF - Function First Design, or File-type First Design is structuring your application by it's function before the files such as a directory named components containing all component files.

File Structure

Structuring applications is hard, here are a few resources to help.

@vova-learn
vova-learn / debounce.js
Created April 10, 2023 09:02
Функция debounce для устранения дребезга
// Функция взята из интернета и доработана
// Источник - https://www.freecodecamp.org/news/javascript-debounce-example
function debounce (callback, timeoutDelay = 500) {
// Используем замыкания, чтобы id таймаута у нас навсегда приклеился
// к возвращаемой функции с setTimeout, тогда мы его сможем перезаписывать
let timeoutId;
return (...rest) => {
// Перед каждым новым вызовом удаляем предыдущий таймаут,
@vova-learn
vova-learn / script.js
Last active May 10, 2024 00:32
Ctrl+keyCode (ctrl+F)
document.addEventListener(`keydown`, (evt) => {
const keyCodeF = 70;
const isEnterAndCtrl = evt.keyCode === keyCodeF && evt.ctrlKey;
if (isEnterAndCtrl) {
evt.preventDefault();
console.log(evt.keyCode);
}
});
@vova-learn
vova-learn / utm-parse.js
Created June 9, 2020 07:08
Парсинг UTM-меток
const getParameterByName = (name) => {
const utmName = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
const regex = new RegExp("[\\?&]" + utmName + "=([^&#]*)");
const result = regex.exec(location.search);
return result === null ? "" : decodeURIComponent(result[1].replace(/\+/g, " "));
}
getParameterByName('utm_term');
@vova-learn
vova-learn / js-convert-sec-to-hours.js
Last active May 10, 2024 00:32
Convert seconds to HH:MM:SS / Конвертация секунд в ЧЧ:ММ:СС
const convertTime = {
part: 60,
convert(inSec) {
const inMin = Math.floor(inSec / this.part);
const hour = Math.floor(inMin / this.part);
const min = Math.round((inMin / this.part - Math.floor(inMin / this.part)) * this.part);
const sec = Math.round((inSec / this.part - inMin) * this.part);
return `${this.checkZero(hour)}:${this.checkZero(min)}:${this.checkZero(sec)}`;
},
@vova-learn
vova-learn / js-get-max-value-array.js
Last active May 10, 2024 00:32
We get two maximum values ​​from the array while maintaining with index / Получить два максимальных значения массива с сохранением индекса
const carsSale = [
{
brand: `KIA`,
model: `Ceed`,
miles: 32080,
}, {
brand: `TESLA`,
model: `MODEL X`,
miles: 2080,
}, {