Skip to content

Instantly share code, notes, and snippets.

View rubinchyk's full-sized avatar
🇮🇱

Alexey Rubinchyk rubinchyk

🇮🇱
View GitHub Profile
@rubinchyk
rubinchyk / bash
Created April 3, 2024 05:56
[Split any file by limit size] Split any file by limit size
split -b 3m Wireframes.fig Wireframes.fig
@rubinchyk
rubinchyk / index.js
Created February 7, 2024 11:55
[Search nearest element from another element] Search nearest element from another element
// example findNextPageBreak(startElement, "page-class")
function findNextPageBreak(startElement, classElement) {
let currentElement = startElement;
while (currentElement) {
if (currentElement.nextElementSibling && currentElement.nextElementSibling.classList.contains(classElement)) {
return currentElement.nextElementSibling;
}
currentElement = currentElement.nextElementSibling || currentElement.parentNode;
if (currentElement.tagName === 'BODY') {
@rubinchyk
rubinchyk / main.js
Created January 9, 2024 10:36
[Proxy object in javascript] Proxy object in javascript
// Data validation and input sanitization.
// Logging and debugging to track object interactions.
// Implementing access control and security checks.
// Creating virtual objects or interfaces.
// Implementing lazy loading for properties or data.
// Implementing change detection and reactivity (e.g., for UI frameworks).
// Caching expensive operations or results.
// Implementing object persistence and serialization.
// Implementing version control for objects or data.
// Intercepting method calls and customizing behavior.
@rubinchyk
rubinchyk / redme.md
Created December 5, 2023 12:42
[Open Google publisher extension]

// In Chrome console javascript: googletag.openConsole()

@rubinchyk
rubinchyk / main.js
Created November 13, 2023 12:03
[Is element visible] Is element visible
function isElementVisible(elem) {
const rect = elem.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
@rubinchyk
rubinchyk / gist:ec98b05d1704da382bc9458afa7db523
Last active November 23, 2023 15:06
SCP cheatsheet (Uploading/Downloading files)
**Upload a file to a remote server:**
```sh
scp /path/to/local/file username@remotehost:/path/to/remote/directory
```
@rubinchyk
rubinchyk / main.js
Last active November 15, 2023 08:42
[User location identification using Cloudflare] User location identification using Cloudflare
fetch('https://sttcdn.site.com/').then(response=>{
const country = response.headers.get('x-user-country');
const countryCodes = ['US', 'CA', 'JP', 'AU', 'SG', 'KR', 'TH', 'MY', 'NZ', 'BR', 'MX']
if (country && country.length === 2 && countryCodes.includes(country)) {
// Country in list
} else {
// Country not in list or no country value
}
}
).catch(error=>{
@rubinchyk
rubinchyk / main.js
Created September 28, 2023 14:06
[To change URL without page reload] To change URL without page reload
// If URL not finished on "/" - to add this "/" at the end without reload
if (window.location.href.charAt(window.location.href.length - 1) !== "/") {
window.history.replaceState({}, document.title, window.location.href + "/");
}
@rubinchyk
rubinchyk / main.js
Created September 21, 2023 07:47
[Intersection Observer - After scroll to block - do something] Intersection Observer - After scroll to block - do something
const observer = new IntersectionObserver(handleIntersection, { threshold: 0 });
function handleIntersection(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.backgroundColor = "#e74c3c";
} else {
entry.target.style.backgroundColor = "#3498db";
}
});
@rubinchyk
rubinchyk / Readme.md
Created August 13, 2023 05:27
Disable ssh passphrase in Termux

For SSH agent forwarding in Termux, you can try the following steps:

Start the SSH agent by running: eval $(ssh-agent)

Add your SSH private key to the agent using: ssh-add /path/to/your/private_key

Check if your SSH agent is running and has your key by using: ssh-add -l

If you encounter the passphrase prompt, enter your passphrase to add the key to the agent.