Skip to content

Instantly share code, notes, and snippets.

View victorpavlov's full-sized avatar

Victor Pavlov victorpavlov

View GitHub Profile
@victorpavlov
victorpavlov / index.html
Created March 20, 2024 16:36 — forked from mrmoyeez/index.html
Slick Slider with auto play YouTube, Vimeo and HTML5 video
<section class="main-slider">
<div class="item youtube">
<iframe class="embed-player slide-media" width="100%" height="100%" src="https://www.youtube-nocookie.com/embed/9IfAjxkLn3w?enablejsapi=1&iv_load_policy=3&fs=0&rel=0&loop=1&start=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="item youtube">
<iframe class="embed-player slide-media" width="100%" height="100%" src="https://www.youtube.com/embed/IUUHhkYaKdo?enablejsapi=1&iv_load_policy=3&fs=0&rel=0&loop=1&start=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
@victorpavlov
victorpavlov / drupal8-media-entity-file-url.md
Created August 3, 2023 11:44 — forked from schnippy/drupal8-media-entity-file-url.md
Programmatically get file URL from a media entity entity reference field in Drupal 8

Programmatically get file URL from a media entity reference field in Drupal 8

I have a content type with a media (image) entity reference field (field_thumbnail_image) and I want to grab its file URL. For this, I need to load the media entity, isolate its source object using getSource, then load this source as a file entity so I can make a proper URL.

    // load the media entity from the media entity reference field
    $media_entity = Media::load($entity->field_thumbnail_image->target_id);

    // get the file source value for the media entity
 $source_value = $media_entity-&gt;getSource()-&gt;getSourceFieldValue($media_entity);
@victorpavlov
victorpavlov / prepare-commit-msg.sh
Created April 30, 2020 11:50 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@victorpavlov
victorpavlov / mapOrder.js
Last active November 22, 2019 10:42 — forked from ecarter/mapOrder.js
Order an array of objects based on another array order
/**
* Sort array of objects based on another array
*/
const mapOrder = (array, order, key) => {
array.sort((a, b) => {
const A = a[key];
const B = b[key];
return order.indexOf(A) > order.indexOf(B) ? 1 : -1;
@victorpavlov
victorpavlov / simple-pagination.js
Created October 10, 2019 11:28 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@victorpavlov
victorpavlov / slugify.js
Created October 3, 2018 12:19 — forked from hagemann/slugify.js
Slugify makes a string URI-friendly
function slugify(string) {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
@victorpavlov
victorpavlov / youtubeID.js
Created March 5, 2018 13:08 — forked from takien/youtubeID.js
Get YouTube ID from various YouTube URL using JavaScript
/**
* Get YouTube ID from various YouTube URL
* @author: takien
* @url: http://takien.com
* For PHP YouTube parser, go here http://takien.com/864
*/
function YouTubeGetID(url){
var ID = '';
url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-landscape-up {
@media (min-width: 900px) { @content; }
}
@mixin for-desktop-up {
@mixin for-size($range) {
$phone-upper-boundary: 600px;
$tablet-portrait-upper-boundary: 900px;
$tablet-landscape-upper-boundary: 1200px;
$desktop-upper-boundary: 1800px;
@if $range == phone-only {
@media (max-width: #{$phone-upper-boundary - 1}) { @content; }
} @else if $range == tablet-portrait-up {
@media (min-width: $phone-upper-boundary) { @content; }
@victorpavlov
victorpavlov / menu-main.html.twig
Created September 30, 2016 13:02 — forked from mortendk/menu-main.html.twig
svg inside a link in drupal menus
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}