Skip to content

Instantly share code, notes, and snippets.

@Hibrix-net
Hibrix-net / simple_img_lazyloader.js
Created Sep 26, 2020
Simple image LazyLoader with jQuery.isOnScreen
View simple_img_lazyloader.js
var imagesBlock = jQuery('#imagesBlock');
var sliderVisible = imagesBlock.isOnScreen(0, -1); // https://github.com/moagrius/isOnScreen
if (typeof jQuery().isOnScreen === 'function' && !sliderLoaded && sliderVisible) {
var imgs = imagesBlock.find("img");
for(var i = 0; i < imgs.length; i++){
var img = jQuery(imgs[i]);
img.attr("src", img.attr("ref-src")); // replace 'ref-src' attribute with 'src'
}
sliderLoaded = true;
}
@Hibrix-net
Hibrix-net / vanilla_trim_text_multiple_els.js
Last active Aug 1, 2020
JS vanilla trim text with iteration loop
View vanilla_trim_text_multiple_els.js
// Trim to 15 words
document.addEventListener("DOMContentLoaded", function() {
var myElements = document.getElementsByClassName('elemsToTrim');
// Real improved for loop: https://stackoverflow.com/questions/31352367/how-can-i-make-sublime-texts-improved-native-for-loop-increment-like-a-normal#answer-31352368
for (var i = 0, l = myElements.length; i < l; ++i) {
delay(i);
}
View nodejs-cheatsheet.js
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@Hibrix-net
Hibrix-net / styling_placeholder.css
Created May 5, 2020
Styling input placholder (cross-browser)
View styling_placeholder.css
/** Styling input placholder (cross-browser pseudo-classes and pseudo-elements) **/
::-webkit-input-placeholder { /* WebKit browsers: Chrome/Opera/Safari; Blink/Edge */
color: #939292;
font-size: 15px;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #939292;
font-size: 15px;
}
@Hibrix-net
Hibrix-net / icon-star-rating.html
Last active Mar 26, 2021
SVG based lightweight star rating system
View icon-star-rating.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en" xml:lang="en">
<head>
<meta charset="UTF-8">
<title>4.2 - 2.6</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style type="text/css">
/* Empty part of stars */
@Hibrix-net
Hibrix-net / CSS_regex.txt
Created Apr 21, 2020
Regex to match CSS rules and media queries
View CSS_regex.txt
// Source: https://stackoverflow.com/questions/36910664/recursive-subroutine-regex-to-match-css-media-queries#answer-36911319
@media print\b[^{]*({((?:[^{}]+|(?1))*)})
// to match i.e.:
@media print {
.post {
margin: 6.6rem 0px 8.8rem;
padding-bottom: 2.2rem;
border-bottom: #eaecee
}
@Hibrix-net
Hibrix-net / linear_gradients_opacity_filters.css
Last active Apr 11, 2020
Cross-browser linear gradients & opacity filters (CSS)
View linear_gradients_opacity_filters.css
gradient {
background: linear-gradient(to top, #DF6210 0%, #F99A5A 100%) repeat scroll 0 0 rgba(0, 0, 0, 0); /* W3C */
background: -moz-linear-gradient(top, #F99A5A 0%,#DF6210 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#DF6210), color-stop(100%,#F99A5A)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #F99A5A 0%,#DF6210 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #F99A5A 0%,#DF6210 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #F99A5A 0%,#DF6210 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#F99A5A', endColorstr='#DF6210',GradientType=0 ); /* IE6-9 */
}
View GIT-common-commands.md

Common

git status
git reset --hard
git clean -f
git fetch
git fetch -p
git checkout feature/branch_name
git pull origin feature/branch_name

Push branch to remote

@Hibrix-net
Hibrix-net / sanitizeDuplicates.php
Last active Apr 21, 2020
PHP Function to correct the issue of having duplicate variables in the same string
View sanitizeDuplicates.php
<?php
/*
* Function to correct the issue of having duplicate variables in the same string
*
* Example usage:
* $listWords['baggage_loss_amount'] = sanitizeDuplicates($listWords['baggage_loss_amount'], 'AMOUNT&&', array('3.000', '350', '700'));
* $listWords['health_search_amount'] = sanitizeDuplicates($listWords['health_search_amount'], 'AMOUNT&&', array('2.000', '15.000'));
*
* @param string $string (current string to filter)
* @param string $duplicatedVar (duplicated variable name without closures: '<' and '>')