Brain Droppings Thoughts, examples, and discoveries in software development http://andredublin.github.io/ Sat, 30 Dec 2017 01:55:42 +0000 Sat, 30 Dec 2017 01:55:42 +0000 Jekyll v3.6.2 A recap of 2015 <p>A recap of things that I’ve discovered, learned, read, met, etc. in 2015 in no particular order old or new.</p> <h4 id="reading-and-videos-on-software">Reading and videos on software</h4> <ul> <li><a href="https://medium.com/startup-study-group/40-npm-modules-we-can-t-live-without-36e29e352e3a#.6ggh5zhhs">40 NPM Modules We Can’t Live Without</a> - an excellent collection of very hepful node package modules.</li> <li><a href="http://www.myeyeson.net/functional-composition/">Functional Composition</a> - a gentle introduction in composing and create higher order functions.</li> <li><a href="http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html">Functors, Applicatives, And Monads In Pictures</a> - more functional programming goodness in pictures.</li> <li><a href="http://blog.fogus.me/2011/09/08/10-technical-papers-every-programmer-should-read-at-least-twice/_">10 Technical Papers Every Programmer Should Read(At Least Twice)</a> - a breadth of information that is useful from a computer science perspective.</li> <li><a href="https://scalablenotions.wordpress.com/2015/05/02/tpl-and-async-await-best-practices-for-the-busy-developer/">TPL and async/await Best Practices for the Busy Developer</a> - A comprehensive guide to understanding and utilizing the C# task parallel library.</li> <li><a href="http://blog.jenkster.com/2015/12/what-is-functional-programming.html">What Is Functional Programming</a> - Understanding what makes languages functional.</li> <li><a href="http://blog.jenkster.com/2015/12/which-programming-languages-are-functional.html">Which Programming Languages Are Functional</a> - Understanding what languages are actually functional.</li> <li><a href="http://mikestokes.co/programming/2015/02/08/storing-lists-in-entity-framework/">Using Lists with Entity Framework</a> - Necessary if your working with EF complex types.</li> <li> <table> <tbody> <tr> <td>[Build 2015</td> <td>Channel 9 Service Fabric Session](https://channel9.msdn.com/Events/Build/2015?sort=sequential&amp;direction=desc&amp;term=Service+Fabric#theSessions) - Researching the new service fabric distributed systems for work.</td> </tr> </tbody> </table> </li> <li><a href="https://www.youtube.com/watch?v=VIC7QW62-Tw">Volatility-Based Decomposition</a> - a coworker introduced me to Juval Lowy’s software architecture design, worth the watch.</li> </ul> <h4 id="programming-languages-ive-hacked-on-last-year">Programming languages I’ve hacked on last year</h4> <p>JavaScript, FSharp, Go</p> <h4 id="programming-languages-used-for-work-related-projects-last-year">Programming languages used for work-related projects last year</h4> <p>CSharp, JavaScript, FSharp, TypeScript</p> <h4 id="programming-languages-that-i-hope-to-explore-this-year">Programming languages that I hope to explore this year</h4> <ul> <li><a href="http://www.idris-lang.org/">Idris</a> - Just picked up Type Driven Development in Idris!</li> <li><a href="https://golang.org/">Go</a> - I explored GO a while back, but now a fellow software engineer acquaintance wishes to do some projects in go.</li> <li><a href="http://fsharp.org/">F#</a> - Honestly I’ve been playing with F# for the past eight months, and I hope to do more open source contributions this year.</li> </ul> <h4 id="papers-discovered-and-read">Papers discovered (and read)</h4> <ul> <li><a href="http://ramcloud.stanford.edu/raft.pdf">In Search of an Understandable Consensus Algorithm</a> - Actually read this a while back, but is a worthy of mention here for those that wish to understand the internals of distributed systems without losing their mind.</li> <li><a href="http://www.sqale.org/wp-content/uploads/2013/01/IEEE-SW-Managing-TD-with-SQALE-Accepted-version.pdf">Managing Technical Debt with the SQALE Method</a> - excellent read on how to analyze and quantify your teams technical debt.</li> </ul> <h4 id="community-efforts">Community efforts</h4> <ul> <li><a href="http://www.meetup.com/CharlestonJS/">CharlestonJS</a> - I’ve recently taken over as head of the CharlestonJS meetup group, this couldn’t be possible without the help of <a href="https://www.theironyard.com/locations/charleston.html">The Iron Yard - Charleston</a></li> <li><a href="https://vimeo.com/144107408">CODETalks 2015</a> - My presentation of Juval Lowry’s volatility based decomposition. This was a great experience and I hope to be back again in the future.</li> <li><a href="https://charlestontechslack.herokuapp.com/">Charleston Teck Slack</a> - I joined what’s possibly the best thing to happen to the Charleston tech scene.</li> </ul> <h4 id="music-discovered">Music discovered</h4> <ul> <li><a href="https://www.youtube.com/watch?v=sLO34NeyTDk&amp;list=RDsLO34NeyTDk">Mulatu Astaqe</a> - Ethiopian music is amazing! Check it out!</li> </ul> <h4 id="games-discovered">Games discovered</h4> <ul> <li><a href="http://hinterlandgames.com/">The Long Dark</a> - I’ve been playing survival games for a bit, and this one honestly captures the extreme pressures of surviving in the wilderness.</li> </ul> <h4 id="etc">Etc</h4> <ul> <li><a href="https://andresbees.wordpress.com/">Andres Bees</a> - I’ve become an amatuer beekeeping and decided to start a blog to track my progress and learn from my mistakes.</li> </ul> <h4 id="plans-for-2016">Plans for 2016</h4> <ul> <li>Contribute to the visual Fsharp power tools.</li> <li>Write some type providers in Fsharp.</li> <li>Write some Go.</li> <li>Discover some new music.</li> <li>Play guitar more.</li> <li>Play my <a href="https://en.wikipedia.org/wiki/Berimbau">berimbau</a> more.</li> </ul> <h2 id="comments">Comments</h2> Tue, 12 Jan 2016 00:00:00 +0000 http://andredublin.github.io/recap/2016/01/12/a-recap-of-2015.html http://andredublin.github.io/recap/2016/01/12/a-recap-of-2015.html recap What I Learned Reading the FSharp Source Part One <p>As part of my learning experience into the F# language, I’ve taken the time to begin reading through parts of the source code that catches my eye to gain a stronger foothold and understanding of the language that I would usually skim over when reading the MSDN docs. The nice thing about reading the source code is that they provide tests to describe the functionality. So most of my time will be spent exploring the tests, some of the source code, and MSDN documentation. Lets begin!</p> <h2 id="arrays">Arrays:</h2> <p>Arrays are not immutable according to the tests where the Array.set method is used to modify an index within the array. Once I saw that I immediately went to the MSDN docs and discovered that “Arrays are fixed-size, zero-based, mutable collections of consecutive data elements that are all of the same type.” I haven’t had a use case for arrays in my work so far, but I can forsee it being useful for collections that will never change size.</p> <script src="https://gist.github.com/andredublin/40e1f0012bed59ac80ad.js"> </script> <h2 id="concat">Concat</h2> <p>Arrays can be built from sequence expressions, which I find quite nice to look at.</p> <script src="https://gist.github.com/andredublin/90ee3393680cbbe0e654.js"> </script> <p>We can also combine expressions to build multidimensional arrays, and that Array.concat will concatenate (flatten) an array of arrays the documentation states and provides and example that it only concatenates a sequence of arrays. This confused me at first that the documentation would state a sequence of arrays, but I was reminded that array implements <code class="highlighter-rouge">IEnumerable&lt;T&gt;</code>. Looking at the signature of Array.concat:</p> <script src="https://gist.github.com/andredublin/674f13f5a0152bd51ac6.js"> </script> <p>We see that it indeed does take a sequence of arrays then Seq.ToArray is called before the concat operation happens. If we are given an array of arrays then we go straight to the concatArrays method thanks to the match expression. Where we see the operator <code class="highlighter-rouge">:?</code> that matches the value to the type expression <code class="highlighter-rouge">('T[][])</code></p> <script src="https://gist.github.com/andredublin/4806e25a5773c6bf5d5f.js"> </script> <p>Which then calls an internal methods concatArrays, concatAddLengths, and concatBlit to return a result.</p> <script src="https://gist.github.com/andredublin/8f6dfd12586f8d66754e.js"> </script> <p>There is a whole lot of goodness going on in these three functions so let’s dive in! The first thing that catches my attention is this line:</p> <script src="https://gist.github.com/andredublin/a753c0e936c08527b2c1.js"> </script> <p>Where we call zeroCreateUnchecked hiding at:</p> <script src="https://gist.github.com/andredublin/8993fbd2efdc01be001c.js"> </script> <p>That calls a common Intermediate language instruction (cil) <code class="highlighter-rouge"># newarr</code> that creates a new array of type ‘T of the concatenated array length of all zeros. Then we call concatBlit with the array of arrays, two counters, and the combined length of the final array. Within that method we have a check for the <code class="highlighter-rouge">i</code> counter is greater than the number of arrays in the array, assign <code class="highlighter-rouge">h</code> to the “i”th array assign <code class="highlighter-rouge">len</code> to the length of <code class="highlighter-rouge">h</code>. Then we call the class method Array.Copy.</p> <script src="https://gist.github.com/andredublin/fe6e7f4d17400c7358a9.js"> </script> <p>Array.Copy then uses the class method Array.Clone to create a shallow copy of the one-dimensional array that is down casted using the operator <code class="highlighter-rouge">:?&gt;</code> to a type of array <code class="highlighter-rouge">‘T[]</code>, where originally they were using zeroCreate and a for loop to push the values. Finally the new array <code class="highlighter-rouge">tgt</code> is built recursively until the <code class="highlighter-rouge">i</code> counter equals the number of arrays in the array. Whew! that’s a lot for just Array.concat!</p> <h2 id="sub">Sub</h2> <p>Next on to Array.sub where we see some tests for it here:</p> <script src="https://gist.github.com/andredublin/614b78c27f45248ab328.js"> </script> <p>Then the module definition here:</p> <script src="https://gist.github.com/andredublin/0e93b4871bf98d158c9d.js"> </script> <p>Where we first do some validation of the array to make sure it is not null and within the array bounds. Next we call subUnchecked located at with the startIndex, count, and the array:</p> <script src="https://gist.github.com/andredublin/17dd9b0a1a47f3dbf4cc.js"> </script> <p>Which it then calls on zeroCreateUnchecked to initialize an empty array, then we check if the size of the desired subarray is less than 64 indexes, and use a for loop if it is or the class method Array.Copy if it is greater. The reasoning behind this is probably due to the efficiency that a for loop has over arrays less than 64 indexes.</p> <h2 id="folding-and-optimized-closures">Folding and Optimized Closures</h2> <p>Now taking a look at module definitions for folding:</p> <script src="https://gist.github.com/andredublin/ccf620d60d9b9de9dbbc.js"> </script> <p>What really catches my eye is “OptimizedClosures.FSharpFunc”. So looking at the documentation <a href="https://msdn.microsoft.com/en-us/library/ee340450.aspx">here</a> I learned that it is used to invoke the implementation of a function. It reminds me of a C# Func&lt;&gt; delegate, but I imagine there is more going on here. So we find the optimized closures and fsharp func located <a href="https://github.com/andredublin/visualfsharp/blob/0f514efe25899ba59778b5bb522e2724aec44a3d/src/fsharp/FSharp.Core/prim-types.fs#L3236-L3391">here</a> Going back to fold module definition</p> <script src="https://gist.github.com/andredublin/bbd7dd7c7bbbdeb9b60f.js"> </script> <p>We see the FSharpFunc is invoked to update the mutable state.</p> <p>Well that’s it for part one of my exploration of the fsharp source code. Please let me know if I missed anything interesting or explanations within my current search.</p> <h2 id="comments">Comments</h2> Wed, 30 Sep 2015 00:00:00 +0000 http://andredublin.github.io/fsharp/.net/2015/09/30/what-I-learned-reading-the-fsharp-source.html http://andredublin.github.io/fsharp/.net/2015/09/30/what-I-learned-reading-the-fsharp-source.html fsharp .net Automapper and Entity Framework Proxies <p>I’ve recently learned about Automapper for mapping objects to other objects and I couldn’t be happier with the results from its use in my day to day projects. However I did come across a situation where I needed to map POCOs to entity objects. What I was trying to do is map the properties of the POCO to an entity that needed to be modified and saved during an update operation within my Web API project. So using the familiar:</p> <script src="https://gist.github.com/andredublin/43528bea0caeed93de87.js"> </script> <p>However I discovered that Automapper was removing my retrieved entity object from the object graph that entity framework provides us in order to track changes of the object state. This of course was not acceptable and I didn’t want to have us go through and map the properties of POCO to entity by hand.</p> <p>Now I could go and call the static Mapper class and define the types of the objects every time I need to map from POCO to entity making use of typeof:</p> <script src="https://gist.github.com/andredublin/429102131c38410fd139.js"> </script> <p>But this isn’t a great way of enabling these mappings, plus its a lot of typing, so I created a helper method that wraps this logic and makes use of generics types instead of using typeof as parameters of the method:</p> <script src="https://gist.github.com/andredublin/90340f0a9c5d51d1dd2e.js"> </script> <h2 id="comments">Comments</h2> Tue, 25 Aug 2015 00:00:00 +0000 http://andredublin.github.io/.net/2015/08/25/automapper-and-entity-framework-proxies.html http://andredublin.github.io/.net/2015/08/25/automapper-and-entity-framework-proxies.html .net Nginx and Angular url routing <p>Lately I’ve had the opportunity to work with Angular on a regular basis. At first it has been a challenge due to a large learning curve with the framework. But after a couple projects things have been moving smoothly. Anyway this post is a blurb on how to properly route request from Nginx to your Angular application.</p> <p>Lots of resources recommend the follow Nginx configuration for your application.</p> <script src="https://gist.github.com/andredublin/6c028fe1aba4bf7c21dc.js"> </script> <p>Note that this is working with an Angular app that is running in html5mode.</p> <p>So in our Nginx conf we have our root location try_files directive that checks for the existence of files in order, and then returns the first file that is found.</p> <p>Now this gets us 50% of the way there. What happens when you have nested routes? e.g. foobar.com/fizz/buzz or query strings? e.g. foobar.com/fizz/buzz?ping=pong.</p> <p>Well Nginx gets you part of the way there with query strings but not nested routes. After some hours of reading Nginx documentation and searching for answers, I came across this solution.</p> <p>In you Angular application entry point file, usually index.html. Inside the head tag section place this tag, <code class="highlighter-rouge">&lt;base href="/"&gt;</code></p> <p>This will allow Angular to handle all route request properly.</p> <h2 id="comments">Comments</h2> Mon, 18 Aug 2014 00:00:00 +0000 http://andredublin.github.io/javascript/2014/08/18/nginx-and-angularjs-url-routing.html http://andredublin.github.io/javascript/2014/08/18/nginx-and-angularjs-url-routing.html javascript Docker, CentOS, and Aerospike DB <p>My recent endeavors with Docker have been quite rewarding. From creating a MongoDB cluster, to a Nginx load balanced reverse proxy container that routes an Angularjs container with a Nodejs API container backing that up. Theres definitely no looking back to provisioning VMs alone anymore.</p> <p>But recently a new database has piqued my interests <a href="http://www.aerospike.com/">Aerospike</a>. So with this new NoSQL DB I wanted to run it within a CentOS container. However there are some current problems that you may run into until the <a href="https://bugs.centos.org/view.php?id=7126#c19831">CentOS 6.6</a> base image is released on the public docker registry.</p> <p>Primarily the issues that arise are the package dependencies that Aerospike and the Aerospike documentation call for. Here is the example from my current Dockerfile</p> <script src="https://gist.github.com/andredublin/f4fdf7a0ce41ab0481cb.js"> </script> <p>Starting at the <code class="highlighter-rouge">Install necessary software and dependencies</code> comment I install wget, tar, logrotate, sudo, and the final odd command system-config-services. This is where you may run into trouble since the documentation requires you to start your Aerospike with the command <code class="highlighter-rouge">sudo service aerospike start</code> and you get centos complaining that sudo or service doesn’t exist.</p> <p>But those final two commands will help resolve this issue. If you notice that the <code class="highlighter-rouge">system-config-services</code> command is prepended with <code class="highlighter-rouge">--enablerepo centosplus</code> this allows yum to get packages from the CentOSPlus repository.</p> <p>Now CentOS recommends that when you require dependencies from that repository to only enable it when you can to pick the exact package that you want to use, vs. enabling it in your <code class="highlighter-rouge">/etc/yum.repos.d/</code> since it is not part of the CentOS upstream distribution. So consider this fix to be experimental until the updated base image is released.</p> <p>I plan on following up with a demostration of an Aerospike cluster using containers so stay tuned.</p> <h2 id="comments">Comments</h2> Wed, 02 Jul 2014 00:00:00 +0000 http://andredublin.github.io/architecture/2014/07/02/docker-centos-and-aerospikedb.html http://andredublin.github.io/architecture/2014/07/02/docker-centos-and-aerospikedb.html architecture Large query string values and Azure <p>By default Microsoft IIS accepts a maximum query string length of 2048 characters. If there is a query string received by the IIS with more than 2048 characters, it will throw a 404.15 - Query String too long error.</p> <p>If your running a service on Azure and are running into issues sending very large values over http via a get request. Then you will have to set the maxQueryString property value to compensate for your request.</p> <p>Unfortunately many answers to this problem fail to address when working on an azure instance. In that context you will need to upload a Web.config file to the wwwroot folder of your instance. Under the system.webServer, security section, add the requestFiltering section. Under the requestFiltering section, add the requestLimits tag with your desired maxQueryString value. Now your web service or web site will be able to accept a maximum query string length you desire. In the example below I have it set to accept a maxQueryString value of “10000” characters. Even if you set a big value for maximum query string, there is a limit for each browser which is handling the url and the query string.</p> <script src="https://gist.github.com/andredublin/802d5c0596e2a3275fbe.js"> </script> <p>The best practice is to limit the maxQueryString size as much as possible, to avoid any injection attacks. You can give a value based on your requirements, but keep in mind that alllowing long query strings is a potential security risk and bad design.</p> <h2 id="comments">Comments</h2> Thu, 26 Jun 2014 00:00:00 +0000 http://andredublin.github.io/.net/2014/06/26/large-query-string-values-and-azure.html http://andredublin.github.io/.net/2014/06/26/large-query-string-values-and-azure.html .net Code Talk Python vs. PHP vs. Ruby <p>I was invited to give PHP a fighting chance at the Charleston Digital Corridor CODEtalk forum. Check out the video <a href="http://vimeo.com/93199441">here</a>.</p> <h2 id="comments">Comments</h2> Thu, 08 May 2014 00:00:00 +0000 http://andredublin.github.io/talks/2014/05/08/codetalk.html http://andredublin.github.io/talks/2014/05/08/codetalk.html talks