Posts

Showing posts from 2017

Christmastime In Philadelphia, 2017

Image
Philadelphia, December 2017

How to Mock JSNLog in Jasmine Unit Tests of Angular Code

One of the development teams at work implemented JSNLog to log from JavaScript in an Angular application we're working on, but even though the documentation to get this set up and running was very clear, the way to get it mocked for unit testing was not . Fortunately, it's not too difficult. The key in getting this to work was to spy on the JL function and have it return a mock with spy methods for the different logging methods (debug(), trace(), etc). Then set it up in your providers declaration. Here's the mock object: export   class   JLMock  {     trace = jasmine.createSpy( 'trace' );     debug = jasmine.createSpy( 'debug' );     info = jasmine.createSpy( 'info' );     warn = jasmine.createSpy( 'warn' );     error = jasmine.createSpy( 'error' );     fatal = jasmine.createSpy( 'fatal' )...

W. T. Grant’s A Very Merry Christmas

Image
I didn’t have a very happy childhood, but some of my fondest memories from when I was young, memories which I cherish, are of baking Christmas cookies with my mother. I was in my early school days, starting around kindergarten or maybe before. I remember rolling out the dough on a round table in our kitchen and using cutouts to make the cookies we would then decorate. Thinking about it now, these are probably my happiest childhood memories. While we’d be making the cookies, my mother would play Christmas music from some old records. They were compilation albums from the 1960s featuring artists of the day performing traditional Christmas songs. To this day it remains my favorite kind of Christmas music. In the years since then, I remembered two album covers specifically: one was a white cover featuring round Christmas tree ornaments with pictures of contemporary stars like Jim Nabors and Johnny Mathis, who appeared on the album, inside the ornaments; the other, which I was sure was ...

Retro Review: The Mummy's Ghost

Image
Synopsis The Mummy terrorizes New England. Again. Wash, rinse, repeat. Review This movie is almost an exact copy of the previous film, The Mummy's Tomb , which I enjoyed (read my review  here  -- shameless plug). So why didn't I like this one ? For starters, I didn't find any of the characters likable. The plot was too similar to the previous film -- I was hoping for something different this time around. This was just more of the same. There's an additional plot twist this time around, with the main character ( Biff? Joe? Butch? ) having a girlfriend of Egyptian descent who has a strange connection to the Mummy and (SPOILER) is the reincarnation of the Mummy's old love...which was part of he plot of the original  film. It did  have an ending I didn't expect. I'll give it that  much. It just felt like a rehash. Also, I'm not sure why it was called The Mummy's Ghost .  Unless I missed something, he was just the same old undead Mummy we'...

Retro Review: Bride of Frankenstein

Image
Synopsis The villagers thought they destroyed the monster, but they were wrong. As he makes his way through the countryside, Dr. Frankenstein’s mentor returns, on a quest to once again create new life. Review I enjoyed this film more than the original. Even though it’s titled  Bride of Frankenstein  (though the poster and advertising refer to it as The  Bride of Frankenstein ), the movie is about much more than that. We see the monster grow and develop. He becomes a sympathetic character. Meanwhile, Frankenstein’s former mentor Dr. Pretorius arrives at the castle and shows Henry Frankenstein the life forms he’s created, which I found to be unexpected. It was an odd turn for the film, but one that isn’t lingered on. The ending is a little predictable, but also has an unexpected bit of heart to it. I found this one to be an enjoyable entry Universal’s series of monster films.

Retro Review: The Mummy's Tomb

Image
Synopsis 30 years after the events of the previous film, Steve Banning is telling his house guests about the undead mummy he and Babe Jensen (now named Babe Hanson  for some reason) battled in Egypt all those years ago. But unbeknownst to any of them, the villains from the previous film survived and have waited 30 years (again, for some reason) to plot their revenge. Review Now we're talkin'. I found the original 1932 The Mummy  to be tedious (and lacking in much mummy, ironically), and found the sequel, 1940s The Mummy's Hand  to be an improvement, but still...lacking much of the mummy. However, this time around he gets plenty of screen time and the plot moves at a quicker pace. I found the timing to be too coincidental: Steve is telling his guests about the mummy, and miles away in Egypt, the plot for revenge is being hatched. What timing. And yes, that's  the part I find unbelievable, and not that an ancient mummy walks the earth! But I digress. The film t...

Universal Monsters and Retro Review: The Mummy's Hand

Image
I've only recently become a fan of the old Universal monster movies. My interest was first piqued a long time ago by one of my favorite retro video games, Zombies Ate My Neighbors , with its extensive use of classic monster movie imagery. But only in the past two years have I begun going through those old films. And while they're not specific to Halloween, so closely has this imagery been associated with the season that they may as well be Halloween movies for me, and that's when I watch them. These films tend to run a little over an hour, which is obviously very short for a film by today's standards. And even though they're quite old, I was surprised by how well some of them still hold up. For example, I think House of Frankenstein  is a great film. I recently watched The Mummy's Hand , which is the first sequel to 1932's The Mummy . Even though that film is considered a horror classic, I don't care much for it, as I found it extremely slow and not ...

How Unit Tests Have Helped Me Write Better Code

Image
I am not perfect. This fact alone supports the need to do my due diligence when it comes to the code I write to make sure it does what it's supposed to, without unintended side-effects, in the most efficient, and extensible, way possible. Rather than say why I think developers should write unit tests, I will instead describe how I've benefited from them. PROLOGUE A number of years back, I worked with a lead developer who had a wide breadth of technical knowledge and whom I considered highly intelligent, perhaps even borderline brilliant. He was (and is) a smart individual, but he saw no use in unit tests. He told me that when he first started working for the company, one of the first things he did was to delete all the unit tests, and he even tried to convince me that the practice of writing unit tests was now being considered a thing of the past, and told me he'd forward me a link to an article he'd read stating as much. I try to keep an open mi...

Creating Buttons That Act Like Links in Angular

While working on a pet project in Angular tonight, I wanted to create some buttons that act like links. Turns out, this is easy -- just apply the routerLink directive to a button and it will act like a link. Here's an example: <button class="btn btn-success" routerlink="/exercises/edit" >Edit an Exercise</button>

Where Everybody Knows Your Name

Image
The classic television sitcom Cheers  tells us that "Sometimes you want to go where everybody knows your name." And when I was in my late teens and earlier twenties, there was a place like that where I spent a lot of my time. Only it wasn't a bar, it was a pool hall. The Rack Room was located on Route 1 in Langhorne, Pennsylvania. It was located behind a Denny's with which it shared a parking lot. It was a pool hall (and a parking lot for that matter) in which I spent a lot of my free time. I'd been introduced to the place when I was 16. I'd been working part-time at a grocery store and one of my friends/co-workers from there was a regular. I hadn't spent much time in pool halls up until that point, and truth be told I still can't shoot a very good game. I spent just as much time in the Rack Room's arcade playing the latest Mortal Kombat  game as I did shooting pool But it wasn't as much about the pool as it was about having a place to ha...

I-95 Marketplace Remembered

One of the staples of my youth was the I-95 Marketplace, an indoor fleamarket which was located in Langhorne, Pennsylvania. It was only open Friday through Sunday (adding Thursdays and eventually the other weekdays during the holidays), and the interior was a large, open space comprised of small shops separated by poles and canvas. You could find all sorts of products there, from clothing, electronics, toys, furniture, books -- pretty much anything. I would typically go there Friday evenings after school. I'd walk through the woods behind my house, cross two sections of creek, walk under two sections of I-95 itself (the northbound and  the southbound), before finally emerging from the woods and arriving at the back of the marketplace building. I have many vivid memories of making the trek in dark, rainy weather, often arriving with wet (or drenched!) sneakers and cuffs, sometimes muddy, but always ready to head inside and spend my allowance on comic books or music or whatever els...

How To Mock Out Child Components In Unit Tests of Angular 2 Code

I was struggling with this one for a bit but found a solution this past weekend. When writing unit tests of a component that contains child components, the solution is to do the following: 1.       Create small mock classes in your test file to represent the child components and include just the functionality you’ll be mocking. These classes should have the @Component() decorator applied to them and contain selectors that match the real components they are being substituted for. 2.       Specify these mock components in the declarations section of the object you’re passing to TestBed.configureTestingModule(). Example: ActivityMgmtComponent has a few child components. Here are two of them: < activity-edit   #viewEditActivity ></ activity-edit > < activity-history   #viewActivityHistory ></ activity-history > Notice the # values – these are there to support the @ViewChild decorator f...

"Arithmetic operation resulted in an overflow" Error When Retrieving Data From Oracle In .NET

I ran into this fun little exception today when calling a stored procedure in Oracle from some .NET code. The error message was "Arithmetic operation resulted in an overflow", and from what I was able to Google, it seemed like it was caused by a difference in precision between numeric data types in .NET and Oracle, or  by the need to compile the code in 32-bit mode. But in my case, neither was the cause. When one of our DBAs suggested I try the same code using the simple "SELECT 1 FROM DUAL" query, and the exception still  occurred, I began to look for other reasons. Fortunately, it was an easy fix. The cause of the problem was actually a setting on the DevArt OracleCommand object being used in the .NET code. Here is the offending line of code: command.FetchSize =  int .MaxValue; Removing this line of code corrected the problem.

Using Webpack to Bundle CSS with Images and Fonts

One of my teams at work is currently developing in Angular 2, and we use Webpack for all of our TypeScript transpilation, module loading, and bundling. Yesterday we ran into an issue where one of the developers had made references to CSS files located in the node_modules directory of one of the 3rd party libraries we're using. This presented a problem because we don't distribute the node_modules folder as part of our build and deployment process -- we use JavaScript bundles created by Webpack. To correct the problem, I leveraged Webpack again, this time to bundle the required CSS files. The first step was to create a SASS file (.scss) which would be used as the entry point by Webpack. The reasoning behind using SASS was to allow us to do more than just reference the other stylesheets. But for the time being, it would do just that, and act as our entry point for Webpack to build its dependancy graph of our styles. Here's what the SASS file looked like at the start: @im...