Skip to content

Instantly share code, notes, and snippets.

View jgauffin's full-sized avatar

Jonas Gauffin jgauffin

View GitHub Profile
(some translations are quite hard to do, since it's a lot of slang)
Feel free to improve the translation :)
Talking: Party on
Talking: Party on
Talking: It's vacation..
(Music from the bottle)
Talking: What the f**k?
Take a tjotablängare (slang for "take a shot/drink") for life.
@jgauffin
jgauffin / BaseController.cs
Created October 8, 2015 19:36
How to modify metadata
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var keywords = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MetaKeywordsAttribute), false);
if (keywords.Length == 1)
ViewData["MetaKeywords"] = ReplaceRouteData(((MetaDescriptionAttribute)keywords[0]).Value);
base.OnActionExecuting(filterContext);
}
@jgauffin
jgauffin / As
Last active August 29, 2015 14:17
As extension method
public static class ObjectExtensions
{
public static T As<T>(this object instance)
{
if (instance == null) return default(T);
var casted = instance as T;
if (casted == null)
throw new ArgumentException("Cannot cast '" + instance.GetType().FullName + "' to '" + typeof(T).FullName + "'.");
return casted;
@jgauffin
jgauffin / BasicAuthentication
Created January 13, 2015 12:03
Basic http authentication with Griffin framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Griffin.Net.Channels;
using Griffin.Net.Protocols.Http;
@jgauffin
jgauffin / BodyDecoder
Created January 12, 2015 19:10
Using Griffin.Framework without a BodyDecoder
using System;
using System.IO;
using System.Net;
using System.Text;
using Griffin.Net.Channels;
using Griffin.Net.Protocols.Http;
using Griffin.Net.Protocols.Http.Messages;
using Griffin.Net.Protocols.Http.Serializers;
using Griffin.Net.Protocols.Serializers;
@jgauffin
jgauffin / MicroMsg2.md
Last active August 29, 2015 14:08
MicroMsg2 - Fast and light weight protocol

MicroMsg2

Micromessage2 is an application layer network protocol which intention is to be lightweight but flexible. Reliable means that it can make sure that all messages are delivered (if you want to). Flexible means that it supports extensions out of the box (using EXTENSION frames).

The protocol follows semantic versioning which means that client/servers that speak the same major version should be able to communicate, even if the minor version is not matching. But with reduced functionality.

Client/Server architecture

This library is based on the assumption that the one connecting acts as a client and the one accepting a connection acts as a server. However, both sides may receive connections. Hence the term server/client is only applied for the current connection and not the applications.

@jgauffin
jgauffin / gist:8363852
Last active January 2, 2016 21:29
"Ask Azure", the full question
I've built a CQRS framework for Azure that uses ServiceBus.
But then I read the Service bus pricing and noticed that every request/reply would consume four messages (as for billing). Any chance of you changing the billing so one message is actually *one* message, instead of charging for each read/send?
The service bus is awesome, but the pricing is not. If you change the price, I'll release the CQRS framework as open source (Apache license).
//jgauffin
@jgauffin
jgauffin / IoC example
Created September 11, 2013 13:18
Examples on how to create unit of work in WinForms/WPF applications
// simple example, can of course be simplified using a ioc wrapper.
public void Button1_Clicked(object source, EventArgs empty)
{
using (var scope = Program.Autofac.BeginLifetimeScope())
{
var uow = scope.Resolve<IUnitOfWork>();
var repos = scope.Resolve<IUserRepository>();
var user = repos.GetUser(1);
user.LastName = txtLastName.Text;
@jgauffin
jgauffin / Example
Last active February 15, 2021 13:20
A better windows service helper - Makes it easier to debug windows service, and to uninstall/install them from the command prompt. From my blog post: http://blog.gauffin.org/2013/08/a-better-windows-service-helper/
internal static class Program
{
private static void Main()
{
// runs the app as a console application if the command argument "-console" is used
if (WindowsServiceHelper.RunAsConsoleIfRequested<Service1>())
return;
// uses "-install" and "-uninstall" to manage the service.
if (WindowsServiceHelper.ManageServiceIfRequested(Environment.GetCommandLineArgs()))
@jgauffin
jgauffin / gist:3911506
Created October 18, 2012 12:33
Code of the day
private void CheckForError(DataRow dr, string procedurnamn)
{
string fel_text = null;
try {
if (!string.IsNullOrEmpty(dr["FELTEXT"]) | dr["SQLCODE"] != 0) {
fel_text = "Procedur " + procedurnamn;
fel_text += Constants.vbCrLf + "PGM " + dr["PGM"];
fel_text += Constants.vbCrLf + "SEKTION " + dr["SEKTION"];
fel_text += Constants.vbCrLf + "TABELL " + dr["TABELL"];
fel_text += Constants.vbCrLf + "SQLKOD " + dr["SQLCODE"];