Skip to content

Instantly share code, notes, and snippets.

View Danthar's full-sized avatar

Arjen Smits Danthar

  • The Netherlands
View GitHub Profile
@Danthar
Danthar / gist:7580931
Created November 21, 2013 12:43
Javascript shim to properly add bootstrap 3 styling to validation helpers et al in asp.net MVC 4
$(function () {
$('span.field-validation-valid, span.field-validation-error').each(function () {
$(this).addClass('help-block col-xs-12 col-sm-reset inline');
});
$('.validation-summary-errors').each(function () {
$(this).addClass('alert');
$(this).addClass('alert-error');
$(this).addClass('alert-block');
@Danthar
Danthar / gist:b64bd263fa27ca962f06
Last active August 29, 2015 14:03
Merge data from a list of ajax requests using jQuery deferred
var dataArguments = ['args1','arg2','arg3','arg4'];
var bucket =[];
$.when.apply($,$.map(dataArguments, function(arg){
//here you setup and return an ajax request
//for example
var ajaxData = {term:arg, somethingelse:0};
return $.ajax({
@Danthar
Danthar / gist:a41b42442d0d996e0903
Created November 7, 2014 13:15
Example of mapping action parameters in an actionattribute for MVC
public class LogAttribute : ActionFilterAttribute {
private IDictionary<string, object> parameters;
private string description;
public LogAttribute(string description) {
this.description = description;
}
public override void OnActionExecuting(ActionExecutingContext filterContext) {
parameters = filterContext.ActionParameters;
@Danthar
Danthar / gist:5f7e27956707de633431
Created March 24, 2015 14:13
Consume RabbitMq messages with Akka
system = ActorSystem.Create("myAkkaSystem");
var coordinator = system.ActorOf<WorkCoordinatorActor>("workcoordinator");
bus = RabbitHutch.CreateBus("host=localhost");
bus.Subscribe<CdrRecieved>("<mysubId>", message => {
var result = coordinator.Ask<WorkCompleted>(new StartWorkFor() {Details = message}).Result;
//do something with it
});
@Danthar
Danthar / gist:2526439ce65f3502b18d
Created April 13, 2015 14:01
Aks and Sender references
coordinatorActor.Ask<string>(new JuleeDoTheThing());
//meanwhile in the coordinatorActor..
//..
Receive<JuleeDoTheThing>(message => {
_askParent = Context.Sender;
childActor.Tell(new DoSomething());
@Danthar
Danthar / gist:d1fe5581a6ba13ca6e30
Created April 15, 2015 07:42
Akka.net Nested ask async await issue example
using System;
using Akka.Actor;
namespace AkkaAsyncAwait
{
class Program
{
static void Main(string[] args)
{
var system = ActorSystem.Create("MySystem");
@Danthar
Danthar / gist:594d08dc26bc36cfab34
Created April 24, 2015 06:42
Consume RabbitMq messages with Akka : Part 2
//this is with the easynetq librabry but could just as easily be anything else.
rabbitBus.Subscribe<MyMessageType>(subscriptionId, message => {
Log.Debug("message from rabbitmq received");
//this works! because of how Ask works (it creates a fake actor that is passed as sender behind the scenes)
var result = workers.Ask<WorkCompleted>(new StartWorkFor() {Details = message}).Result;
});
//however this...
@Danthar
Danthar / gist:5c44f93e65706467cc46
Created May 8, 2015 11:49
Simple akka supervision and retry with IUnboundedStash example
class Program
{
static void Main(string[] args) {
var system = ActorSystem.Create("failboat");
var actor = system.ActorOf(Props.Create(() => new ParentActor()));
actor.Tell(5); //this will fail
actor.Tell("This message will work");
@Danthar
Danthar / gist:12f1b2dd229d4e58927a
Created June 8, 2015 13:49
Start werkzaamheden - command based - vanaf scratch poc
public class WerkbonAggregate {
private WerkbonModel _state;
private List<object> _uncommittedEvents = new List<object>();
public WerkbonAggregate(WerkbonModel state) {
_state = state;
}
public void StartWerkzaamHeden(DateTime gestartOp){
@Danthar
Danthar / Throttler.cs
Created June 18, 2015 10:45
Basic throttler
//Usefull for consumer/producer processing where you keep track of how many work you have served up in the producer
//and call Wait with that amount
//then consumer will call Hit to signal some work has been completed.
//producer will block on Wait until consumer has catched up
public class Throttler {
private AutoResetEvent resetEvent = new AutoResetEvent(false);
private int counter;
private int throttleAmount;