Skip to content

Instantly share code, notes, and snippets.

View travislwatson's full-sized avatar

Travis Watson travislwatson

View GitHub Profile
@travislwatson
travislwatson / property.js
Created February 11, 2015 18:06
A property creator, optimized for public access
(function() {
'use strict';
window.property = function(initialValue) {
var internalValue = null,
watchers = [];
set(initialValue);
var output = function(value) {
@travislwatson
travislwatson / HexExtensions.cs
Last active August 29, 2015 14:03
Extension methods for conversion between byte arrays and hexadecimal strings
internal static class HexExtensions
{
public static string ToHex(this byte[] array)
{
return BitConverter.ToString(array).Replace("-", "").ToLower();
}
public static byte[] ParseHex(this string hex)
{
hex = hex.ToLower();
@travislwatson
travislwatson / jquery.mutuallyExclusive.js
Last active December 22, 2015 07:29
A jQuery plugin for making a set of <select> mutually exclusive based on their values. I created this for security questions, where each question needs to be distinct. Usage: $('select').mutuallyExclusive(); Demo: http://jsfiddle.net/DNrTL/1/
/*!
* jQuery Mutually Exclusive Select Plugin v0.1
* https://gist.github.com/traviswatsonws/6438321
*
* Author: Travis Watson (http://travis.watson.ws)
* Public domain: use however you like!
*/
(function ($) {
function cacheInitialOptions($selects) {
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
@travislwatson
travislwatson / view.php
Created March 6, 2013 03:17
A simple PHP View class
class View
{
const LogSuccess = 0;
const LogInfo = 1;
const LogWarning = 2;
const LogError = 3;
public $Logs = array();
private $data;
@travislwatson
travislwatson / maxlength.js
Last active December 11, 2015 14:39
Shim for maxlength attribute.
jQuery(function ($) {
$('textarea[maxlength]').each(function () {
var $this = $(this),
limit = parseInt($this.attr('maxlength'));
if (!isNaN(limit) && isFinite(limit) && limit > 0) {
$this.keyup(function () {
var curText = $this.val();
if (curText.length > limit) {