Skip to content

Instantly share code, notes, and snippets.

@Boztown
Boztown / gist:2570685
Created May 1, 2012 19:24
Javascript: Namespaced Javascript Template
/*
Self invoking anonymous function assigned to the yournamespacechoice global variable. Serves the effect of keeping all functions and variables private to this function. To expose a function or variable we must explictly return it at the bottom of the function. Remaps jQuery to $.
*/
var yournamespacechoice = (function ($) {
var publicfunction;
function privatefunction() {
// function only available within parent function
}
@Boztown
Boztown / gist:2571023
Created May 1, 2012 20:12
C#: ExpandoObject
dynamic expando = new ExpandoObject();
expando.Address = new ExpandoObject();
expando.Address.State = "WA";
Console.WriteLine(expando.Address.State);
@Boztown
Boztown / gist:2598018
Created May 4, 2012 22:03
jQuery: Plugin Skeleton
(function($){
$.fn.extend({
pluginname: function(options) {
this.defaultOptions = {};
var settings = $.extend({}, this.defaultOptions, options);
return this.each(function() {
var $this = $(this);
});
@Boztown
Boztown / gist:2648813
Created May 9, 2012 21:03
C#: Shorthand If
// Using the (Question) ? Positive Answer : Negative Answer patterns the above can be rewritten as:
int x = 10;
int y = 20;
int max = (x > y) ? x : y;
@Boztown
Boztown / gist:2649625
Created May 9, 2012 23:13
C#: SqlDataReader NullCheck
TourHostCompanyProv.Text = NullCheck(reader, "fldTourHostCompanyProv");
public string NullCheck(SqlDataReader reader, string key)
{
return (reader[key] == DBNull.Value) ? String.Empty : (string)reader[key];
}
@Boztown
Boztown / gist:2776464
Created May 23, 2012 17:17
T-SQL: Get latest record with shared GUID
SELECT DISTINCT TOP 1 * FROM Customers WHERE CustomerGUID = 'a3a3' ORDER BY CreatedAt DESC
@Boztown
Boztown / purge.sql
Created June 15, 2012 16:49
Wordpress: Purge revisions SQL
DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( b.term_taxonomy_id = d.term_taxonomy_id)
@Boztown
Boztown / pattern.js
Created June 21, 2012 22:19
Javascript: Extendible Pattern
//Self-Executing Anonymous Func: Part 2 (Public & Private)
(function( skillet, $, undefined ) {
//Private Property
var isHot = true;
//Public Property
skillet.ingredient = "Bacon Strips";
//Public Method
skillet.fry = function() {
@Boztown
Boztown / gist:3007017
Created June 27, 2012 21:35
Razor Examples
// strongly-typed textbox helper (not the @ because "class" is a keyword... sneaky)
@Html.TextBoxFor(model => model.Title, new { @class = "span4" })
// strongly typed validation message
@Html.ValidationMessageFor(model => model.Title)
@Boztown
Boztown / gist:3054684
Created July 5, 2012 16:34
AS3: Convert Ranges
private function newRange( value:Number, oldMin:Number, oldMax:Number, newMin:Number, newMax:Number):Number
{
value -= oldMin;
value /= (oldMax - oldMin); //returns a value between 0 and 1
return value * (newMax - newMin) + newMin; //place that ratio from previous step into a new range function
}