Regex based Lexer with F#

This lexer allows you to define your regular expression based rules in a very declarative way using F# computation expressions. open Lexer let definitions = lexerDefinitions { do! addNextlineDefinition “NEWLINE” @”(\n\r)|\n|\r” do! addIgnoreDefinition “WS” @”\s” do! addDefinition “LET” “let” do! addDefinition “ID” “(?i)[a-z][a-z0-9]*” do! addDefinition “FLOAT” @”[0-9]+\.[0-9]+” do! addDefinition “INT” “[0-9]+” do! addDefinition “OPERATOR” @”[+*=!/&|<>\^\-]+”…

2

I finally got fed up with Enum.Parse

I don’t know why I didn’t do this long ago, but I am done writing this: var val = (SomeEnum)Enum.Parse(typeof(SomeEnum),”someString”); I have typed this too many times and it annoys me.  I wrote a small extension method on the string type to make this better: public static class StringExtensions { public static T ToEnum<T>(this string…

4

DRY and Unit Tests don’t mix well

When reading source code, I sometimes come across unappealing code(sometimes even my own).  However, there is one kind of “bad code” I see quite frequently.  It is a set of unit tests which have had the DRY (Don’t Repeat Yourself) principle unduly forced upon them.  DRY is the idea that you shouldn’t have to write…

0

A functional take on console program loop in F#

Often when learning a new technology I start with a simple console application in which the program is run in a loop it continues to prompt you for more input until you give some command like quit or exit or whatever you choose: Enter input: someInput someOutput Enter input: otherInput someoutPut Enter input: quit Thanks!…

1

Synchronizing Scrollbars using JQuery

I just wrote this simple plugin for JQuery which lets you synchronize the scroll bars of any collection of elements.  This lets you move the scrollbar of one div it have the scrollbars’ of the rest of the divs move the same exact amount. Here is the code: 1: jQuery.fn.synchronizeScroll = function() { 2:  3:…

1

Prime Factorization using Unfold in Haskell

I randomly yesterday started thinking about the unfoldr function in Haskell while working out at the gym (how nerdy is that, I am lifting iron but thinking of functional programming). Unfoldr take a single and an unfolding function and turns it into a list (the opposite of fold).  At the gym I was thinking about…

3

Code Assumptions

My co-workers and I recently came across a piece of code which exposed some assumptions we had about the “correct” behavior of two functions; these assumptions turned out to be false.  The code dealt with determining if the IP of a  request coming into to a website matches a certain range of IP address. The…

1

Snippet Designer 1.1 Released

I just released Snippet Designer 1.1.  This is not a major release but just some bug fixes and often requested changes to make the snippet designer more useful.   Some of the most notable changes are: Languages Service are turned OFF by default now.  Since I was unable to figure out a way to host…

3

Model Binder

When working with a multi-tier application I often find myself converting from one of the tiers object models to my own similar (but often different) model.  I often write code that would set one by one each property from a web tier object to my object.  In order to make this easier I wrote this…

0

Updated JQuery ResizeComplete method

I made 2 slight changes and I think it works pretty well now.  I now detect if the browser is Firefox and use the regular resize event since its resize behaves like a resizeComplete.  I also modified the timeout a bit since I think 100 ms might be too small. Here is the updated version:…

1