Skip to content

Instantly share code, notes, and snippets.

View menacestudio's full-sized avatar

Dennis Rongo menacestudio

View GitHub Profile
@menacestudio
menacestudio / ServiceResolverAdapter.cs
Created March 13, 2012 03:56 — forked from haacked/ServiceResolverAdapter.cs
ServiceResolverAdapter: Allows you to use the ASP.NET MVC DependencyResolver for ASP.NET Web API
public class ServiceResolverAdapter : IDependencyResolver
{
private readonly System.Web.Mvc.IDependencyResolver dependencyResolver;
public ServiceResolverAdapter(System.Web.Mvc.IDependencyResolver dependencyResolver)
{
if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver");
this.dependencyResolver = dependencyResolver;
}
@menacestudio
menacestudio / gist:2026647
Created March 13, 2012 03:57
JS: jQuery Google CDN
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
@menacestudio
menacestudio / jspat6_4.html
Created March 13, 2012 04:02 — forked from kentbrew/jspat6_4.html
JS: Pro JS Design Patterns Sample Code
<html>
<head>
<title>Chapter 6 Section 4, Pro JavaScript Design Patterns</title>
</head>
<body>
<script>
// this is straight from the code exampes at http://jsdesignpatterns.com/
// sadly, it fails with a syntax error. quoth JSLint:
//
@menacestudio
menacestudio / jquery.loadasync.js
Created April 18, 2012 22:16 — forked from mathiasbynens/jquery.loadasync.js
jQuery: Load scripts asynchronously
// Load scripts asynchronously
jQuery.loadAsync = function(url, callback) {
// Don't use $.getScript since it disables caching
jQuery.ajax({
'url': url,
'dataType': 'script',
'cache': true,
'success': callback || jQuery.noop
});
};
@menacestudio
menacestudio / example.html
Created April 25, 2012 22:19 — forked from joelnet/example.html
KO: Unobtrusive Knockout support library for jQuery
Choose a ticket class: <select id="tickets"></select>
<p id="ticketOutput"></p>
<script id="ticketTemplate" type="text/x-jquery-tmpl">
{{if chosenTicket}}
You have chosen <b>${ chosenTicket().name }</b>
($${ chosenTicket().price })
<button data-bind="click: resetTicket">Clear</button>
{{/if}}
@menacestudio
menacestudio / gist:9d25efcd922662709eb7
Created May 25, 2012 23:12
ASP.NET - Recursive find control within a parent.
private Control FindField(Control source, string id)
{
Control target = source.FindControl(id);
if (target != null) return target;
foreach (Control child in source.Controls)
{
target = this.FindField(child, id);
if (target != null) return target;
}
return null;
@menacestudio
menacestudio / gist:4509238
Created January 11, 2013 09:24
Handlebars: Load template with RequireJS
define(['handlebars','text'], function (Handlebars, text) {
var _buildMap = {};
var _buildTemplate = Handlebars.compile(
'define("{{pluginName}}!{{moduleName}}", ["handlebars"], function(Handlebars){'+
' return {{fn}}'+
'});\n'
);
return {
load: function (name, req, onLoad, config) {
@menacestudio
menacestudio / gist:4515310
Created January 12, 2013 00:43 — forked from efeminella/gist:1937609
Handlebars: Loading external templates
/*
* Extends Handlebars with a basic get method for loading external
* Handlebars templates. Simply pass an options object which contains
* the following properties:
* - path (required) : Path to the external template file to be loaded
* - success (required) : Callback invoked with the compiled loaded template.
* - cache (optional) : true if the template is to be cached, otherwise false.
*
* In addition to the above arguments, any jQuery/Zepto.ajax options argument
* can be specified as well.
@menacestudio
menacestudio / paginated_collection.js
Created January 23, 2013 00:05 — forked from takinbo/paginated_collection.js
Backbone: pagination
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage', 'filtrate', 'sort_by');
typeof(options) != 'undefined' || (options = {});
typeof(this.limit) != 'undefined' || (this.limit = 20);
typeof(this.offset) != 'undefined' || (this.offset = 0);
typeof(this.filter_options) != 'undefined' || (this.filter_options = {});
typeof(this.sort_field) != 'undefined' || (this.sort_field = '');
@menacestudio
menacestudio / animate1.js
Last active December 12, 2015 07:19
SO: Toggle current excerpt and show full view and hide other full views.
$(function() {
$('[id^="post-"]').click(
function() {
var self = $(this);
/** Toggle all posts except for the current one. */
$('.post_content').not(self.find('.post_content')).hide();
$('.image-box').not(self.find('.image-box')).show('slow', function(){});
$('.post_excerpt').not(self.find('.post_excerpt')).show(500, function(){});
/** Show full post but hide excerpt UI elements. */