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: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 = '');
// Original idea: http://stackoverflow.com/questions/9565889/get-the-ip-address-of-the-remote-host
using System.Net.Http;
using System.ServiceModel.Channels;
using System.Web;
namespace CrowSoftware.Api
{
public static class HttpRequestMessageHelper
{
@menacestudio
menacestudio / 0_reuse_code.js
Created August 16, 2014 07:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console