Jon's Programming Blog

Prototypes & Compositions with Objects

I was trying to figure out the best way to have functions be both compatible with an object oriented paradigm and a functional oriented paradigm when working on objects. My implementations are probably naive, but instructive nevertheless. It seems that lo-dash and other libraries have done a good job bridging those worlds. Let’s say you have an object O such that function O(a, b){ this.a = a this.b = b } var o = function(a, b){ return new O(a, b) } Now, you want to extend the object but you also want the option to use the object in a more fuctional way with compose.

Functional Immutability in JavaScript

This is taken from Michael Fogus' book Functional JavaScript in the chapter Purity, Immutability, and Policies for Change. Immutability is impossible to achieve in JavaScript without using Object.freeze but it only performs makes the object immutable shallowing, you have to roll your own deepFreeze if you would like to make the object truly immutable. So there are some practices you can do to make your functions and variables perform in a more immutable manner.

Functional or Object Oriented JavaScript?

When people are first exposed to JavaScript and its minimal set of tools (functions, objects, prototypes, and arrays), many are underwhelmed. Therefore, in order to “modify” JavaScript to conform to their idea of what it takes to model software solutions, they very often seek out or re-create class-based systems using the primordial ooze. - Michael Fogus Functional Programming Of course, the next sentence he softens that quote, I just enjoyed the first part though.

Notes on Monads, Monoids, and Make Believe

with Brian Lonsdorf Working with Objects the better way var SSN = Constructor(function(number, current_user){ this.number = number this.user = current_user }) SSN.prototype = { fmap: function(f){ if(this.user.is_admin) return SSN(f(this.number), this.user) } } social.fmap(replace('-', '')) //=> SSN('123456789', user) social.fmap(function(number){return number.reverse()}) //=> SSN('1234-56-789', user) the functor way Note: Functor function defined. var AdminAccess = Constructor(function(val, current_user){ this.val = val this.user = current_user }) Functor(AdminAccess, { fmap: function(f){ if(this.user.is_admin) return AdminAccess(f(this.val), this.user) } }) var social = AdminAccess('1234-56-789', current_user) fmap(removeDashes, social) //=> AdminAccess('123456789', current_user) fmap(validNumber, social) //=> AdminAccess(true, current_user) He then goes into other useful patterns with monads.

bilby.js & functional programming

I’ve been learning functional programming for quite some time and like the programming paradigm. But, it can be difficult sometimes. Some libraries like lodash.js can be easy to start learning, but others like bilby.js require that you understand more of the functional approach. So, here are some videos that have helped me understand bilby.js better. This one gives a quick overview. Note that Maybe (Haskell) is similar to Option (Scala)

Notes On Functional Programming

Patterns for the Non-Mathematician with Brian Lonsdorf Lenses Using lenses for composable/polymorphic model manipulation. E.g., var user = {id:1, name:{first:'doris', last:'day'}} var L = makeLenses(['name', 'first']) var firstNameChar = compose(, L.first, _1) over(firstNameChar, toUpperCase, user) //=> {id:1, name:{first:'Doris', last:'day'}} Maybe Use Maybe (Haskell) types (Option types in bilby.js / Scala style) to make composition easier. This works with fmap (functor maps). Returns resultant option. Error Handling (Either) Either('need an int', 3) //=> Right(3) Either('need an int', undefined) //=> Left('need an int') fmap(function(x){return x+1;}, Right(2)) //=> Right(3) fmap(function(x){return x+1;}, Left('need an int')) //=> Left('need an int') compose(fmap(f), Either(error)) Future Values I’ll have to come back to this one later when I use it more.

Spreadsheet Budget Launched

This first version is pretty basic - yet powerful. It will import your financial data from KMyMoney(I’ll add more financial programs later). Soon I will add report templates so you can easily view your finances - how you like it. It comes with an auto updater (wyUpdate) so you can stay up to date with the latest version with small packages. Let me know what financial program you use so I can add it to the list for future compatibility.

Bit Torrent Sync & Updating/Installing Programs

Bit Torrent Sync (BT Sync) is great software which can be used for syncing files. I use it for backing up all my pictures/videos/music/files/mobile computers. Well, I did some testing and it looks like it can be used for installing and updating software also. I tested it with my Windows 8 computer over to my Windows XP computer. I created an Excel xla add-in file and I also created an executable file.

Zipping Files with VBA and USB Drives

I used Ron de Bruin’s file zipping (and sending) code with Excel. It works great with a few tweaks. Unfortunately when someone is using a USB drive with their workbook on it it fails to work. So warning: Make sure the users are using it on the main computer when trouble shooting!


I have one Time Card template setup with SUMIFS (used for Excel 2007 and above templates) and one set up with MATCH/INDEX (used for my 2003 and below templates). I tested the calculation speeds for each in Excel 2013 (preview) on Windows 8. Here’s the VBA test code: Sub test() Dim dTimer As Double Dim iLoops As Integer, iTotalIterations As Integer Dim wksStage As Worksheet Set wksStage = ThisWorkbook.Worksheets("Staging Area") iTotalIterations = 1 dTimer = Timer() For iLoops = 0 To iTotalIterations wksStage.