Skip to content

Instantly share code, notes, and snippets.

View 5iDS's full-sized avatar
💭
@ease with the Source

Max 5iDS

💭
@ease with the Source
View GitHub Profile
@5iDS
5iDS / getImageLightness.js
Created September 7, 2018 09:46
This function will convert each color to gray scale and return average of all pixels, so final value will be between 0 (darkest) and 255 (brightest).
function getImageLightness(imageSrc,callback) {
var img = document.createElement("img");
img.src = imageSrc;
img.style.display = "none";
document.body.appendChild(img);
var colorSum = 0;
img.onload = function() {
// create canvas
var Scheduler = (function () {
var tasks = [];
var minimum = 10;
var timeoutVar = null;
var output = {
add: function (func, context, timer, once) {
var iTimer = parseInt(timer);
context = context && typeof context === 'object' ? context : null;
if(typeof func === 'function' && !isNaN(iTimer) && iTimer > 0) {
tasks.push([func, context, iTimer, iTimer * minimum, once]);
@5iDS
5iDS / removeClass.js
Created April 28, 2017 08:10
Vanilla JS function to remove class from DOM elements
function removeClass(elements, myClass) {
// if there are no elements, we're done
if (!elements) { return; }
// if we have a selector, get the chosen elements
if (typeof(elements) === 'string') {
elements = document.querySelectorAll(elements);
}
@5iDS
5iDS / AddClass.js
Last active April 28, 2017 08:11
Vanilla JS function to add class on DOM elements.
function addClass(elements, myClass) {
// if there are no elements, we're done
if (!elements) { return; }
// if we have a selector, get the chosen elements
if (typeof(elements) === 'string') {
elements = document.querySelectorAll(elements);
}
@5iDS
5iDS / angular.preloadder.js
Created November 14, 2016 12:58
Directive for Preloader
/*
* Define UI Elements
* ------------------------------------------------*/
Application.Directives.uiPreloader = function () {
return {
restrict: 'AE',
scope: {},
transclude: true,
template: '<div data-ng-transclude></div>',
// ref: http://stackoverflow.com/a/1293163/2343
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
function CSVToArray( strData, strDelimiter ){
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || ",");
@5iDS
5iDS / WPSingleUserLoggin.php
Created June 8, 2016 10:11
Wordpress Single Login Session Per User
<?php
/*
Plugin name: Single user login
Plugin URI:
Description:
Author: Ben May
Author URI: http://benmay.org/wordpress/single-user-wordpress/
Version: 0.1
*/
if( !class_exists( 'WPSingleUserLoggin' ) )
function _validate_passport( passport ) {
//Utils._strict( [ String ], arguments ); // Thirdparty Function
//trim
passport = passport.replace( /(^\s+|\s+$)/g, '' );
var passport_characters = passport.split('');
if( passport_characters.length == 9 ) {
@5iDS
5iDS / PHP Week dates
Created March 23, 2016 11:46
Return beginning and end dates of current week.
function getStartAndEndDate($week, $year)
{
$time = strtotime("1 January $year", time());
$day = date('w', $time);
$time += ((7*$week)+1-$day)*24*3600;
$return[0] = date('Y-n-j', $time);
$time += 6*24*3600;
$return[1] = date('Y-n-j', $time);
return $return;
@5iDS
5iDS / S.A. Phone Number REGEX
Created February 28, 2016 21:49
Matches South African telephone/mobile numbers, with or without the country code. Can also include spaces or hyphens between values. Doesn't match brackets around the area code
/**
* Matches: 0111231234 | 011 123 1234 | 011-123-1234 | 0821231234 | +27821231234 | +2782-123-1234 | +2782 123 1234 | 27111231234 | 2711 123 1234 | 2711-123-1234
* Non-Matches: (011)1231234 | (+2711) 123 1234 | (011) 123-1234
/**/
var pattern2 = new RegExp(/^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$/);
console.log( pattern2.test( '+27134622241' ) );