Skip to content

Instantly share code, notes, and snippets.

@Hibrix-net
Hibrix-net / sanitizeDuplicates.php
Last active April 21, 2020 15:02
PHP Function to correct the issue of having duplicate variables in the same string
<?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 '>')
@Hibrix-net
Hibrix-net / linear_gradients_opacity_filters.css
Last active April 11, 2020 09:17
Cross-browser 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 */
}
@Hibrix-net
Hibrix-net / CSS_regex.txt
Created April 21, 2020 07:37
Regex to match CSS rules and media queries
// 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 / icon-star-rating.html
Last active March 26, 2021 16:26
SVG based lightweight star rating system
<!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 / styling_placeholder.css
Created May 5, 2020 08:12
Styling input placholder (cross-browser)
/** 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 / nodejs-cheatsheet.js
Created June 10, 2020 18:51 — forked from LeCoupa/nodejs-cheatsheet.js
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@Hibrix-net
Hibrix-net / vanilla_trim_text_multiple_els.js
Last active August 1, 2020 14:21
JS vanilla trim text with iteration loop
// 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);
}
@Hibrix-net
Hibrix-net / simple_img_lazyloader.js
Created September 26, 2020 14:04
Simple image LazyLoader with jQuery.isOnScreen
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 / randomObjectPropertiesGenerator.js
Last active April 26, 2022 15:57
Random object properties generator (example with 5.000 properties: keys with 21 chars, values with 6 chars)
const obj = {};
for (let index = 0; index < 5000; index++) {
obj[makeid(21)] = makeid(6);
}
function makeid(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;