Skip to content

Instantly share code, notes, and snippets.

@corymartin
corymartin / gist:1518824
Created December 25, 2011 06:42
jQuery pseudo selectors for HTML5 input types
//
// Adds jQuery Pseudo Selectors for HTML5 input types.
//
// Example:
// HTML:
// <input type="email" name="user_email">
// jQuery:
// $(':email');
//
//
@corymartin
corymartin / gist:1518841
Created December 25, 2011 07:15
jQuery Fast
//
// For simple selectors, these return a jQuery object
// faster via native element selection.
//
(function(window) {
var
doc = window.document,
$ = window.jQuery;
@corymartin
corymartin / Friends.cs
Created February 23, 2012 23:05
Using SQL Server's XML type to pass an "array" of values for multiple inserts, updates, etc.
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace Gists.Data
{
public class Friends
{
/// <summary>
/// Inserts each friends' name into a table.
@corymartin
corymartin / flags.js
Created April 15, 2012 14:55
Flag Enumerations in JavaScript
// Flag Enumerations in JavaScript
// ===============================
// Flag enums
// ----------
// Values must increment by powers of 2
var SEASONS = {
Spring : 1,
Summer : 2,
@corymartin
corymartin / gist:2434311
Created April 21, 2012 05:33
isInvalidDate()
function isInvalidDate( /*Date*/date ) {
if (date == null || !(date instanceof Date)) return true;
var ts = date.getTime();
if (ts !== ts) return true; // NaN
var str = date.toString();
return str === 'Invalid Date' || str === 'NaN';
}
@corymartin
corymartin / gist:3156752
Created July 21, 2012 18:50
Learning Go. First attempt at serving JSON.
package main
import (
"encoding/json"
"fmt"
"net/http"
)
// Learning Go
// First try at serving JSON
@corymartin
corymartin / Person.cs
Created August 8, 2012 20:15
Parsing JSON array in C# :/
public class Person {
public string name { get; set; };
public byte age { get; set; };
}
@corymartin
corymartin / ExampleUsage.cs
Created December 26, 2012 03:02
Extension method: System.Web.Mvc.FormCollection#Fetch
[HttpPost]
public ActionResult Create(FormCollection collection)
{
var username = collection.Fetch("username", "anonymous");
// username will equal "anonymous" if it was not submitted
}
// VERSUS:
[HttpPost]
@corymartin
corymartin / printElement.js
Last active December 11, 2015 23:38
Prints an element and its contents. jQuery free version of Ben Nadel's jQuery plugin. http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm
/**
* Prints an element and its contents.
* jQuery free version of Ben Nadel's jQuery plugin.
* http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm
*
* @param {HTMLElement} el
* @returns {undefined}
*/
function printElement(el) {
var csslinks = document.getElementsByTagName('link');
@corymartin
corymartin / range.js
Last active December 16, 2015 00:29
Tiny array range api
/**
* range(2, 6) // [2,3,4,5,6]
* range(5).to(8) // [5,6,7,8]
* range(4).until(10) // [4,5,6,7,8,9]
*/
var range = function(s, e) {
if (e == null) {
return {
to: function(e) {