Skip to content

Instantly share code, notes, and snippets.

View dieseltravis's full-sized avatar
🆗
I'm ok

Travis Hardiman dieseltravis

🆗
I'm ok
View GitHub Profile
@dieseltravis
dieseltravis / gist:2247
Created July 24, 2008 18:57
Getting a unique random item in a collection
private string GetRandomRelatedViewID(string viewIDList)
{
BaseGenericList<BrandEnsemble.Framework.RelatedItems.Components.RelatedItem> riList = BrandEnsemble.Framework.RelatedItems.RelatedItems.GetAllRelatedItems();
riList.Filter(new string[] { "Caption" }, string.Empty, FilterOperand.NotEquals);
BrandEnsemble.Framework.RelatedItems.Components.RelatedItem rri = riList.RandomItem();
while (viewIDList.IndexOf(rri.ViewID) >= 0)
{
rri = riList.RandomItem();
}
return rri.ViewID;
Date.prototype.atSomePoint = function(hours) {
var startHour = new Date(this.valueOf());
var endHour = new Date(this.valueOf());
startHour.setSeconds(0);
startHour.setMinutes(0);
endHour.setSeconds(0);
endHour.setMinutes(0);
if (hours) {
startHour.setHours(hours.between);
endHour.setHours(hours.and);
@dieseltravis
dieseltravis / gist:2519
Created July 25, 2008 20:43
adding a drop shadow to the page using RUZEE.ShadedBorder
/* add shadow to page */
$("#body").wrap("<div id=\"body-shadow\" style=\"width:800px; margin: auto; padding: 0 4px 5px 0;\"></div>");
var border = RUZEE.ShadedBorder.create(
{
corner: 1,
shadow: 8,
border: 0,
borderOpacity: 0.8
}
);
/* Pushup
* Copyright (c) 2008 Nick Stakenburg (www.nickstakenburg.com)
*
* License: MIT-style license.
* Website: http://www.pushuptheweb.com
*
*/
var Pushup = {
Version: '1.0.0.1.jquery',
@dieseltravis
dieseltravis / gist:4102
Last active August 29, 2015 14:24
Non-blocking JavaScript Downloads, with jQuery
<script src="scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">//<![CDATA[
var js = ["scripts/jquery.dimensions.js", "scripts/shadedborder.js", "scripts/jqmodal.js", "scripts/main.js"];
var $head = $("head");
for (var i = 0; i < js.length; i++) {
$head.append("<script src=\"" + js[i] + "\" type=\"text/javascript\"></scr" + "ipt>");
}
//]]></script>
@dieseltravis
dieseltravis / gist:5572
Created August 15, 2008 14:22
saving an image from the web to a local path and returning a stream
Public Shared Function GetExternalImage(ByVal url As String) As IO.Stream
Dim parts As String() = url.Split("."c)
Dim ext As String = parts(parts.Length - 1)
Dim path As String = HttpContext.Current.Server.MapPath("~/App_Data/rss/photogallery/")
If Not Directory.Exists(path) Then
Directory.CreateDirectory(path)
End If
Dim stream As IO.Stream = Nothing
If File.Exists(cacheFilePath) Then
stream = File.OpenRead(cacheFilePath)
/**
* Favicons 1.0.th
*
* Prepends or appends a favicon image to all external links
*
* Usage: jQuery.favicons();
*
* @class favicons
* @param {Object} conf, custom config-object
*
@dieseltravis
dieseltravis / gist:22148
Created November 4, 2008 15:24
use jQuery to set elements to have equal heights, factoring in min-heights and vertical padding
// call this to reset the size to the columns
function setColumnsEqualHeight()
{
// some example items to measure and resize
var $toMeasure = $("#content-left-shadow, #content-middle, #content-right-shadow, #secondary-nav");
var $toResize = $("#content-bottom-container, #content-left-shadow, #content-middle, #content-right-shadow");
setEqualHeight($toMeasure, $toResize);
}
// call the helper method for both ready and load to make sure stuff is sized as dynamically as possible
@dieseltravis
dieseltravis / cached-xml.cs
Last active August 29, 2015 17:34
Caching an XML document with a file dependency
XmlDocument xDoc = null;
string xmlPath = "~/App_Data/SomeXml.xml";
if (HttpContext.Current.Cache[xmlPath] == null) {
string cacheFilePath = HttpContext.Current.Server.MapPath(xmlPath);
xDoc = new XmlDocument();
xDoc.Load(cacheFilePath);
HttpContext.Current.Cache.Insert(xmlPath, xDoc, new CacheDependency(cacheFilePath));
} else {
xDoc = (XmlDocument)HttpContext.Current.Cache[xmlPath];
@dieseltravis
dieseltravis / gist:25940
Created November 17, 2008 22:46
Date Validator
Protected Sub DateValidator_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles DateValidator.ServerValidate
args.IsValid = DateTime.TryParse(args.Value, New DateTime())
End Sub