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
function array_chunk(input, size, preserve_keys) {
// discuss at: http://phpjs.org/functions/array_chunk/
// original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
// improved by: Brett Zamir (http://brett-zamir.me)
// note: Important note: Per the ECMAScript specification, objects may not always iterate in a predictable order
// example 1: array_chunk(['Kevin', 'van', 'Zonneveld'], 2);
// returns 1: [['Kevin', 'van'], ['Zonneveld']]
// example 2: array_chunk(['Kevin', 'van', 'Zonneveld'], 2, true);
// returns 2: [{0:'Kevin', 1:'van'}, {2: 'Zonneveld'}]
// example 3: array_chunk({1:'Kevin', 2:'van', 3:'Zonneveld'}, 2);
@5iDS
5iDS / Crossbrowser RGBA
Created December 29, 2014 09:49
Crossbrowser RGBA and Prevention of Opacity Propagation
/**
* Crossbrowser RGBA and Prevention of Opacity Propagation
* Created by Martin Ivanov
* http://wemakesites.net
*/
.outer
{
position: absolute;
top: 24px;
@5iDS
5iDS / CSS3 Tooltips
Created December 29, 2014 09:52
CSS3 Tooltips
/**
* CSS3 Tooltips
* Created by Martin Ivanov
* http://wemakesites.net
*/
/* the tooltip will be applied to any element, containing data-title attribute */
[data-title]
{
position: relative;
@5iDS
5iDS / center_crop_image
Created January 22, 2015 08:05
Center and crop images with a single line of CSS
img {
object-fit: cover;
}
@5iDS
5iDS / AutoUpdater
Created June 26, 2015 02:59
PHP Auto Updating Class
<?php
// Prevent loading this file directly and/or if the class is already defined
if ( ! defined( 'ABSPATH' ) || class_exists( 'WPGitHubUpdater' ) || class_exists( 'WP_GitHub_Updater' ) )
return;
/**
*
*
* @version 1.6
@5iDS
5iDS / getDates
Created November 22, 2015 01:10
Get weeks of year for given period
Date.prototype.addDays = function(days) {
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
};
// Source: http://stackoverflow.com/questions/497790
function convertDate ( d ) {
// Converts the date in d to a date-object. The input can be:
// a date object: returned without modification
@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' ) );
@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;
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 / 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' ) )