Skip to content

Instantly share code, notes, and snippets.

View JimBobSquarePants's full-sized avatar
💭
(•_•) ( •_•)>⌐■-■ (⌐■_■)

James Jackson-South JimBobSquarePants

💭
(•_•) ( •_•)>⌐■-■ (⌐■_■)
View GitHub Profile
@JimBobSquarePants
JimBobSquarePants / GetAllColorNames.cs
Created November 30, 2015 09:09
Gets all the System.Drawing names in the format I need.
void Main()
{
PropertyInfo[] colorProperties = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public);
List<Color> colors = colorProperties.Select(prop => (Color)prop.GetValue(null, null)).ToList();
Color rp = Color.FromName("RebeccaPurple");
colors.Add(rp);
foreach (Color c in colors.OrderBy(co => co.Name))
{
@JimBobSquarePants
JimBobSquarePants / jQuery.MultiGetScript.js
Last active December 12, 2015 01:19
jQuery plugins to get multiple scripts in a single call. In cached and un-cached flavours.
(function ($) {
/**
* Multiple parallel getScript with caching.
*
* @param {Array|String} url (one or more URLs)
* @param callback fn (oncomplete, optional)
* @returns {function}
*/
$.getCachedScript = function (url, callback) {
// License: CPOL at http://www.codeproject.com/info/cpol10.aspx
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace System.IO
{
public static class AsyncIoExtensions
{
@JimBobSquarePants
JimBobSquarePants / getVendorPropertyName.js
Last active December 23, 2015 02:59
Gets the correct vendor property name for the current browser. ("transition" => "MozTransition")
getVendorPropertyName = function (prop) {
/// <summary>Gets the correct vendor property name for the current browser.</summary>
/// <param name="prop" type="String">The property to return the name for.</param>
/// <returns type="String">The correct vendor property name.</returns>
var el = document.createElement("div");
if (prop in el.style) {
return prop;
}
@JimBobSquarePants
JimBobSquarePants / centered-image.css
Last active December 23, 2015 09:49
Dimension Independent Centred Images - This allows an image to be centered within a parent container of a fixed height no matter what height or width the child image is. http://jsfiddle.net/jamessouth/JpCXX/
/*
* 1: Arbitrary width.
*/
.parent {
position: relative;
height: 250px;
max-width: 400px; /* 1 */
overflow: hidden;
}
@JimBobSquarePants
JimBobSquarePants / ColorOperator.cs
Created January 4, 2016 14:20
Generic operators
public static Color<T> operator +(Color<T> left, Color<T> right)
{
if (typeof(T) == typeof(byte))
{
return (Color<T>)(object)new Color<byte>(
(byte)((byte)(object)left.R + (byte)(object)right.R),
(byte)((byte)(object)left.G + (byte)(object)right.G),
(byte)((byte)(object)left.B + (byte)(object)right.B),
(byte)((byte)(object)left.A + (byte)(object)right.A));
}
#master-header .contact-number, #master-header .cta-links a, #mobile-nav .mobile-tools .contact-number, #mobile-nav .second-level a, #mobile-nav .top-level a, #primary-nav ul.top-level .primary-link, #quote-panel .btn-change, #quote-panel .btn-join-now, #quote-panel .value, .a-feature p, .accordion-content .header p, .btn-form-next, .btn-form-prev, .btn-get-quote, .btn-get-quote-white, .btn-join, .btn-large-primary, .btn-large-secondary, .btn-med-primary, .btn-med-secondary, .btn-members-services, .compare-cover-tile h1, .comparison-table .category-title p, .contact-us .tab-btns-row a, .contact-us h1, .contact-us h2, .contact-us h3, .extras-cover-table .key span, .extras-select .title, .form-section h1, .general-content h1, .general-content h2, .hero-image h1, .left-nav a, .legend h1, .live-quote-tool .bootstrap-select .dropdown-toggle .filter-option, .live-quote-tool .lqt-compare-table .column .group .group-label, .live-quote-tool .lqt-compare-table .column .product-label, .live-quote-tool .lqt-compare-table
<div class="intro-copy">
<h2>"I am supposed to be a quote but I have the wrong markup."</h2>
<p class="user-desc">Cassie <span>Science Teacher</span></p>
</div>
@JimBobSquarePants
JimBobSquarePants / ImageCropperPropertyConverter.cs
Last active March 10, 2016 04:49
ImageCropperPropertyConverter for Umbraco
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageCropperPropertyConverter.cs" company="Deepend">
// Copyright (c) Deepend
// </copyright>
// <summary>
// The image cropper property converter. This allows Ditto to map the image cropper using the built in Umbraco
// methods.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Throttles duplicate requests.
/// Based loosely on <see href="http://stackoverflow.com/a/21011273/427899"/>
/// </summary>
public sealed class AsyncDuplicateLock
{
/// <summary>
/// The collection of semaphore slims.
/// </summary>
private static readonly ConcurrentDictionary<object, SemaphoreSlim> SemaphoreSlims