Skip to content

Instantly share code, notes, and snippets.

View digiguru's full-sized avatar

digiguru

View GitHub Profile
@digiguru
digiguru / echoDataAfterTime.js
Last active August 29, 2015 14:04
For faking ajax calls in jquery functions I use this...
var echoDataAfterTime = function(echoData, waitTime) {
var dfd = new $.Deferred();
waitTime = waitTime || 1000 * 3; //3 second default (it's long but it proves a point)
console.log("Waiting for " + waitTime/1000 + " seconds");
setTimeout(function () {
console.log("Waited for " + waitTime/1000 + " seconds to return data", echoData);
dfd.resolve(echoData);
}, waitTime);
/* euclidean GCD (feel free to use any other) */
function gcd(a,b) {if(b>a) {temp = a; a = b; b = temp} while(b!=0) {m=a%b; a=b; b=m;} return a;}
/* ratio is to get the gcd and divide each component by the gcd, then return a string with the typical colon-separated value */
function ratio(x,y) {c=gcd(x,y); return ""+(x/c)+":"+(y/c)}
/* fix it so the shortest side is always first */
function rotatedRatio(x,y) {var bx=x;if(x>y){x=y;y=bx;} return ratio(x,y)}
/* eg:
@digiguru
digiguru / jquery.dylanCarousel.js
Created March 21, 2011 09:32
A very very lightweight carousel for jQuery, using the simplest "slide" effect. Can be used on any group of HTML elements (images or text)
(function ($) {
$.fn.dylanCarousel = function (options) {
var settings = $.extend({
circular: true,
pageNo: 0,
item: "li",
button: {
next: ".nextBtn",
prev: ".prevBtn"
}
@digiguru
digiguru / RenderJqueryTemplateServerSide
Created May 26, 2011 21:53
Replace all data values from an array into a string using jQuery Template markup.
Public Shared Function RenderTemplate(template As String, list As Array) As String
Dim myRegexOptions As RegexOptions = RegexOptions.Multiline
Dim myRegex As New Regex(strRegex, myRegexOptions)
Dim splits = myRegex.Split(template)
Dim matches = myRegex.Matches(template)
Dim i As Integer = 0
Dim swap As Boolean = False
Dim str As New StringBuilder
For Each item In list
@digiguru
digiguru / ToMultiKeyDictionary.vb
Created February 11, 2012 07:09
To convert any list into a complicated nest of dictionaries for ultra fast lookup.
<ExtensionAttribute()>
Public Function ToMultiKeyDictionary(Of TSource, TSecKey)(ByVal source As IEnumerable(Of TSource), ByVal ParamArray func() As Func(Of TSource, TSecKey)) As IDictionary
'EXAMPLE USAGE
'dict = students.ToMultiKeyDictionary(
' {
' Function(x) x.Age,
' Function(x) x.Location,
' Function(x) x.Job,
' Function(x) x.Name,
@digiguru
digiguru / jQuery.bvplural.js
Created February 22, 2012 11:29
Generic Pluralization Function
/**
* jQuery.bvplural
* Generic Pluralization Function
*
* @Author: Adam Hall
* @Date: 2012-02-21
* @Copyright: © Brand View
* @Version: 1.0.0
* http://www.brandview.co.uk
*
Public Module SessionExtensions
<Runtime.CompilerServices.Extension()>
Public Function TryGetValue(session As System.Web.SessionState.HttpSessionState,
sessionItemName As String,
ByRef result As Object) As Boolean
If session Is Nothing Then
Throw New ArgumentNullException("Session", "Session is nothing.")
End If
@digiguru
digiguru / adapter.js
Last active December 16, 2015 02:29 — forked from elijahmanor/adapter.js
/*!
* jquery-win8-deferred - jQuery $.when that understands WinJS.promise
* version: 0.1
* author: appendTo, LLC
* copyright: 2012
* license: MIT (http://www.opensource.org/licenses/mit-license)
* date: Thu, 01 Nov 2012 07:38:13 GMT
*/
(function () {
var $when = $.when;
@digiguru
digiguru / CurrencyInput
Last active December 19, 2015 09:49
We have a budget planner app, and the first thing we ask the user is "What is your wedding budget?". Given an input of various types, I wanted to calculate the intention of the user without having to ask them any further questions. Originally we just did a simple parseInt(input, 10). After a while we noticed users getting the input incorrect. A …
/*jslint plusplus: true */
/*jslint nomen: true*/
/*global $:false, test:false, ok:false, equal:false */
/* brackets-xunit: qunit */
function convertStringToBudget(input) {
"use strict";
var pointReg = /\./g,
commaReg = /\,/g,
initCurrReg = /[£$R€₹]/g,
name: Office Online Content Control Issue
description: Test an issue in Office Online.
host: WORD
api_set: {}
script:
content: |
$("#copy").click(() => tryCatch(copy));
$("#paste").click(() => tryCatch(paste));
let xmlContent = null;