Skip to content

Instantly share code, notes, and snippets.

View menacestudio's full-sized avatar

Dennis Rongo menacestudio

View GitHub Profile
@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 / angular.cshtml
Last active October 19, 2016 22:48
Quick AngularJS CRUD
@section scripts {
<script>
var app = window.app = {};
app.userTypes = @Html.Raw(Json.Encode(Model.GetUserTypes()));
</script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-resource.min.js"></script>
<script src="~/Scripts/underscore.min.js"></script>
<script src="~/Scripts/angular/main.js"></script>
// 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 / md_to_html.py
Created March 13, 2013 00:42
Converts a Markdown file to HTML.
# Author: Dennis Rongo
# Date: 03.12.2013
# Description: Thie script converts a Markdown (*.md) file to HTML within the same directory.
# This requires Pandoc (http://johnmacfarlane.net/pandoc/) to do the conversion.
import sys
import getopt
import subprocess
def process(arg):
@menacestudio
menacestudio / backbone_ajax1.js
Created March 12, 2013 22:30
Backbone: Override AJAX methods
/** Global override to make all AJAX calls as POST type */
Backbone.ajax = function() {
var args = Array.prototype.slice.call(arguments, 0);
return Backbone.$.ajax.apply(Backbone.$, _.extend(args, {type: 'POST'}));
};
/** Manual override per call */
Collection.fetch({data: {id: 34}, type: 'POST'});
@menacestudio
menacestudio / option1.js
Last active December 14, 2015 19:49
Backbone: Only persist a Model with valid attributes.
var President = Backbone.Model.extend({});
var m = new President({first: 'Abraham', last: 'Lincoln', age: 90, registered: true});
m.set({first: null});
/** Loop through each property and unset if invalid. Also check if property if boolean type. */
_.each(m.toJSON(), function(val, col){
if (typeof val !=='boolean' && !val) {
m.unset(col);
}
@menacestudio
menacestudio / defer.js
Last active December 14, 2015 19:38
Using jQuery's deferred object.
/**
Author: Dennis Rongo
Description: This demonstrates the jQuery deferred object and used when running asynchronous operations (non-AJAX) functions.
Each function returns a 'promise' object that notifies the subscriber when the operation has completed.
*/
$(function(){
/** Create a long operation */
var loadQueue = function() {
var dfrQueue = new $.Deferred();
@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. */
@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 / 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) {