Skip to content

Instantly share code, notes, and snippets.

@theStrangeAdventurer
theStrangeAdventurer / .js
Created November 5, 2019 22:27
REACT REDUX: snippet mapStateToProps changePage connected-react-router
import { push } from 'connected-react-router';
import { bindActionCreators } from 'redux';
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
changePage: () => push('/url-to-another-page')
},
dispatch
);
@theStrangeAdventurer
theStrangeAdventurer / .js
Created March 13, 2019 17:19
multer and gm - upload and save multiple images with varios resolutions (nodejs, express)
import multer from 'multer'
import passportManager from '../../config/passport'
import fs from 'fs'
import gm from 'gm'
import mime from 'mime'
import 'array-foreach-async'
const storage = multer.diskStorage({
destination: function (req, file, cb) {
const { params: { folder, subfolder } } = req
@theStrangeAdventurer
theStrangeAdventurer / .css
Created March 7, 2019 08:03
Scroll down animation css (streak animation)
.image-down-arrows span{
position: relative;
display: block;
width: 3px;
height: 8rem;
background-color: #fff;
animation: scrolldown 3.5s infinite;
}
@keyframes scrolldown {
@theStrangeAdventurer
theStrangeAdventurer / .css
Created March 5, 2019 08:12
Shake infinite animation
.element {
-webkit-animation: shake;
animation: shake;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-duration: 4s;
animation-duration: 4s;
-webkit-animation-timing-function: cubic-bezier(0.36, 0.07, 0.19, 0.97);
animation-timing-function: cubic-bezier(0.36, 0.07, 0.19, 0.97);
-webkit-animation-delay: 4s;
@theStrangeAdventurer
theStrangeAdventurer / .js
Created February 28, 2019 22:59
Recursive images optimization with multiple formats (JPG and WEBP) and multiple resolutions
var gulp = require('gulp');
var responsive = require('gulp-responsive');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('images', function () {
return gulp.src('src/images/**/*')
.pipe($.responsive({
'**/*.{jpg,jpeg,png}': [
{
@theStrangeAdventurer
theStrangeAdventurer / .js
Last active July 17, 2019 10:00
Back to top vanilla JS button (Конпка "Наверх", Ванильный js)
class Upstair {
constructor(options={}) {
this.duration = options.duration || 350
this.callback = options.callback || ((f) => f)
this.scrollStartHeight = options.scrollStartHeight || 100
this.btnColor = options.btnColor || '#444'
this.btnStrokeWidth = options.btnStrokeWidth || 2
this.stickySelector = options.stickySelector || null
this.html = options.html || this.getDefaultBtnHtml()
this.defaultStyle = {
@theStrangeAdventurer
theStrangeAdventurer / .php
Last active July 31, 2019 07:04
БИТРИКС: Очистка файлов в папке upload - Выборка используемых файлов В элементах выбранных инфоблоках а также в выбранных свойствах этих элементов.
<?php require( $_SERVER[ "DOCUMENT_ROOT" ] . "/bitrix/modules/main/include/prolog_before.php" );
use Bitrix\Main\Loader;
/**
* Вернет массив файлов в директории, для любой вложенности
*
* @param $dir
* @param array $results
* @return array
@theStrangeAdventurer
theStrangeAdventurer / .php
Created December 11, 2018 14:13
new_developers
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
set_time_limit(0);
define('XML_DIR', 'xml');
define('UPLOAD_DIR', 'upload_images');
define('AVITO_FID', 'https://autoload.avito.ru/format/New_developments.xml');
@theStrangeAdventurer
theStrangeAdventurer / .sh
Created August 31, 2018 09:44
Download site bash script
#!/bin/bash
#-r — указывает на то, что нужно рекурсивно переходить по ссылкам на сайте, чтобы скачивать страницы.
#-k — используется для того, чтобы wget преобразовал все ссылки в скаченных файлах таким образом, чтобы по ним можно было переходить на локальном компьютере (в автономном режиме).
#-p — указывает на то, что нужно загрузить все файлы, которые требуются для отображения страниц (изображения, css и т.д.).
#-l — определяет максимальную глубину вложенности страниц, которые wget должен скачать (по умолчанию значение равно 5, в примере мы установили 7). В большинстве случаев сайты имеют страницы с большой степенью вложенности и wget может просто «закопаться», скачивая новые страницы. Чтобы этого не произошло можно использовать параметр -l.
#-E — добавлять к загруженным файлам расширение .html.
#-nc — при использовании данного параметра существующие файлы не будут перезаписаны. Это удобно, когда нужно продолжить загрузку сайта, прерванную в предыдущий раз
# Переменные цветов >>
@theStrangeAdventurer
theStrangeAdventurer / .php
Created June 20, 2018 10:43
get subway stations and cities of Russia superjob API
<?php
class CitySubway
{
protected static $apiCitiesUrl = "https://api.superjob.ru/2.0/towns/";
protected static $apiMetroListUrl = "https://api.superjob.ru/2.0/suggest/town/:id_town/metro/all/";
public static function getAllCities()
{
$params = [