Skip to content

Instantly share code, notes, and snippets.

View bryanhunter's full-sized avatar

Bryan Hunter bryanhunter

View GitHub Profile
@bryanhunter
bryanhunter / gist:1256193
Created October 1, 2011 15:34
Session "Bringing Erlang into your C# Shop: a How-to"

OK... you've heard the Erlang success stories, you know the sweet spots, and you're convinced that Erlang is for you. Where does that leave you as a C# developer? In a pretty good spot actually. A team of C# and Erlang developers is a force to be reckoned with because Erlang and .NET are complements--each is lousy at what the other is exceptional at. Realizing this can save you and your company a lot of time, money and headaches. Many C# developers write both JavaScript and SQL scripts; adding Erlang to the mix should be just as natural. So how is it done? What are the best interop strategies? What are the development tools? Can it all be done on Windows? How about unit testing and deployment? What are the risks? How can they be avoided?

@bryanhunter
bryanhunter / HashCode.cs
Created October 20, 2011 16:25
Get hash code
public static class HashCode
{
public static string Of(string content)
{
var buffer = Encoding.UTF8.GetBytes(content);
var sha1 = new SHA1CryptoServiceProvider();
var hash = BitConverter.ToString(sha1.ComputeHash(buffer)).Replace("-", "");
return hash;
}
}
@bryanhunter
bryanhunter / build-erlang-r14b04.sh
Created December 1, 2011 17:14
Script to build Erlang 14B04 (tested on a fresh Ubuntu 11.10 install)
#!/bin/bash
# Pull this file dowm, make it executable and run it with sudo
# wget https://raw.github.com/gist/1418287/build-erlang-r14b04.sh
# chmod u+x build-erlang-r14b04.sh
# sudo ./build-erlang-r14b04.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@bryanhunter
bryanhunter / build-erlang-r15b.sh
Created January 12, 2012 20:52
Build Erlang R15B on a fresh Ubuntu box (tested on Ubuntu 11.10)
#!/bin/bash
# Pull this file dowm, make it executable and run it with sudo
# wget https://raw.github.com/gist/1603037/build-erlang-r15b.sh
# chmod u+x build-erlang-r15b.sh
# sudo ./build-erlang-r15b.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@bryanhunter
bryanhunter / CastleCommandHandlerDemo.cs
Created February 7, 2012 16:42
Commands sent to a CommandRouter get routed to the appropriate CommandHandler (using Castle.Windsor)
using System;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace CollectionResolverForGenericInterface
{
internal class Program
{
private static void Main(string[] args)
{
@bryanhunter
bryanhunter / oo-banana.md
Created February 10, 2012 04:05
Joe Armstrong on reusability in software (OO-vs-functional)

I think the lack of reusability comes in object-oriented languages, not functional languages. Because the problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.

If you have referentially transparent code, if you have pure functions-- all the data comes in its input arguments and everything goes out and leaves no state behind-- it's incredibly reusable. You can just reuse it here, there, and everywhere.

-Joe Armstrong, Designer and implementer of the Erlang programming language

@bryanhunter
bryanhunter / CaliburnMicroConventionsForActipro.cs
Created March 12, 2012 16:40
Caliburn.Micro conventions for Actipro controls
using ActiproSoftware.Windows.Controls.Ribbon.Controls;
using ActiproSoftware.Windows.Controls.Ribbon.Controls.Primitives;
using Caliburn.Micro;
namespace SampleApp
{
public static class CaliburnMicroConventionsForActipro
{
public static void AddConventions()
{
@bryanhunter
bryanhunter / erlang-memory.txt
Created March 30, 2012 23:23
Erlang memory usage
**ER15B 32-bit smp disabled**
Erlang R15B (erts-5.9) [async-threads:0]
Eshell V5.9 (abort with ^G)
1> Fun = fun() -> receive after infinity -> ok end end.
#Fun<erl_eval.20.111823515>
2> process_info(spawn(Fun), memory).
{memory,1308}
3>
@bryanhunter
bryanhunter / LeftJoinExtension.cs
Created May 10, 2012 04:23
Simplifies LINQ left joins
using System.Collections.Generic;
namespace System.Linq
{
public static class LeftJoinExtension
{
public static IEnumerable<TResult> LeftJoin<TLeft, TRight, TKey, TResult>(
this IEnumerable<TLeft> left,
IEnumerable<TRight> right,
Func<TLeft, TKey> leftKeySelector,
@bryanhunter
bryanhunter / TabSeparatedValueDataLoader.cs
Created June 13, 2012 23:00
Tab-separated Value data loader
public static class TabSeparatedValueDataLoader
{
public static IEnumerable<T> ParseTsv<T>(this string rawTabDeleimetedData, Func<string[], T> mapper)
{
IEnumerable<string[]> data = rawTabDeleimetedData.Split(new[] {'\r', '\n'},
StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Split(new[] {'\t'}, StringSplitOptions.None));
return data.Select(mapper);
}