Skip to content

Instantly share code, notes, and snippets.

View jphase's full-sized avatar

Jeff Hays jphase

View GitHub Profile
@jphase
jphase / gist:9261824
Created February 27, 2014 23:19
Add ymd prototype to Date object to format javascript dates as Y-m-d
// Prototype for js Date object to format in Y-m-d
Date.prototype.ymd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString();
var dd = this.getDate().toString();
return yyyy + '-' + (mm[1] ? mm : '0' + mm[0]) + '-' + (dd[1] ? dd : '0' + dd[0]);
}
@jphase
jphase / regexYoutube.html
Last active November 26, 2021 21:29
Regex match all youtube links
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<div id="anothercontainer">
@jphase
jphase / regexMatch.js
Last active January 28, 2016 22:17
jQuery regex search element text/contents and return matches based on child element containing regex
// Escape all RegEx reserved characters from string
function escRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
// Return matched elements based on regex contents
function highlight(regex, element, child) {
// Create a regex based on the match string
var regex = new RegExp(escRegExp(regex), 'gim');
// Generate results based on regex matches within match_parent