Skip to content

Instantly share code, notes, and snippets.

View alexsasharegan's full-sized avatar

Alex Regan alexsasharegan

View GitHub Profile
@alexsasharegan
alexsasharegan / states-select.html
Created December 23, 2016 00:37
Form select with all 50 states.
<select name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
@alexsasharegan
alexsasharegan / gulpfile.js
Created January 7, 2017 20:27
Browserify js bundling and sass compilation
// gulpfile.js
// Heavily inspired by Mike Valstar's solution:
// http://mikevalstar.com/post/fast-gulp-browserify-babelify-watchify-react-build/
"use strict";
const gulp = require( 'gulp' );
const browserify = require( 'browserify' );
const babelify = require( 'babelify' );
const uglifyify = require( 'uglifyify' );
const watchify = require( 'watchify' );
@alexsasharegan
alexsasharegan / addEventListenerOnce.js
Last active August 21, 2017 15:45
Add an event handler that unbinds after firing once (no jQuery).
function addEventListenerOnce(node, event, callback) {
function listenOnce() {
node.removeEventListener(event, fnOnce)
return callback.apply(null, arguments)
}
node.addEventListener(event, fnOnce)
}
@alexsasharegan
alexsasharegan / regex.js
Created March 6, 2017 21:35
Common RegExes for me
class MyRegEx {
static email(){
return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
}
static ssn(){
return /^(?!000|666|900|999)(\d{3})-?(?!00)(\d{2})-?(?!0000)(\d{4})$/;
}
}
@alexsasharegan
alexsasharegan / debounce.js
Last active March 17, 2017 17:42
Hijacking the useful debounce function from underscore.js
function debounce( func, wait, immediate ) {
let timeout;
let args;
let context;
let timestamp;
let result;
const now = Date.now || () => new Date().getTime();
const later = function () {
@alexsasharegan
alexsasharegan / Countdown.js
Last active March 20, 2017 02:11
Javascript to animate a countdown. Ideal for a coming soon or event page.
( function ( ) {
'use strict';
function Countdown( endDate, elSelector ) {
if ( endDate instanceof Date ) {
this.countdownDate = endDate.getTime( );
} else {
this.countdownDate = new Date( endDate ).getTime( );
}
@alexsasharegan
alexsasharegan / SafeArray.php
Last active June 12, 2024 17:01
Use dot-notation to safely get and set deeply nested array values.
<?php
class SafeArray implements JsonSerializable, ArrayAccess {
/**
* @var array
*/
private $data;
/**
@alexsasharegan
alexsasharegan / extract-all-object-props-to-array.php
Created March 24, 2017 16:14
Use reflection to get an array of both visible & hidden object properties. Handles nested objects recursively.
<?php
function extractAllObjectPropsToArray( $object )
{
$properties = [];
$reflection = new ReflectionClass( $object );
foreach ( $reflection->getProperties() as $property )
{
$property->setAccessible( TRUE );
@alexsasharegan
alexsasharegan / ResponseReflector.php
Last active March 26, 2017 12:14
Extracts all the properties of an instance of ANetApiResponseType to an array.
<?php
class ResponseReflector {
/**
* @param \net\authorize\api\contract\v1\ANetApiResponseType $responseType
*
* @return array
*/
public static function extractANetResponsePropsToArray( \net\authorize\api\contract\v1\ANetApiResponseType $responseType )
@alexsasharegan
alexsasharegan / material-design-drop-shadows.css
Created April 14, 2017 05:44
Add in some material design style drop shadows with css classes
.md-drop-shadow-lt {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.md-drop-shadow {
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
.md-drop-shadow-heavy {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);