Skip to content

Instantly share code, notes, and snippets.

@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;
@csainty
csainty / app.js
Created January 10, 2012 05:26
Blog Post: node-webkit-twitter
var nwebkit = require('node-webkit');
nwebkit.init({
'url' : 'index.html',
'width' : 800,
'height' : 600
});
@csainty
csainty / app.js
Created January 16, 2012 07:42
Blog Post - node-webkit onclose
var nwebkit = require('node-webkit'),
http = require('http');
var server = http.createServer(function(request, response) {
response.writeHead(200, { 'Content-Type': 'text/plain'});
response.end('Hello');
}).listen(3000, '127.0.0.1');
nwebkit.init({
'url' : 'views/index.html',