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);
(function ($, window, delay) {
// http://jsfiddle.net/AndreasPizsa/NzvKC/
var theTimer = 0;
var theElement = null;
var theLastPosition = {x:0,y:0};
$('[data-toggle]')
.closest('li')
.on('mouseenter', function (inEvent) {
if (theElement) theElement.removeClass('open');
window.clearTimeout(theTimer);
function delay(callback, ms) {
var timer = 0;
return function() {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
}
@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;
// e.g: @include truncate(14px, 1.4, 10)
@mixin truncate($font-size: 16px, $line-height: 1.5, $lines-to-show: 3) {
display: block; // Fallback for non-webkit
display: -webkit-box;
max-width: 100%;
max-height: $font-size*$line-height*$lines-to-show; // Fallback for non-webkit
line-height: $line-height;
-webkit-line-clamp: $lines-to-show;
-webkit-box-orient: vertical;
@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\/)/);