Skip to content

Instantly share code, notes, and snippets.

@csainty
csainty / Inmate.cs
Created July 5, 2011 03:56
Draft Inmate model for Macto
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Macto
{
public class Inmate
{
public int Id { get; set; }
@csainty
csainty / gist:1064886
Created July 5, 2011 14:01
Example RavenDb Profiling JSON
{
"Results": [
{
"Title": "Macto: The boundaries of a prison",
"LegacySlug": null,
"Body": "<p>Macto is a prison management system. To be rather more exact, it is an <em>incarceration </em>management system. Managing a prison is a very complex process (did you ever think about who takes the trash out? Or how to handle things like watch rotations?).</p> <p>I am getting ahead of myself, however. The first thing that we have to do when we start designing a system is check:</p> <ul> <li>What is the scope of the system?</li> <li>What is the intended usage?</li> <li>Who are the users?</li> <li>What other systems are we going to interface with?</li></ul> <p>Those are the basics, because in a lot of projects, they don’t get asked.</p> <p>Running a prison is a complex task, I already said. If we wanted a single piece of software to do it all, we would have to do a <em>lot</em> of stuff that we don’t really need. For example, are we going to write our own payroll system for the prison’s stuff? O
@csainty
csainty / Profiler.cs
Created July 5, 2011 23:50
Glimpse.RavenDb
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Glimpse.Core.Extensibility;
using Raven.Client.Document;
namespace Glimpse.RavenDb
{
@csainty
csainty / CompiledQuery_NoParam.cs
Created August 17, 2011 05:49
blog post - Compiled Queries
public class Repository {
private gReadieModelContext _Ctx = gReadieModelContext.Create(gReadieModelContext.ConnectionString);
public Func<gReadieModelContext, IEnumerable<Folder>> Query_FoldersWithUnreadPosts =
CompiledQuery.Compile((gReadieModelContext db) => db.Folders.Where(d => d.UnreadCount != 0).AsEnumerable());
public IEnumerable<Folder> GetFoldersWithUnreadPosts() {
return Query_FoldersWithUnread(_Ctx);
}
}
@csainty
csainty / MemoryCheck.cs
Created August 19, 2011 05:57
blog post - Background Agents
if (((double)DeviceStatus.ApplicationCurrentMemoryUsage / (double)DeviceStatus.ApplicationMemoryUsageLimit) * 100d > 97d) {
// We are using too much memory, try clean a few things up
if (_Ctx != null)
_Ctx.Dispose();
_Ctx = new gReadieModelContext(gReadieModelContext.ConnectionString);
GC.Collect();
if (((double)DeviceStatus.ApplicationCurrentMemoryUsage / (double)DeviceStatus.ApplicationMemoryUsageLimit) * 100d > 97d) {
// We couldn't recover enough memory, so we are really running out, lets be nice and bail
NotifyComplete();
return;
@csainty
csainty / download_device.bat
Created August 29, 2011 01:18
WP7.5 Isolated Storage Tool
"C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool\ISETool.exe" ts de b8c6eab0-543c-4b55-be96-0b3da982df37 "C:\Users\chris_sainty\Desktop\IsoStore"
@csainty
csainty / index.html
Created October 7, 2011 13:51
Knockout Blog Post
<ul data-bind="template: { name : 'tweetTemplate', foreach: tweets }"></ul>
<input type="text" placeholder="search..." data-bind="value: searchTerm" />
<button data-bind="click: search">Search</button>
<script type="text/x-jquery-tmpl" id="tweetTemplate">
<li class="tweet">
<img src="${profile_image_url}" alt="${from_user}" />
<p class="content">
@csainty
csainty / ApiModule.cs
Created October 10, 2011 10:15
Nancy Demo Blog
public class ApiModule : NancyModule
{
private readonly IDataStore _Data;
public ApiModule(IDataStore data) : base("/api")
{
_Data = data;
Get["/messages/list"] = p => Response.AsJson(_Data.GetMessages());
@csainty
csainty / HelloWorld.js
Created October 27, 2011 05:38
Code for Node blog post
var http = require('http');
http.createServer(function(request, response) {
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
response.end('Hello World');
}).listen(8080);
@csainty
csainty / ApiModule.cs
Created November 29, 2011 03:34
Blog Post - Nancy + Mongo + AppHarbor
using System.Linq;
using MongoDB.Driver;
using Nancy;
using NancyMongo.Models;
namespace NancyMongo
{
public class ApiModule : NancyModule
{
private readonly MongoCollection<Message> _Messages;