Skip to content

Instantly share code, notes, and snippets.

@JefClaes
JefClaes / gist:7428657
Created November 12, 2013 10:22
Can you guess which country this is about?
What happened here was the gradual habituation of the people, little by little, to being governed by surprise; to receiving decisions deliberated in secret; to believing that the situation was so complicated that the government had to act on information which the people could not understand, or so dangerous that, even if the people could not understand it, it could not be released because of national security.
@ashic
ashic / gist:7371417
Last active December 27, 2015 18:39
C# vs F# 0MQ sync REP server
public class Server
{
private readonly NetMQContext _context;
private readonly string _id;
public Server(NetMQContext context, string id)
{
_context = context;
_id = id;
}
@mausch
mausch / gist:6774627
Created October 1, 2013 06:37
Applicative validation is simple.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
// As opposed to magic validation libraries that rely on reflection and attributes,
// applicative validation is pure, total, composable, type-safe, works with immutable types, and it's easy to implement.
public abstract class Result<T> {
private Result() { }
[AttributeUsage(System.AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class ಠ_ಠAttribute : Attribute
{
public ILog Log { get; set; }
public ಠ_ಠAttribute()
{
Log.Info("This code is bad and you should feel bad");
}
}
public class SomeClass {
public void SomeMethod() {
this.Log().Info(() => "Here is a log message with params which can be in Razor Views as well: '{0}'".FormatWith(typeof(SomeClass).Name));
}
}
@isaacs
isaacs / .gitconfig
Created June 8, 2012 19:01
These are my shortcuts for git.
# A bunch of the stuff above relies on this, especially the aliases.
[user]
# you probably want to change this bit.
name = isaacs
email = [email protected]
signingkey = 0x6C481CF6
[alias]
ci = commit
st = status
br = branch
@mausch
mausch / gist:2630024
Created May 7, 2012 20:01
VB.NET funcs
Just found out that VB.NET can infer function types correctly. I.e. this won't work in C#:
var withMemoryStream =
(Action<MemoryStream> f) => () => {
using (var ms = new MemoryStream())
f(ms);
};
("Cannot assign lambda expression to implicitly-typed local variable", because it can't tell a Func<T> from an Expression<Func<T>>).
But the exact same code in VB.NET does work:
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@paulmillr
paulmillr / mapreduce.scala
Created March 10, 2012 16:03
Why functional programming matters (aka MapReduce for humans)
import com.cloudera.crunch._
import com.cloudera.scrunch._
class ScrunchWordCount {
def wordCount(inputFile: String, outputFile: String) = {
val pipeline = new Pipeline[ScrunchWordCount]
pipeline.read(from.textFile(inputFile))
.flatMap(_.toLowerCase.split("\\W+"))
.filter(!_.isEmpty())
.count
@kellabyte
kellabyte / CQS_and_CQRS.cs
Created March 3, 2012 03:19
CQS_and_CQRS
// CQS (Command-Query Separation)
// Bertrand Meyer devised the CQS principle
// It states that every method should either be a command that performs an action, or a
// query that returns data to the caller, but not both. In other words, asking a question
// should not change the answer. More formally, methods should return a value only if they
// are referentially transparent and hence possess no side effects.
//
// Example:
public class CustomerService