Skip to content

Instantly share code, notes, and snippets.

View davidrautert's full-sized avatar

David Macedo davidrautert

  • Gibsonville, NC, USA
View GitHub Profile
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
@davidrautert
davidrautert / unique.js
Created November 13, 2018 20:52
Count unique elements within any iterable
function unique(iterable) {
return new Set(iterable).size;
}
@davidrautert
davidrautert / isPalindrome.js
Last active November 13, 2018 20:42
Checks whether given string is a palindrome
function isPalindrome(str) {
var len = Math.floor(str.length / 2);
for (var i = 0; i < len; i++)
if (str[i] !== str[str.length - i - 1])
return false;
return true;
}
@davidrautert
davidrautert / removeDuplicate.js
Last active November 13, 2018 20:40
Recursive Unique object filtering
// I'm writing out my whole thought process for this. Lots of console.logs and comments
// Let's make some data
let objA = { something: '1 does a thing' };
let objB = { something: '2 does a thing' };
let objC = objA;
let objD = { something: objC };
let arrA = ['test', objB, 'testing thing', objA, '3 doing things'];
let data = [objA, objB, objC, objD, arrA];
@davidrautert
davidrautert / getAbsoluteUrl.js
Created July 23, 2013 17:07
Provided a url and a path relative to that url, this function will return the resulting absolute url
var getAbsoluteUrl = function(url, path) {
if(url.substr(-1) == '/') {
url = url.substr(0, url.length-1);
}
var path = path;
if(path !== null) {
if(url.substr(-1) == "/") {
url = url.substr(0, url.length-1);
@davidrautert
davidrautert / intersect.js
Created October 15, 2012 16:34
JS: Multi-array intersect
/*
** intersect.js
** intersect multiple arrays
** Usage:
var arr1 = ['hey', 'you', 'guys', 'test', 'there'];
var arr2 = ['there', 'you'];
var arr3 = ['some', 'there', 'you', 'thrice', 'hey', 'huzzah'];
intersect(arr1, arr2, arr3);
*/
function intersect() {
@davidrautert
davidrautert / shift.prototype.js
Created November 8, 2011 20:02
js prototype of shift function
if(!Array.prototype.shift) { // if this method does not exist..
Array.prototype.shift = function(){
firstElement = this[0];
this.reverse();
this.length = Math.max(this.length-1,0);
this.reverse();
return firstElement;
}
@davidrautert
davidrautert / unshift.prototype.js
Created November 8, 2011 20:02
js prototype of unshift function
if(!Array.prototype.unshift) { // if this method does not exist..
Array.prototype.unshift = function(){
this.reverse();
for(var i=arguments.length-1;i>=0;i--){
this[this.length]=arguments[i]
}
this.reverse();
@davidrautert
davidrautert / removeEmptySubfolders.php
Created March 9, 2011 17:42
Scan through a given directory, removing empty directories
function removeEmptySubFolders($path) {
$empty = true;
foreach (glob($path.DIRECTORY_SEPARATOR."*") as $file) {
$empty &= is_dir($file) && RemoveEmptySubFolders($file);
}
return $empty && rmdir($path);
}
@davidrautert
davidrautert / in_array_exclusively.php
Created March 2, 2011 22:33
Check whether a value or array of values are the only existing values within an array
function in_array_exclusive($needles, $haystack) {
$keys = count($haystack);
if(is_array($needles)) {
foreach($needles as $needle) {
if(!in_array($needle, $haystack)) {
return false;
} else {
$keys = $keys - 1;
}
}