Skip to content

Instantly share code, notes, and snippets.

View glennblock's full-sized avatar

Glenn Block glennblock

View GitHub Profile
@glennblock
glennblock / gist:1824681
Created February 14, 2012 07:43
receive message
var serviceBusService = azure.createServiceBusService(),
topic = 'taskdiscussion',
subscription = 'client1';
serviceBusService.createSubscription(topic, subscription, function(error1){
if(!error1){
// Subscription created
serviceBusService.receiveSubscriptionMessage(topic, subscription, function(error2, serverMessage){
if(!error2){
@glennblock
glennblock / fork forced sync
Created March 4, 2012 19:27
Force your forked repo to be the same as upstream.
git fetch upstream
git reset --hard upstream/master
//generic formatter which takes in a model and transforms it to something specific for the media type
//StrategyFormatter is a generic formatter that you derive from to create specific ones. You override the formatter methods to write the response.
public interface IFormatterStrategy<TOutput> {
TOutput Transform(object model);
}
//loops through all the formatter strategies and asks them to handle the model
public abstract class StrategyFormatter<TOutput> : MediaTypeFormatter {
public IEnumerable<IStrategyFormatter<TOutput>> Strategies {public get;private set;}
@glennblock
glennblock / gist:2394695
Created April 15, 2012 20:29
async exits with streamline
//this does not work because exists does not accept a standard callback
function createRequiredFilesIfNotPresent(_) {
var baseFolder = process.cwd();
var exists = path.exists(baseFolder + "/server.js");
log.info(exists);
}
//using a wrapper function however works. Log entries added for sequence.
@glennblock
glennblock / gist:2722523
Created May 18, 2012 00:57
Autofac dependency resolver and scope
public class AutofacApiDependencyResolver : AutofacDependencyScope, IDependencyResolver
{
private readonly ILifetimeScope _container;
public AutofacApiDependencyResolver(ILifetimeScope container) : base(container)
{
_container = container;
}
public IDependencyScope BeginScope()
@glennblock
glennblock / gist:2722862
Created May 18, 2012 02:48
Forms auth wrapping
public interface IFormsAuthentication
{
void SetAuthCookie(string userName, bool createPersistantCookie, string cookiePath);
void SetAuthCookie(string userName, bool createPersistentCookie);
}
public class FormsAuthenticationWrapper : IFormsAuthentication
{
public void SetAuthCookie(string userName, bool createPersistantCookie, string cookiePath)
MenuContext.cs
public class MenuContext : DbContext
{
public DbSet<MenuItem> MenuItems { get; set; }
public DbSet<Review> Reviews { get; set; }
}
MenuController.cs
public class CustomerController : ApiController {
private ICustomerContext repo;
public CustomerController(ICustomerContext repo) {
this.repo = repo;
}
public Customer Get(int id) {
var customer = repo.Customers.SingleOrDefault(c=>c.CustomerID == id);
if (customer == null) {
public class CustomerController : ApiController {
private ICustomerContext repo;
public CustomerController(ICustomerContext repo) {
this.repo = repo;
}
public HttpResponseMessage Post(Customer customer) {
repo.Add(customer);
repo.SaveChanges();
@glennblock
glennblock / gist:2947545
Created June 18, 2012 08:53
child processes
//child_process.js
var util = require('util'),
child_process = require('child_process'),
child,
cmd;
var os = require('os');
exec();