Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
dieseltravis / ReadMe.txt
Created August 18, 2010 20:30
My entry into the 10k.aneventapart.com
Entry: http://10k.aneventapart.com/Entry/201
Title: Yahtml
Description: a 5-dice game like Yahtzee, but in html+javascript+css
Browsers: IE9p4, Firefox 3.6, Chrome 6b, Safari 5, iPhone 3G, Nokia E71x
Files:
~/yahtml/index.html
10,105 Bytes
~/yahtml/ya.manifest
@dieseltravis
dieseltravis / gist:547690
Created August 24, 2010 14:59
create an interrobang operator for isnullorempty strings
//NOTE: since the string class is sealed, and you can only override existing operators this will not compile
// coalesce strings when they're null or empty (the ?? operator just coalesces on null)
public static string operator ‽‽(string s1, string s2)
{
return string.IsNullOrEmpty(s1) ? s2 : s1;
}
public static string operator ‽(string s1)
@dieseltravis
dieseltravis / gist:572517
Created September 9, 2010 20:36
unbind then rebind click, call postback manually, using jQuery
// using jQuery:
$("#<%= ButtonId.ClientID %>").unbind("click").bind("click", function () {
if (someCondition) {
// call postback event:
//__doPostBack(this.id.replace(/\_/, "$"),'');
return true;
} else {
return false;
}
});
@dieseltravis
dieseltravis / gist:572577
Created September 9, 2010 21:07
using a CustomValidator with client side and server side validation
<p>
<label for="<%= AgreeTerms.ClientID %>"><asp:CheckBox ID="AgreeTerms" runat="server" />
I agree to the terms.</label>
<asp:CustomValidator id="AgreeTermsValidator" ClientValidationFunction="termsAgreed" CssClass="error" Display="Dynamic" EnableClientScript="true" ErrorMessage="* required" runat="server"></asp:CustomValidator>
</p>
<p><asp:Button ID="SubmitButton" runat="server" Text="Submit Order" CssClass="button" /></p>
<script type="text/javascript">//<![CDATA[
var termsAgreed = function (source, arguments) {
var yield = function(file, callback) {
var o = document.createElement('object');
o.data = file;
o.width = 0;
o.height = 0;
o.onload = function() {
var s = document.createElement('script');
s.src = file;
@dieseltravis
dieseltravis / gist:727225
Created December 3, 2010 17:03
look in all nested controls for a control of a particular type, with a specific id
public static T FindNestedControl<T>(Control controlToSearch, string id) where T: Control
{
T foundControl = null;
bool exceptionThrown = false;
// look directly in the control first
try
{
foundControl = (T)controlToSearch.FindControl(id);
}
@dieseltravis
dieseltravis / gist:752007
Created December 22, 2010 19:53
javascript exercises
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>javascript exercise #1</title>
<style>
.highlight { background-color: yellow; }
</style>
</head>
<body>
@dieseltravis
dieseltravis / gist:765308
Created January 4, 2011 19:58
bookmarklet to re-GET url in IE with a bit of cache protection
//javascript:
(function() {
var l = top.location;
top.location = l.href.split(/&?r=/)[0] + (l.search ? '&' : '?') + 'r=' + Math.random();
})();
@dieseltravis
dieseltravis / ajax.cs
Created January 10, 2011 19:19
Ajax in Asp.Net with jQuery
// SomePage.aspx.cs (ASPX codebehind) function
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static string GetSomeObjects(string id)
{
//TODO: get stuff here
}
@dieseltravis
dieseltravis / gist:779203
Created January 14, 2011 05:13
Hide iOS toolbar after page load
if (window.navigator.standalone !== void(0)) {
$(window).load(function() {
if (!this.navigator.standalone) {
this.setTimeout(function() { this.scrollTo(this.scrollX, this.scrollY + 1); }, 500);
}
});
}