Skip to content

Instantly share code, notes, and snippets.

@msarchet
msarchet / RetryRedisClient.cs
Created February 12, 2013 04:24
pseudo code for redis retry
public static TResult Retry(this IRedisClient client, Func<TResult> Retry)
{
try
{
return (TResult)Retry.Invoke();
}
catch(RedisException RedisException)
{
//Do Something Here To Wait
return (TResult)Retry.Invoke();
var oldUser = User;
User.UserStatus = (UserStatuses)Status;
var newUser = User;
using(var client = ClientManager.GetClient())
{
client.Replace<UserModel>(UsersKey, oldUser, newUser);
}
return User;
@msarchet
msarchet / Extensions.cs
Created February 7, 2013 04:17
Cleanly update an item in a ServiceStack.Redis.IRedisList<T>
/*
Sometimes you need to just udpate something and assure that it happens
*/
public static class GenericReplaceLock
{
public static void Replace<T>(this IRedisClient Client, string key, T old, T newer)
{
using (var redis = Client.As<T>())
using (var transaction = redis.CreateTransaction())
{
@msarchet
msarchet / Example.cs
Created February 1, 2013 16:06
Ghost Doc Example
/// <summary>
/// Joins the chat.
/// </summary>
/// <param name="UserName">Name of the user.</param>
/// <param name="authguid">The authguid.</param>
/// <exception cref="System.Exception">
/// Unable to find user
/// or
/// Unable to authorize user
/// </exception>
public async void CheckForRooms()
{
var getRooms = new Task<IList<RoomModel>>(() => { return _roomRepo.Rooms(); });
var Rooms = await getRooms;
var emptyRooms = new List<RoomModel>();
foreach (var room in Rooms)
{
if (_userRoomRepo.GetUsersForRoom(room.RoomName).Any())
{
emptyRooms.Add(room);
@msarchet
msarchet / Hub.cs
Created January 28, 2013 00:21
An Example of binding to a proxy later and adding a user to a group allowing a method on a proxy to be invoked
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace noproxySignalR
{
//This is the code required for the hub
@msarchet
msarchet / Hub.cs
Last active December 11, 2015 19:39
This is the code required to reproduce a bug in SignalR where joining a Group will allow messges to be invoked on the server even if the hub is not conencted to
//This is the code required for the hub
public class TestHub :Hub
{
public void joinGroup()
{
Groups.Add(Context.ConnectionId, "base");
}
public void Send()
@msarchet
msarchet / gist:4649919
Created January 27, 2013 19:26
Example For Dfowler
var TinyChat = TinyChat || {};
TinyChat.ConnectionID = '';
TinyChat.Connection = null;
TinyChat.Proxy = null;
TinyChat.StartChat = function () {
TinyChat.Connection = $.hubConnection();
TinyChat.Connection.logging = true;
@msarchet
msarchet / Example.cs
Created January 13, 2013 22:55
example
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
System.Diagnostics.Debugger.Launch();
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
@msarchet
msarchet / client.js
Created December 12, 2012 17:19
Functioning Array Call
$.connection.hub.start().done(function() {
$.connection.myHub.server.test(['1', '2', '3']);
});