Skip to content

Instantly share code, notes, and snippets.

View kyleweiner's full-sized avatar

Kyle Weiner kyleweiner

View GitHub Profile
@kyleweiner
kyleweiner / jQuery isMobile.js
Created March 2, 2013 07:06
jQuery: A jQuery function to detect mobile devices.
/**
* @function isMobile
* @description a jQuery function to detect mobile devices
* @param userAgents [array]
* @return object
*/
var userAgents = ['iPad', 'iPhone', 'Android', 'IEMobile', 'BlackBerry'];
function isMobile(userAgents) {
@kyleweiner
kyleweiner / PHP Set Timezone By Offset
Created January 7, 2013 06:43
PHP: A snippet for setting the default timezone using a GMT offset.
// Set the default timezone using a GMT offset
$offset = -5; // GMT offset
$is_DST = FALSE; // observing daylight savings?
$timezone_name = timezone_name_from_abbr('', $offset * 3600, $is_DST); // e.g. "America/New_York"
date_default_timezone_set($timezone_name);
@kyleweiner
kyleweiner / CreatePlane.cs
Created November 14, 2012 09:01
Unity: An editor script for Unity 3D that creates a custom plane.
// CreatePlane
// Credit: http://wiki.unity3d.com/index.php?title=CreatePlane
// 1. Using the inspector, create a new C# script.
// 2. Name the script "CreatePlane" and place it in a folder titled "Editor".
// 3. A new menu option titled "Custom Plane" will appear in "GameObject > Create Other".
using UnityEngine;
using UnityEditor;
using System.Collections;
@kyleweiner
kyleweiner / Unity DrawGizmo
Created November 11, 2012 01:41
Unity: Draws an icon on a game object in Unity 3D's Scene View.
#pragma strict
/***********************************************************************
* Notes
***********************************************************************/
/*
* Attach this script to an empty game object to give it an icon in the
* Scene View. The icon file, as set by the "name" variable, should reside
* in the project's "Assets/Gizmos" folder. See this page for more details:
@kyleweiner
kyleweiner / Unity 2DController
Created November 9, 2012 15:07
Unity: A boilerplate 2D controller for use with Unity 3D
#pragma strict
/***********************************************************************
* Notes
***********************************************************************/
/*
* This is a boilerplate controller for a 2D or 2.5D platform game.
* To that end, this controller allows for movement along the X and Y
* axes only. There is built-in support for jumping, double jumping,
@kyleweiner
kyleweiner / PHP getCreditCardExpiryYears
Created November 3, 2012 00:48
PHP: A function that returns an array of years into the future (relative to the current year). Useful dynamically generating credit card expiry years.
// return an array of years relative to the current year
function getCreditCardExpiryYears($yearsFromNow = 10)
{
if ( ! is_numeric($yearsFromNow)) $yearsFromNow = 10;
$thisYear = date('Y');
$untilYear = $thisYear + $yearsFromNow; // e.g. 2012 + 10 = 2022
$years = array();
for ($i = $thisYear; $i <= $untilYear; $i++)
@kyleweiner
kyleweiner / PHP getYearsByAgeRange
Created October 31, 2012 18:09
PHP: A function that returns an array of years (relative to the current year) using an age range.
// return an array of years (relative to the current year) using an age range
function getYearsByAgeRange($minAge = 0, $maxAge = 0)
{
if ( ! is_numeric($minAge) || ! is_numeric($maxAge) || $minAge > $maxAge) return;
$thisYear = date('Y');
$maxYear = $thisYear - $minAge; // e.g. 2012 - 11 = 2001
$minYear = $thisYear - $maxAge; // e.g. 2012 - 105 = 1907
$years = array();