Skip to content

Instantly share code, notes, and snippets.

View nathggns's full-sized avatar

Nate Higgins nathggns

View GitHub Profile
@nathggns
nathggns / base64url.php
Created September 21, 2013 18:34
base64url functionality for php
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
@nathggns
nathggns / functions.js
Created September 20, 2013 13:56
Different ways of generating function
_.once($.fn.slideUp.bind($div, $.fn.remove.bind($div)));
// vs
_.once(function() {
$div.slideUp($.fn.remove.bind($div));
});
// vs
@nathggns
nathggns / autocast-params.js
Last active December 22, 2015 17:59
Something I wish was in ES6
jQuery.prototype.fromObject = function(object) {
if (object instanceof jQuery) {
return object;
}
return $(object);
}
function handlejQueryObject(jQuery object) {
// object will always be a jquery rep of the body element
@nathggns
nathggns / util.js
Last active December 20, 2015 19:29
/**
* This function allows you to prefill "parts" of a functions
* arguments.
*
* @param {Function} func The function to call
* @param {mixed} An argument
* @param {mixed} ...
*
* @return {Function} Function with arguments that're prefilled
*
@nathggns
nathggns / requirejs-config.js
Last active August 11, 2016 18:11
Monkey Patch requirejs.config to be able to be called multiple times
(function() {
/**
* Little script that allows you to call requirejs.config multiple times.
*/
/**
* Stores the actual config that gets passed into requirejs.config
* @type {Object}
*/
@nathggns
nathggns / README.md
Last active December 20, 2015 15:39
Nice little TickEventEmitter (EventEmitter extension with automatic tick support)
@nathggns
nathggns / templating.html
Last active December 20, 2015 09:59
Ideal Templating
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Templating</title>
</head>
<body>
<div id="Item" class="template">
<li class="item">
@nathggns
nathggns / regex_sort.php
Created July 19, 2013 21:30
Sort an array based on an array of regular expressions.
<?php
/**
* Search an array of regular expressions for the indexes that match a needle
*
* @param string $needle The needle
* @param array $haystack The array of regular expressions to search
* @param boolean $all Should it return all indexes or just the first one
* @return mixed boolean: false if no matches are found and $all
* equals false
*
@nathggns
nathggns / dabblet.css
Created July 4, 2013 11:56
Growing and fading numbers
/**
* Growing and fading numbers
*/
* { padding: 0; margin: 0; }
html, body { height: 100%; overflow: hidden; }
.number {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% -50%);
@nathggns
nathggns / replace.php
Created July 1, 2013 12:54
Convert Short Tags to open tags (Respect whitespace)
<?php
define('DS', DIRECTORY_SEPARATOR);
/**
* Recursive glob
*/
function recursive_glob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern) . DS . '*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {