Tiny types scala edition

Previously I wrote about generating value type wrappers on top of C# primitives for better handling of domain level knowledge. This time I decided to try it out in scala as I’m jumping into the JVM world.

With scala we don’t have the value type capability that c# has, but we can sort of get there with implicits and case classes.

The simple gist is to generate stuff like

package com.devshorts.data

case class foo(data : String)
case class bar(data : String)
case class bizBaz(data : Int)
case class Data(data : java.util.UUID)

And the implicit conversions

package com.devshorts.data

object Conversions{
    implicit def convertfoo(i : foo) : String = i.data
    implicit def convertbar(i : bar) : String = i.data
    implicit def convertbizBaz(i : bizBaz) : Int = i.data
    implicit def convertData(i : Data) : java.util.UUID = i.data
}

Now you get a similar feel of primitive wrapping with function level unboxing and … Read more

Simple log context wrapper

I’m still toying around with the scala play! framework and I wanted to check out how I can make logging contextual information easy. In the past with .NET I’ve used and written libraries that wrap the current log provider and give you extra niceties with logging. One of my favorites was being able to do stuff like

var foo = "1";
var bar = "2";
logger.With(new { foo, bar }).Info("data")

Which would output a log line like

data, foo=1; bar=2

The logger’s “with” was even chainable so you could capture a previously built “with” context and re-use it. It was really nice when you want to create a baseline logging context for complex functions.

Java doesn’t have the concept of anonymous classes and I’m not sure you can do optimizations with reflection like you can with .NET (creating reflective based property invokers into delegates).

Either way, this makes for a … Read more

Conditional injection with scala play and guice

It’s been a crazy year for me. For those who don’t know I moved from the east coast to the west coast to work for a rather large softare company in seattle (I’ll let you figure which one out) and after a few short weeks realized I made a horrible mistake and left the team. I then found a cool job at a smaller .net startup that was based in SF and met some awesome people and learned a lot. But, I’ve been poached by an old coworker and am now going to go work at a place that uses more open source things so I decided to kick into gear and investigate scala and play.

For the most part I’m doing a mental mapping of .NET’s web api framework to the scala play framework, but the more I play in play (pun intended) the more I like it.

On … Read more

Quickly associate file types with a default program

I use JuJuEdit to open all my log files since it starts up fast, is pretty bare bones, but better than notepad. The way my log4net appender is set up is that log files are kept for 10 days and get a .N appended to them for each backup. I.e.

FooLog.log
FooLog.log.1
FooLog.log.2

Etc.

I hate having to go through each one and set the default program to open since its slow and annoying. A faster way is to use cmd (not powershell!) and use the assoc and ftype commands.

You can associate an extension (like .2) with a “file type” (which doesn’t really mean anything) and then map the file type to a program to open.

For example:

>ftype logfile="C:\Program Files (x86)\Jujusoft\JujuEdit\JujuEdit.exe" %1
>assoc .3=logfile
>assoc .4=logfile
>assoc .5=logfile
>assoc .6=logfile
...

And now they all open with juju edit. If i ever want to change it I … Read more

Creating stronger value type contracts

I’ve long been annoyed that value types don’t have strong semantic information attached to them such that the compiler would barf if I try and pass an value type that isn’t semantically the same as what the function wanted. For example, what does the following signature mean other than than taking in 2 ints and returning a bool?

IsLoggedIn :: int -> int -> bool

What I’d really like the signature to look like is

IsLoggedIn :: UserId -> SessionId -> bool

In F# you can do this sort of with type aliases and augmenting the signature with the type information. However, its just editor magic, it doesn’t actually compile to anything that would stop you from accidentally calling a function with the arguments reversed. An int is an int is an int, right?

var userId = 1
var sessionId = 2

IsLoggedIn(sessionId, userId)

This is perfectly valid to the … Read more

AngularJS for .Net developers

A few months ago I was asked to be a technical reviewer on a new packt pub book called AngularJS for .Net developers. It mostly revolves around ServiceStack (not web API) and building a full stack application with angular. I actually really enjoyed reading it and thought it touched on a lot of great points that a developer who is serious needs to know about.

Unfortunately I think the book doesn’t do a very good job at explaining angular in general. It’s certainly geared to the experienced developer who has worked with angular and servicestack/c# REST before.

Still, if you are interested in using angular as a .net developer its an informative and quick read! … Read more

Leveraging message passing to do currying in ruby

I’m not much of a ruby guy, but I had the inkling to play with it this weekend. The first thing I do when I’m in a new language is try to map constructs that I’m familiar with, from basic stuff like object instantiation, singletons, inheritance, to more complicated paradigms like lambdas and currying.

I came across this blog post that shows that ruby has a way to auto curry lambdas, which is actually pretty awesome. However, I was a little confused by the syntax

a.send(fn, b)

I’m more used to ML style where you would do

fn a b 

So what is a.send doing?

Message passing

Ruby exposes its dynamic dispatch as a message passing mechanism (like objective c), so you can send “messages” to objects. It’s like being able to say “hey, execute this function (represented by a string) on this context”.

If you think of it that … Read more

Sometimes you have to fail hard

This was a post I wrote in the middle of 2013 but never published. I wanted to share this since it’s a common story across all technologies and developers of all skill levels. Sometimes things really just don’t work. As a post-script, I did come back to this project and had a lot of success. When in doubt, let time figure it out :)


For the last couple of weeks, I’ve been trying my hand at the node.js ecosystem. I had an app idea but I wanted to make sure I chose tech stacks wisely. There’s no better way to get familiar with different stacks than to get your hands dirty and try them all, so that’s what I did.

Sometimes when you start with a new language or platform things come easy, you can blaze a burning trail writing great software. You’re like an extension of the computer, everything … Read more

wcf Request Entity Too Large

I ran into a stupid issue today with WCF request entity too large errors. If you’re sure your bindings are set properly on both the server and client, make sure to double check that the service name and contract’s are set properly in the server.

My issue was that I had at some point refactored the namespaces where my service implementations were, and didn’t update the web.config. For the longest time things continued to work, but once I reached the default max limit (even though I had a binding that set the limits much higher), I got the 413 errors.

So where I had this:

<service name="Foo.Bar.Service">
	<endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Foo.Bar.v1.Service.IService"/>
</service>

I needed

<service name="Foo.Bar.Implementation.Service">
	<endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Foo.Bar.v1.Service.IService"/>
</service>

How WCF managed to work when the service name was pointing to a non-existent class, I have no idea. But it did.… Read more

Short and sweet powershell prompt with posh-git

My company has fully switched to git and it’s been great. Most people at work use SourceTree as a gui to manage their git workflow, some use only command line, and I use a mixture of posh-git in powershell with tortoise git when I need to visualize things.

Posh-git, if you load the example from your profile, will set the default prompt to be the current path. If you go into a git directory it’ll also add the git status. Awesome. But if you are frequently in directories that are 10+ levels deep, suddenly your prompt is just obscenely long.

For example, this is pretty useless right?

2014-07-09 11_53_20-

Obviously it’s a fictitious path, but sometimes you run into them, and it’d be nice to optionally shorten that up.

It’s easy to define a shortPwd function and expose a global “MAX_PATH” variable that can be reset.

$MAX_PATH = 5

function ShortPwd
{
    … Read more