Skip to content

Instantly share code, notes, and snippets.

View jkresner's full-sized avatar

ಠ_ಠ jkresner

  • airpair, inc.
  • San Francisco
View GitHub Profile
@jkresner
jkresner / AccountModels.cs
Created October 4, 2012 17:29
Cause EF5 context to create tables on Mvc App Start
public class UsersContext : DbContext
{
public UsersContext()
: base("cf5WebContext")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
@jkresner
jkresner / Filters\InitializeSimpleMembershipAttribute.cs
Created October 9, 2012 17:30
Facebook Realtime Updates w C#/Asp .net Mvc 4, EF5 CodeFirst (30 mins setup|Oct 2012)
WebSecurity.InitializeDatabaseConnection("fbRealtimeWebContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);
@jkresner
jkresner / Global.asax
Created October 30, 2012 20:20
Asp .net Mvc 4 Proxy Server/Controller (For help with Cross Domain Request)
public class WebApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
RouteTable.Routes.MapRoute("HttpProxy", "proxy/{*path}", new { controller = "Proxy", action = "Http" })
}
}
@jkresner
jkresner / hack_detail.coffee
Created December 3, 2012 06:58
Meteor Template
Template.hacks_detail.hack = -> Hacks.findOne({ _id : Session.get('hack_id') })
Template.hacks_detail.creatorName = ->
owner = Meteor.users.findOne @owner
if owner then displayName(owner) else ''
@jkresner
jkresner / app.html
Last active December 10, 2015 13:18
Running Google Analytics with Meteor js (Insert your own tracking code)
<head>
<title>Your meteor app</title>
</head>
<body>
{{> setup}}
</body>
<template name="setup"></template>
@jkresner
jkresner / FilteringPagingCollection.coffee
Last active December 10, 2015 18:48
Filtering, paging, sorting and searching collection with backbone.js
class FilteringAndPagingCollection extends Collection
pagesize: 25 # overriden in the child class
constructor: (args) ->
Backbone.Collection.prototype.constructor.apply(@, arguments) # called so backbone wires up & calls initialize
@filteredmodels = @models
@on 'reset', @resetfilteredmodels, @ # if the collection is reset, we need to reset the filtered version too
@on 'search sort', @resetpaging, @
resetfilteredmodels: ->
@filteredmodels = @models
@resetpaging()
exports.config =
files:
javascripts:
joinTo:
'javascripts/app.js': /^app/
'javascripts/vendor.js': /^vendor/
'test/javascripts/test.js': /^test[\\/](?!vendor)/
'test/javascripts/test-vendor.js': /^test[\\/](?=vendor)/
order:
before: [
@jkresner
jkresner / after.coffee
Created January 24, 2013 17:47
Refactoring Coffee Loop: 1) Always refer to jquery elements inside of backbone views with this.$ (@$) => forces jquery to search a subset of the dom (better for bugs & speed) 2) Coffee looping is clean
render_carousel: ->
@$('.carousel-images').append('<img src="'+img.url+'">') for img in images
@jkresner
jkresner / Collections.coffee
Last active December 12, 2015 04:48
Filter + PagingCollection Improved. A Filtering collection is a collection that has 2 views of it's models. (1) The original set of models and a filtered view using some custom filtering logic defined in the child collection of the base FilteringCollection class. A PagingCollection inherits from FilteringCollection and can keep track of and retu…
""" FilteringCollection
(1) Holds an original AND a filtered view of it's models
(2) Can sort filtered models on any arbitrary attribute
- sort can be invoked multiple times with different attributes to get
sorted by A then B """
class FilteringCollection extends Backbone.Collection
# Use coffee's constructor function so we can enforce initialization code +
# let the child class use the standard Backbone initialize function to
@jkresner
jkresner / aTest.coffee
Created April 13, 2013 08:44
TDD nodejs, mocha, mongo, mongoose with a test database
mongoose = require 'mongoose'
wipeDbAfterTests = true
describe "Your test suite", ->
# connect to our mongo test database, note how done is passed to mongoose connect
before (done) ->
mongoose.connect "mongodb://localhost/airpair_test", done