Skip to content

Instantly share code, notes, and snippets.

View typesafe's full-sized avatar

Gino Heyman typesafe

  • Element 80 BV
  • Belgium
View GitHub Profile
///<summary>
/// Provides methods for raising domaing events and registering their handlers.
///</summary>
public static class DomainEvents
{
[ThreadStatic]
private static List<Delegate> actions;
/// <summary>
/// Gets or sets the service provider used to resolve event handlers.
@typesafe
typesafe / ng-submit.js
Last active August 29, 2015 14:19
ngSubmit with $attempted directive
AppModule.directive('ngSubmit', function () {
var thiz = this;
thiz.submit = function (ev, scope, el, attr) {
el.removeClass('shake');
var frmController = scope[attr.name];
frmController.$attempted = true; // can be used to provide visual feedback
if (frmController.$invalid) {
el.find('.ng-invalid')[0].focus();
@typesafe
typesafe / alerts.js
Created July 28, 2014 14:19
AngularJS $alerts module
(function(angular) {
var alertsModule = angular.module('alerts', []);
alertsModule.service('$alerts', ['$rootScope', '$q', function($rootScope, $q){
var _this = this;
var broadcast = function(topic, clazz, data){
var d = $q.defer();
$rootScope.$broadcast(topic, angular.extend({clazz: clazz, deferred: d}, data));
return d.promise;
};
@typesafe
typesafe / api.js
Created May 12, 2014 18:47
resolve parameters in expressjs
var server = require('./server.js');
var collection = require('./collection.js');
var app = server();
app.put('/items/:id/part', server.resolve(collection), function(req, res){
// no more 404 checking
// access resolved item
@typesafe
typesafe / tabindex directive
Created April 11, 2014 16:33
angularjs directive to make tabindex attributes work with routing
MyModule.directive('tabindex', function () {
return {
restrict: 'A',
link: function (scope, elem, attr, ctrl) {
if (attr.tabindex == 1) {
elem.focus();
}
}
};
});