Subscribe: Jeffry Houser's Blog
http://www.jeffryhouser.com/rss.cfm?mode=full
Added By: Feedage Forager Feedage Grade A rated
Language: English
Tags:
application  background  body  code  color  content  create  css  flash  flex  import  object  page  parameters  part  string 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Jeffry Houser's Blog

Jeffry Houser's Blog



Jeffry Houser's Blog



Published: Thu, 19 Oct 2017 07:22:18 -0600

Last Build Date: Tue, 17 Oct 2017 09:00:00 -0600

 



Angular Unit Testing: How do I Fix a Platform with a Different Configuration Has Been Created?

Tue, 17 Oct 2017 09:00:00 -0600

I've run into this one a few times. You're setting up Unit Testing of an Angular application and get an error like this:
Uncaught Error: A platform with a different configuration has been created. Please destroy it first.
It's frustrating and a but confusing. If you Google on that error you'll find a bunch of stuff, but no explicit solution. You've probably set up a TestBed configuration environment as part of your unit testing, probably like this: import { TestBed } from "@angular/core/testing"; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing"; TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); However, somewhere in the code, the non-testing modules have been loaded, probably like this: import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule); The error occurs because of the conflict between the platformBrowserDynamic() and the platformBrowserDynamicTesting(). Make sure that you exclude the source files the import and initialization of the non-test version of the library. In your karma.conf file add an exclude property to the Karma configuration object, something like this: exclude : "src/app/main.ts", In my case, today, the error was related to a missing '/' in the excluded directory structure. I hope this helps someone.



How do I fix IE11 problems with CSS Calc and min-height?

Tue, 10 Oct 2017 10:00:00 -0600

I hate it when you have a problem that you cannot replicate in a simple example. That's exactly where I am. I'm working on an application built with HTML, CSS, and various JavaScript frameworks. The application requires a footer to be aligned at the bottom of the page. If the content is too large for the page, then the the footer should show up under the content. But, if the content is too small for the page, the footer should show up at the bottom of the window, or viewport. This should be pretty simple to build using CSS and HTML:
Lots of Main Content and navigation and headers Here
Some Footer Information Here that should always be at the bottom of the page
The CSS would be something like this: html, body { height: 100vh; margin : 0; } .wrapper { min-height: calc(100% - 200px); } footer { height : 200px; background-color : blue; } The actual client project code is a lot more complex, but this gives you the gist. Play with the code here. Ignore my design skills. The problem I was having was that IE11 seemed to have a problem with the min-height. When clicking in the page, or clicking a link to go to another page, it was as if the wrapper's min-height would shrink down on pages where the view height was greater than the actual content. This would cause the footer to jump to the middle of the page. For the life of me, I haven't been able to create a simple sample to demonstrate this. Some part of the client's custom code seems to be causing this. After some head banging and conferring with my team, I came up with this solution. It makes use of JavaScript and JQuery to 'hard code' the min-height on the wrapper. Instead of using the CSS Calc. this happens when the page loads and whenever the page is resized. if(/MSIE \d|Trident.*rv:/.test(navigator.userAgent)){ function onResize(){ /* The jquery calc code */ $('.wrapper').css('min-height', '100%').css('min-height', '-=200px'); } $(window).resize(function() { onResize() }); $(window).ready(function(){ onResize() }); } I used a regex trick to only execute the code for IE browsers. And I used this answer as a base for my solution. Part of our problem solving this was my inability to create a simple reproducible case, but pouring over thousands of line of code I could not find the magic style combination that caused the 'footer jump' problem. Frustrating; but the JS code above seems to solve the issue admirably.



Create TypeScript Modules - - Part 8

Fri, 18 Aug 2017 13:00:00 -0600

This is the last in my series of articles intended to introduce you to Typescript. It is bonus material I wrote for my Angular 4 book. This is the last part of the series. Check out part 1, part 2, Part 3, Part 4, Part 5. and Part 6, and Part 7. When writing a real-world application, it does not make sense to include all the code in a single file. TypeScript supports that by allowing you to expand different functionality into modules. Create Interface Module The first thing we're going to do is create a module for the name interface. I put this in a file named IFile.ts: export interface name { firstName: string; middleInitial? : string; lastName: string; getName() : string; }; This looks exactly like the Interface created in the previous exception with the one addition of the export keyword. Export tells the compiler that this class is available for use inside other classes. Create Class Modules Now create the Person class: export class Person implements name { firstName: string; middleInitial : string; lastName: string; getName() : string { return this.firstName + ' ' + this.middleInitial + ' ' + this.lastName; } } This also puts the export keyword in front of the class definition. If you try this you'll notice an immediate error. The name is not defined. To define it we'll need to add an import statement: import {name} from "./IName"; The import statement tells you that the name entity is imported from the IName file and can be used within this class. The path I used, './IName', tells us that the files are in the same directory, however we can use a more elaborate package setup, and most likely you will do that for main applications. We can create the Pets.ts module in the same manner: import {name} from "./IName"; export class Pet implements name { firstName: string; lastName: string; type : string; getName() : string { return this.firstName + ' ' + this.lastName + ", " + this.type; } } This code mirrors the Person module, with the primary changes being the use of the export keyword before the class definition and the import of the name interface. The Echo class needs a similar rework: import {name} from "./IName"; export class Echo { static readonly messageIntro : string = "Hello" subjectArray : name[]; private message : string; constructor(subjects : name[]){ this.subjectArray = subjects; } createMessage():void{ this.message = ''; for (let person of this.subjectArray){ this.message += Echo.messageIntro + " " + person.getName() + ""; } } echo():string{ return this.message; } } The functionality remains unchanged. Like the previous classes it uses an export statement to make the class available elsewhere, and an import statement to make use of the name interface. Rework Main Application With all the classes stored in separate files, our primary app has become a lot simpler. First, import all the classes: import {name} from "./IName"; import {Person} from "./Person"; import {Pet} from "./Pet"; import {Echo} from "./Echo"; Then, create the nameArray: let nameArray : name[] = []; Now, populate the nameArray: let jeffryInstance : Person = new Person(); jeffryInstance.firstName = "Jeffry"; jeffryInstance.middleInitial = "A"; jeffryInstance.lastName = "Houser"; nameArray.push(jeffryInstance); let hercInstance : Pet = new Pet(); hercInstance.firstName = "Hercules"; hercInstance.lastName = "Houser"; hercInstance.type = "Dog"; nameArray.push(hercInstance); let zeusInstance : Pet = new Pet(); zeusInstance.firstName = "Isadora"; zeusInstance.lastName = "Houser"; zeusInstance.type = "Dragon"; nameArray.push(zeusInstance); Create an instance of the Echo class: let echoInstance : Echo = new Echo(nameArray); Call the createMessage() function: echoInstance.createMessage(); Finally, output the results: document.body.innerHTML = echoInstance.echo(); The changes here was, primarily, r[...]



How do I Extend a Background Color the Full Height of a Div with CSS?

Fri, 11 Aug 2017 06:19:00 -0600

Last week I used CSS to tile a graphic across the whole width of a page. The purpose was to extend a header bar's color when the page scrolled right beyond the iniital viewport. Now, with the same project I wanted to extend the left nav to the full height of the page. I couldn't use the same trick as you can't tile two separate background images. This is still doable with some CSS. First, start the HTML Body: We want the body to be the height of the view area: body { height : 100vh; } This sets the body to 100% height of the view area. Now create our content wrapper div inside the body:
This code uses FlexBox for display: .flex { display : flex; height : auto; min-height : 100%; } It also contains a trick. The height is set to auto and the min-height is set to 100%. That, combined with the body's height of 100vh will extend this div through the full height of the page. Finally, create our left nav bar inside our Flex div:
Some Text and other things
This is styled with a specific width, but no specific height. I also specified the color .somebar{ width : 150px; background-color:blue; color : white; } Check out the code here. I've been doing a lot of HTML CSS work for a client, but I'm working on some longer programming based articles which will be coming out soon.



Can I create an HTML Background with an inline Image?

Fri, 04 Aug 2017 11:05:00 -0600

I'm working on a site for some clients, and one of their complaints was that the left nav bar was not extending the full height of the page. The nav div was set to expand to its content, which meant it stopped when it ran out of content. On some pages it looked fine, on others the nav bar ended too early. As a programmer, I don't often deal with design issues like this, so I pulled in the project's designer and we put our heads together to find a solution. First, the problem was very generically like this: Title body { margin : 0px; } .nav{ background-color : #0000FF; width : 200px; height : 50%; color : #ffffff; } .nav a { color : #ffffff; } Some info in the nav bar Some Link Our code was much more complicated, using Flexbox for complicated layouts, but this is simple enough example to demonstrate the problem. We were not able to use a simple height:100% in CSS because some parent containers used Flexbox styling and did not stretch the full height of the page. My designer friend recommended tiling a background image. We can change the CSS for the body tag to something like this: body { margin : 0px; background: top left url(blue1x200.png) repeat-y; } The blue1x200.png is an image with just the color blue in it which has a height of 1 pixel and a width of 200 pixels. The repeat-y clarification tells the browser to repeat this image on the y axis, meaning up and down. This solved our issue, so whatever was happening to the page nav or the page content it would not prevent the left 200 pixels on the page from showing up the same color as the background. Using the url attribute to the background CSS will force the page to spawn another HTTP request to load the image. My designer had a trick for that too. He converted the image to a Base64 string representation and replaced the URL: background: top left url('data:image/png;base64,iVBORw0KGgoAAAAN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LVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGsw[...]



Goodbye Flash

Thu, 27 Jul 2017 09:35:00 -0600

Adobe announced an End of Life for the Flash Player. I've written things in defense of Flash in the past and thought it would be worth it to revisit those statements today. Who Am I? If you came across this without knowing me, I am arguably one of the best Flex Developers in the world. I tied my business and professional life to the Flash Platform, and Flex, more than a decade ago. Here are some of my credentials: I produced two Flex podcasts. a href="http://www.theflexshow.com">The Flex Show presented highly edited community interviews. and The Flextras Friday Lunch was a live demo with Q&A. I created Flextras, a business selling Flex components. I was editor in chief of the short-lived Flex Authority magazine. I spoke at dozens of Flash based user groups and conferences. I answered a ton of questions on StackOverflow and still retain the top spot in the Flex user charts. I became an Adobe Community Professional due to my work in the Flash community. I was one of the founding PMC members of the Apache Flex team. Back then, I bet that Flex would provide a better application building experience than anything HTML could offer. I thought it would rule the world. I wanted to get in early and ride the wave to success. I took a calculated risk that turned out to be wrong. Why Does Adobe's Decision Makes Sense? Browsers have slowly been shutting down their plugin APIs and Flash Player was a plugin. Flash was able to get around this because it is widely used and Adobe was able to negotiate to add Flash directly into the browser. Both Microsoft Edge and Google Chrome are distributed with Flash. These APIS have slowly become more restrictive over time and the future of the web will be plugin-free. Since HTML is finally adding a native form of DRM, the bulk of the major content providers no longer need Flash's proprietary nature to protect their content. This removes the last commercial obstacle which I suspect has been keeping the Flash player alive. Jeffry, How does this Affect You? Personally, I spent a couple hours last night playing Bloon Tower Defense one of my favorite casual browser games. I hadn't touched it in years, but I'll miss it when it is finally gone. Professionally, this doesn't affect me all that much. I refactored my business more than five years ago to focus on alternate technologies. In the HTML world, I really like Angular, but I've touched on a lot of different technologies. I never turn down the Flex work that comes my way, and people still find me based on my past history. But, I am not actively pursuing it. If you need help migrating your Flex applications to an HTML5 platform, I'd be glad to help, so reach out and we can discuss. How does this Affect you? Adobe will stop distributing the Flash Player in 2020, but the Adobe Flash Platform will live on through Adobe AIR. Given AIR's use as a cross platform mobile app development platform I expect that to be around for a long time. If you still have Flash applications in production, now is the time to start planning a migration of sorts. You have, roughly, 2 years to plan your strategy. What migration strategies can you use? Distribute to the Desktop as an Adobe AIR application. You can use all your existing code and the migration will not take long. Distribute as a Mobile Application with Adobe AIR. This has the benefit of using the same code base, but you'll probably need some UI rework to accommodate for the different screen sizes. Rework to HTML5: You can rework your application into an HTML5 application. You should be able to reuse a lot of your services and database code, which means you'll just be writing a new UI. Some technologies such as FlexJS or Haxe allow you to use your ActionScript skills in the process I'll be more than happy to help you with any of these tasks, so give me a call. What Next? I had a fun ride with the Flex communit[...]



How can I revert a Git directory without affecting all changes?

Mon, 17 Jul 2017 09:00:00 -0600

I have been working on a specific code change with a client for about two weeks. This included about a dozen commits to the git repository before making a pull request. The client reviewed the pull request before merging, and requested I roll back a few changes. I had made these commit 8 commits ago, and from the dozens of files changed I only had to roll back two. How do you do it? I didn't see an obvious way to roll back just those files using SmartGit, my tool of choice, so I had to drop back to the command line. This did it: git checkout SHA-Value /c/path/to/repo/root/path/to/subdirectory/with/rejected/changes The SHA is the unique identifier for each commit. I opened up SmartGit, viewed a change log, found out which commit I changed these files, went to the commit before that, clicked 'details' and the SHA value is listed right there. You can also get the SHA value from GitHub if you prefer. Go into the Pull Request, and select commits. The value is in the table, to the right of the commit message. The path to the directory is your local system path. I had to use the absolute path. Since I'm a Windows user that started with the C drive, drilled down into my project folder, to the repository. And then I drilled down deeper into the repository to find the specific subdirectory I wanted to revert. Reverting the subdirectory is easier than reverting all the files individually. I executed the line inside of GitShell. Everything worked. I found a bunch of posts covering this topic, but most of them confused me. Hopefully this helps someone. Let me know!



How can I control the parameter order when doing a HTTP POST call from Flex?

Tue, 11 Jul 2017 09:40:00 -0600

I've been working on a legacy AIR application for a client. It integrates with a backend I have no control over. According to their documentation, we need to pass the form parameters in a specific order. This seems unusual for a form post, which contains key-value pairs and is probably not accessed in parameter order. But due to other problems integrating with this service, I decided to see what I could do to specify the parameter order and remove that as a possible point of failure. I wrote about my attempts in this StackOverflow question.

What Didn't Work

This is what we were doing. First, create an HTTPService: Then, create the parameter object in code: var parameters : Object = new Object(); parameters.firstParameter = "firstOne"; parameters.amount = 100; parameters.otherParameters = "Other Random Misc Data"; parameters.lastParameter = "LastOne"; When the parameter object is created for the service call, I added the parameters to the object in order. Then make the call: var call : Object = this.service.send(parameters); call.addResponder( this.responder ); You may have already guessed why this won't work. Object parameters, or keys in a dictionary, are by definition, not in any specific sort order. When the Flex code looped over all parameters to add them to the outgoing service, it was accessing them in alphabetical order. However, that is not something I would bet my life on happening every single time due to the unordered nature of object properties. I also noticed that the outgoing request in the Flash Builder network monitor had the parameters in yet another order. Something with them changed between the Flex code and the server hit. So, what am I to do?

Using Lower Level APIs to make this work

The final solution was to use lower level APIs. I created the request using URLRequest and URLLoader classes. Instead of passing an object to the request I also had to manually create the request body which is very similar to a URL parameter string. First, create the parameter string: var parameters : String = ''; parameters += "firstParameter=firstOne&"; parameters += "amount=100&"; parameters += "otherParameters=Other Random Misc Data&"; parameters+= "lastParameter=LastOne"; Then, create the URLRequest: var r:URLRequest = new URLRequest(yourURLHere); r.data = parameters; r.method = URLRequestMethod.POST; r.contentType = "application/x-www-form-urlencoded"; The data is set to the parameters string. The method is set to POST and the contentType is set to 'application/x-ww-form-urlencoded'. And finally, create the URLLoader: var l:URLLoader = new URLLoader(); l.addEventListener(Event.COMPLETE, myResultMethod); l.addEventListener(IOErrorEvent.IO_ERROR, myFailureMethod ); l.addEventListener(SecurityErrorEvent.SECURITY_ERROR, myFailureMethod ); l.load(r); After doing this I could see in the outgoing requests that the parameter order was retained. So, things were good and my issue was solved! This is a lot more tedious than using the HTTPService, but at least I eliminated it as a possible error.