Skip to content

Instantly share code, notes, and snippets.

View caracal7's full-sized avatar

Dmitrii Vasilev caracal7

  • This planet
View GitHub Profile
@caracal7
caracal7 / outbound-email-with-cloudflare.md
Created October 16, 2024 17:15 — forked from irazasyed/outbound-email-with-cloudflare.md
Using Gmail SMTP with Cloudflare Email Routing: A Step-by-Step Guide

Using Gmail SMTP with Cloudflare Email Routing: Step-by-Step Guide

Learn how to send emails through Gmail SMTP with Cloudflare Email Routing in this comprehensive guide.

Step 1: Enable 2-Factor Authentication

To proceed with this method, ensure that you have enabled two-factor authentication for your Google account. If you haven't done so already, you can follow the link to set it up → Enable 2FA in your Google account.

Step 2: Create an App Password for Mail

@caracal7
caracal7 / what-forces-layout.md
Created September 18, 2024 13:02 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@caracal7
caracal7 / from-now.js
Created January 20, 2024 13:07 — forked from davidrleonard/from-now.js
moment.fromNow() implemented in vanilla JavaScript as a simple, standalone function. Runs in the browser. No dependencies required.
/**
* Implements all the behaviors of moment.fromNow(). Pass a
* valid JavaScript Date object and the method will return the
* time that has passed since that date in a human-readable
* format. Passes the moment test suite for `fromNow()`.
* See: https://momentjs.com/docs/#/displaying/fromnow/
*
* @example
*
* var pastDate = new Date('2017-10-01T02:30');
@caracal7
caracal7 / string.hashcode.js
Created March 29, 2023 12:10 — forked from hyamamoto/ string.hashcode.js
JavaScript Implementation of String.hashCode() .
/**
* Returns a hash code for a string.
* (Compatible to Java's String.hashCode())
*
* The hash code for a string object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using number arithmetic, where s[i] is the i th character
* of the given string, n is the length of the string,
* and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
@caracal7
caracal7 / mysql_escape_string.js
Last active February 6, 2020 15:53 — forked from sstur/mysql_escape_string.js
Escape string for MySQL
const mysql_escape_string = str => str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, ch => {
switch (ch) {
case "\0": return "\\0";
case "\x08": return "\\b";
case "\x09": return "\\t";
case "\x1a": return "\\z";
case "\n": return "\\n";
case "\r": return "\\r";
case "\"":
case "'":
@caracal7
caracal7 / scroll.js
Last active June 15, 2019 09:48 — forked from thetutlage/scroll.js
Scroll to the bottom of an element with smooth animation - Pure Javascript
function scrollTo (element, duration) {
if (!element) return;
var target = element.scrollHeight;
target = Math.round(target);
duration = Math.round(duration);
if (duration < 0) return false;
if (duration === 0) {
element.scrollTop = target;
return true;
}
@caracal7
caracal7 / json-syntax-highlighter.js
Last active August 27, 2019 10:19 — forked from twilson63/json-syntax-highlighter.js
Javascript JSON syntax highlight
const isISODate = date => new Date(date) !== "Invalid Date" && !isNaN(new Date(date)) && date == new Date(date).toISOString();
const syntaxHighlight = json => {
json = JSON.stringify(json, null, ' ')
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
var result = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = '';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@caracal7
caracal7 / objectpath.js
Created March 24, 2019 19:18 — forked from alanthai/objectpath.js
Object Path
// Gets value of object given a string path
// Example: objectPathGet({a: {b: {c: {d: "hello"}}}}, "a.b.c.d") // returns "hello"
function objectPathGet(obj, path, _default) {
try {
var keys = path.split(".");
return (function _get(obj) {
var child = obj[keys.shift()];
return keys.length ? _get(child) : child;
})(obj);
} catch(err) {
@caracal7
caracal7 / async-foreach.js
Created March 24, 2019 14:43 — forked from atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)