Skip to content

Instantly share code, notes, and snippets.

@spyesx
spyesx / jquery.removeClassRegEx.js
Last active September 16, 2015 20:08
jQuery.removeClassRegEx() remove classes by using a Regex
(function($)
{
$.fn.removeClassRegEx = function(regex)
{
return this.each(function()
{
var classes = $(this).attr('class');
if( !classes || !regex){ return false; }
@spyesx
spyesx / jquery.hasClassRegEx.js
Last active June 10, 2020 10:39
jQuery.hasClassRegEx() hasClass by using a Regex
(function($)
{
$.fn.hasClassRegEx = function(regex)
{
var classes = $(this).attr('class');
if(!classes || !regex){ return false; }
classes = classes.split(' ');
var len = classes.length;
// Allows random intervals that do not start with 1. So you can get a random number from 10 to 15 for example.
function randomIntFromInterval(min,max)
{
return Math.floor( Math.random()* ( max - min + 1 ) + min );
}
@spyesx
spyesx / truncate-text.css
Last active August 29, 2015 14:23
Truncate text in CSS to be SEO friendly
.trucate{
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@spyesx
spyesx / positive_negative.js
Last active October 26, 2022 14:29
Several methods to get a random positive or negative number
// Math.random() will give you a random decimal number between 0 and 1
// Just check if the number is greater than 0.5
// And apply -1 or 1 depending on the result
Math.random() < 0.5 ? -1 : 1;
// Math.random() will give you a random decimal number between 0 and 1
// Math.rand() of a Math.random() will give you an integer 0 or 1
// Use 0 or 1 as a result of a condition to use -1 or 1
Math.round(Math.random()) ? -1 : 1;
// /!\ NOTE : Can be used for any other values like 9 or 37 ; -2 or 2...
@spyesx
spyesx / string-to-slug.js
Last active March 15, 2024 12:05
String to slug in JS (wordpress sanitize_title)
var string_to_slug = function (str)
{
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/_,:;";
var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn------";
for (var i=0, l=from.length ; i<l ; i++)
@spyesx
spyesx / adblock-blacklist.css
Last active February 7, 2024 09:48
Class and ID to avoid because of AdBlock
.sidebar_newsletter_sign_up,
.sidebar_subscribe,
.sign-up-form-single,
.signup-form--header,
.signup-with-checkboxes,
.skinny-sign-up,
.slidedown-newsletter,
.small-newsletter,
.social-link-mail,
.social_newsletter_box,
@spyesx
spyesx / fix_node_sass
Created November 26, 2015 18:18
'libsass bindings not found. Try reinstalling 'node-sass'?
npm uninstall gulp-sass node-sass --save-dev
npm install gulp-sass node-sass --save-dev
@spyesx
spyesx / foundation.row-fullwidth.sass
Created January 1, 2016 17:19
Full width for Zurb Foundation
.row{
&.full-width{
width: 100%;
max-width: 100%!important; //might be needded depending on your settings
&>.column:first-child,
&>.columns:first-child{
padding-left: 0;
}
&>.column:last-child,
&>.columns:last-child{
@spyesx
spyesx / import_sql_from_file
Created February 3, 2016 17:31
Mysql commands to import SQL from a file
cd path/to/the/sql/
mysql -p mysqlUser -p
use dbName
source file.sql