Skip to content

Instantly share code, notes, and snippets.

@erratir
erratir / startJobAt.js
Last active April 27, 2024 03:35
start job at time
function startJobAt(hh, mm, code) {
var interval = 0;
var today = new Date();
var todayHH = today.getHours();
var todayMM = today.getMinutes();
if ((todayHH > hh) || (todayHH == hh && todayMM > mm)) {
var midnight = new Date();
midnight.setHours(24,0,0,0);
interval = midnight.getTime() - today.getTime() +
(hh * 60 * 60 * 1000) + (mm * 60 * 1000);
@erratir
erratir / index.html
Last active April 27, 2024 03:18
Event Emitter - паттерн: https://codepen.io/erratir/pen/dybEVPO
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<input type="text">
@erratir
erratir / MVP_example.js
Last active April 27, 2024 03:18
MVP (Model-View-Presenter) pattern example https://codepen.io/erratir/pen/xxKYevd
// https://codepen.io/erratir/pen/xxKYevd
// MVP — Presenter — создает модель и отображение, после чего отвечает за связывание их между собой:
// слушает изменения в каждом из них и вызывает обновления
// user-view.js
const render = (html) => {
const element = document.createElement(`div`);
element.innerHTML = html;
return element;
};
@erratir
erratir / MVC.js
Last active April 27, 2024 03:19
MVC (Model-View-Controller) pattern example https://codepen.io/erratir/pen/aboqxKZ
// https://codepen.io/erratir/pen/aboqxKZ
// MVC — Controller — создает модель и отображение и знакомит их между собой, дальше модель и отображение общаются напрямую
// user-view.js
const render = (html) => {
const element = document.createElement(`div`);
element.innerHTML = html;
return element;
};
@erratir
erratir / resize.js
Created September 4, 2019 14:34
Вписывает изображение в рамку
/**
* Вписывает изображение в рамку
* @param {object} frame Размеры рамки
* @param {object} image Размеры изображения
* @return {{width: number, height: number}}
*/
const resize = (frame, image) => {
const ratioWidth = 1 / (image.width / frame.width);
const ratioHeights = 1 / (image.height / frame.height);
@erratir
erratir / readme.md
Created August 27, 2019 14:28
Шпаргалка по Markdown
@erratir
erratir / chrome-utils.js
Created August 9, 2019 22:38
Get the current URL of the selected Chrome tab.
/**
* Get the current URL of the selected Chrome tab.
* Useful for Chrome/Chromium extensions.
* @return {Promise<any>}
*/
const getCurrentUrl = () => {
return new Promise((resolve, reject) => {
chrome.tabs.query({"active": true, "currentWindow": true}, (tabs) => {
resolve(tabs[0].url);
});
@erratir
erratir / chrome.md
Created August 9, 2019 12:03 — forked from 0xjjpa/chrome.md
Understanding Google Chrome Extensions

#Introduction

Developing Chrome Extensions is REALLY fun if you are a Front End engineer. If you, however, struggle with visualizing the architecture of an application, then developing a Chrome Extension is going to bite your butt multiple times due the amount of excessive components the extension works with. Here are some pointers in how to start, what problems I encounter and how to avoid them.

Note: I'm not covering chrome package apps, which although similar, work in a different way. I also won't cover the page options api neither the new brand event pages. What I explain covers most basic chrome applications and should be enough to get you started.

Table of Contents

  1. Understand the Chrome Architecture
  2. Understand the Tabs-Extension Relationship
  3. Picking the right interface for the job