Skip to content

Instantly share code, notes, and snippets.

View KryptikOne's full-sized avatar
:octocat:
Slaying Code Dragons ⚔️🐲🧑🏽‍💻

Jason KryptikOne

:octocat:
Slaying Code Dragons ⚔️🐲🧑🏽‍💻
View GitHub Profile
@KryptikOne
KryptikOne / common-regex.php
Last active October 6, 2015 18:48 — forked from nerdsrescueme/regex.txt
Common Regex
Perl and PHP Regular Expressions
PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.
All Major Credit Cards
This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.
//All major credit cards regex
'/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/'
@KryptikOne
KryptikOne / common-regex.js
Created August 5, 2015 21:03
Common JavaScript Regular Expressions
// Digits
/^[0-9]+$/
// Alphabetic Characters
/^[a-zA-Z]+$/
// Alpha-Numeric Characters
/^[a-zA-Z0-9]+$/
// Date (MM/DD/YYYY)/(MM-DD-YYYY)/(MM.DD.YYYY)/(MM DD YYYY)
@KryptikOne
KryptikOne / wp-query-args-list.php
Created June 25, 2015 19:21
WP_Query Args List
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@KryptikOne
KryptikOne / attribute-selectors-quick-reference.css
Last active August 29, 2015 14:23
Attribute Selectors Quick Reference
[rel="external"] ---------------- Attribute EXACTLY matches a certain value
[rel*="external"] --------------- Attribute CONTAINS certain value somewhere
[rel^="external"] --------------- Attribute BEGINS WITH certain value
[rel$="external"] --------------- Attribute ENDS WITH certain value
[rel~="external"] --------------- Attribute is WITHIN Space Separated List (e.x.-compound classes)
[rel|="external"] --------------- Attribute is WITHIN Dash Separated List (e.x.-compound classes)
[title="one"][rel^="external"] -- Multiple Attribute Matches
@KryptikOne
KryptikOne / get-element-position.js
Last active August 29, 2015 14:17
Get the position of an element.
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
(function($, window, undefined) {
var InfiniteScroll = function() {
this.initialize = function() {
this.setupEvents();
};
this.setupEvents = function() {
$(window).on(
'scroll',
this.handleScroll.bind(this)
@KryptikOne
KryptikOne / switch-replacement.js
Created November 10, 2014 06:44
Replacement for the switch statement, much cleaner and more elegant.
function doSomething (condition) {
var stuff = {
'one': function () {
return 'one';
},
'two': function () {
return 'two';
},
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if ( supportsSVG() ) {
document.documentElement.className += ' svg';
} else {
document.documentElement.className += ' no-svg';
var imgs = document.getElementsByTagName('img'),
dotSVG = /.*\.svg$/;
@KryptikOne
KryptikOne / password-input-validation.js
Last active August 29, 2015 14:08
Password input validation
$('#someInput').keyup(function( e ) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if ( false == enoughRegex.test( $(this).val() ) ) {
$('#validationMessage').html('Need More Characters');
}
if ( strongRegex.test( $(this).val() ) ) {
$('#validationMessage').className = 'ok';
$('#validationMessage').html('Strong Like Bull!');
@KryptikOne
KryptikOne / wp-add-favicon-to-admin.php
Last active August 29, 2015 14:07
Adding Favicon To WP Admin (Probably a good idea to make it Black/Grey so as to not confuse site tabs with admin tabs)
// Adding Admin Favicon
function add_admin_favicon() {
$favicon_url = get_stylesheet_directory_uri() . '/assets/admin/images/admin-favicon.ico';
echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
// Calling Favicon Function in the <head> on Login and Admin pages
add_action('login_head', 'add_admin_favicon');
add_action('admin_head', 'add_admin_favicon');