Skip to content

Instantly share code, notes, and snippets.

View ivansky's full-sized avatar
😊
Wubba lubba dub dub!

Ivan Martianov ivansky

😊
Wubba lubba dub dub!
  • Armenia, Yerevan
View GitHub Profile
@ivansky
ivansky / download_telegram_cache_video.js
Created November 19, 2023 14:02
web telegram save cached video
// web telegram stream video from cache
// it probably uses shared/webworkers to save bytes chunks into cache storage
// so once video is fully cached it could be saved from cache to device
// browser could ask to allow parallel files downloads from web telegram domain, just allow it
(async function downloadCachedVideos() {
// global downloaded set is to prevent downloading videos were alreadt downloaded
window.downloaded = window.downloaded || new Set([])
function saveVideo(outname, dataArray) {
console.log(`Start downloading ${outname} with ${dataArray.length} chunks`)
@ivansky
ivansky / Catalog.tsx
Created May 10, 2022 14:03
Catalog.tsx
import React, { useEffect, useState } from "react";
import { render } from "react-dom";
import generateRandomWord from "random-words";
interface Data {
id: string;
data: string;
}
const DATA_CHUNK = 10;
@ivansky
ivansky / pathfinder.js
Created September 27, 2020 18:00
Pathfinder Calculation
const original = [1, 0, 0, 0, 1, 1, 0];
const relations = {
1: [1, 2, 6],
2: [1, 2],
3: [3, 5],
4: [4, 5, 6],
5: [3, 4, 5],
6: [1, 4, 6],
};
@ivansky
ivansky / example.jsx
Created April 26, 2019 13:33
React how to attach scroll event and measure DOM elements
import throttle from 'lodash/throttle';
class Component {
someSectionRef = null;
componentDidMount() {
// check window object existing, to not listen events in SSR
if(window) {
window.addEventListener('scroll', this.onScroll);
}
type ScrollDirection = 'vertical' | 'horizontal' | 'both';
/**
* It prevents default behaviour above the scrollable areas
* until it's in available scrollable direction.
*
* Example of checkScrollableElement:
*
* var cleanBlocking = (
* blockOverScroll(
@ivansky
ivansky / YADWord.php
Created May 26, 2015 11:25
Yandex Wordstat Collector
<?php
class YADWord {
private static $bind_region = array();
private static $bind_crc = array();
public $region_id = 213;
public $original;
@ivansky
ivansky / search_keyword_prepare.php
Created May 26, 2015 10:45
Search Keyword Prepare
<?php
/**
* Remove from string all invalid characters
* Leave only English, Russian, Turkish, Kazakh and Numbers
* @link http://www.unicode.org/charts/
* @param string $w
* @return string
*/
function prepareSearchKeyword($w){
@ivansky
ivansky / .htaccess
Last active February 12, 2019 10:09
PHP 304 Last Modified Example
# Bitrix Example
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
#RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
<?php
function test($str){
list($var) = explode('/', $str);
return $var;
}
function test2($str){
$var = array_shift(explode('/', $str));
return $var;