- Details
- Category: Code
- By Stuart Mathews
- Hits: 2486
I’ve accomplished quite a lot this festive season. My last endeavour was deploying my project to the cloud. This entailed figuring out how Docker works, AWS container services and Travis CI among other things. Basically this all hinged round this rather good document: Deploy .NET Core with Docker to EC2 Container Service. I also connected it up to AWS RDS services using SQL Express 2017. So at the end of the day I’d reached my goal: I had my service deployed into a container on a linux host running in the cloud. And on top of that set it up in the code to automatically connect to the RDS database while in the cloud and to the localDB instance while its under testing on my laptop. Awesome.
One of the nice things about Container services in EC2 is being able to inject environment variables into the image at runtime so you don’t have to store any AWS keys with the source code. You just configure them with the container’s ‘task definition’ and apply them at runtime and get the code to look for its keys from the environment variables which have now been made available via this injection.
In .net core 2.0 you can hook into the environment via the IHostingEnvironment interface to see if you’re running in a production mode profile or a development mode profile and then switch your settings appropriatey. I switch to AWS RDS connection string (which I extract from environment variables which will be injected into the running container) and otherwise use the localDB. Which actually reminds me, I need to install 2017 Sql Express so I can have parity between my AWS and local environment as setup while I’m testing my code. Because you can’t have localBD on linux, it wouldn’t be quite the same, so having a connection to a local sql express 2017 is similar to a connation to RDS which is a SQL 2017 express instance. That’s one of my my next jobs.
I’ve also had some good luck with AWS however it has become quite apparent that to truly be ‘agile’ one needs to use CloudFormation templates to bring environments up and down. Agile meaning that I can do my stuff and then shut it all down and then bring it all up again real quick so I don't have to pay for hours and hours of running resources. So after I got my service deployed I deleted it and all its resources that it was using.
So basically What I’ve got up and running now is a .net core 2.0 web api service that uses EntityFramework Core 2.0. It also uses swagger for the API documentation and simple interaction. This was all to convert my project from full blown Asp.net MVC5(which is awesome btw) because I want to run it in the cloud as a scalable component and the problem with it is that full–blown MVC5 couples the front end website and the backend service tightly together. I want to deploy the two components as two separate things. The service will be a .net core web api service using EF(I had to change things to work rather with EF core 2.0 and not EF6 btw) and I want the front end to be totally independent on the code on the backend and just use HTTP to communicate with it. So I converted the front end MVC5 views to Angular 5 components and the backend to .net core 2.0.
So now I’ve got two independent components one in Angular/Html/TypeScript and one in C# .net core 2. Now I’ve been able to deploy the service as a Docker container to AWS and it works just perfectly. This is the first time I’ve seen .net core run in a container on a linux host. Very cool.
Now what I need to do is put the front end into a image and deploy that as a container too. This way these two parts can scale out much more easily in a cloud environment – my motivation was part Linux containers as well as AWS and using a scalable software architecture (Microservices like).
So I need to figure out how to learn how to script elastic container services and elastic cloud instances among other things. I’ll do that next I guess but I think this will take a while to learn so until I commit, I’ll just chill and do other things. Speaking of which:
I watched Ferdinand the bull movie as well as the new Star wars.
- Details
- Category: Code
- By Stuart Mathews
- Hits: 2724
When we talk about C and C++ and we talk about variables, we often refer to variable’s as names/symbols that ‘refer’ to things. We say things like that because we like to abstract ie. do represent complex things as simpler, and faster-to-understand. Its not accurate but its faster.
I’ve been reading “Game coding complete” today and this became evident.
People are generally very messy when it comes to using word terms that represent anything in languages. They often don’t articulate what they mean, and usually expect you to guess the same meaning they are assuming or figure it out. For instance.
“A variable refers to a thing” is messy because to truly represent what a variable is in C++ you would say that a variable is a name that stores an address in memory.That's really what a variable is.
The problem is that doing that all the time, makes things very verbose and time consuming especially when you have lots to say about something. We are lazy. So you use messy words that are faster and generally people figure out. So anyway, by point in this article is to say that because we learn from messy teachers, we dont know that all variables in C/C++ store addresses – not just pointers!
In C/C++ you have the following notations for variables:
[Type] [Variable-name] or [Type] [*] [Variable-name]
such as
char name;
char * name;
These are variable declarations.
Both store memory addresses: Some people don’t know that because they’ve learned by being taught by messy words which suggest that one of these variables store an address. That’s the consequence. Trust me,they both store addresses.
So mostly they look and do the same thing.
One is called a variable and the other is called a pointer variable. So how do they differ? And I’ll tell you how they differ at the implementation level.
char name; // variable stores a memory address say 0002, where say the content “Stuart” is stored or will be stored.
char* pname = &name; // pointer stores a memory address also of 0002, also thus where the content “Stuart” is stored.
The main difference between the two variables is what happens when the variables are read/accessed.
The * in the variable declaration denotes that the variable has access to the address its storing *directly*. You can think of the * asterisk as saying this variable has full access to its stored address(0002)
A variable without the asterisk does not have full access to its address, instead when you access it, it bypasses access to the address(which it still stores but just doesn;t have direct access so) and instead refers to the raw data/content at that memory location – not the memory location itself, not the number representing the memory address 0002.
So a non-pointer will always manipulate the data at the address location that it stores, the pointer will always manipulate the address itself that it stores. Done.
So in summary:
All variables store memory addresses whether they are pointers or not. Pointer variables, have the special ability (denoted by * during declaration) of accessing that memory address number. Normal variables don’t, and instead directly go to that address and manipulate the content at that address..not the address number itself.
Extra information.
Memory addresses can be addresses on the stack or on the heap. variables and pointers can store either. Depends on how they address is obtained:
int variable1(1); // stores an address on the stack and when you access that variable, you are manipulating the content of a int’s data at that location( in this case 1).
int *variable2(new int(2)); // stores a heap address also on the stack, but variable2 has direct access to that stack address…which happens to additionally store new address of a heap location returned by new()
That's really how it works. but to be more accurate each variable itself is a memory location on the stack, that just stores other memory locations on the stack. And depending on how the variable was declared will determine how the content of that memory location is read/accessed.
[some stack address] holds variable1’s content which always another stack address (who’s when accessed, the content 1 is directly accessed/amnipulated)
[some stack address] holds variable2’s content which in this case is a heap address who’s content when accesses, refers directly to that heap address.
Simple.
- Details
- Category: Code
- By Stuart Mathews
- Hits: 2776
The other day
I moved to Amazon Mail the other day. I got sick and tired of managing Postfix, Roudcube, Squirrelmail etc. So I changed my MX records and now all my mail is handled by Amazon. its got a great UI and It integrates really well with Outlook 2016 which I like and I like its built in Spam support. I could have gone with Gmail professional but I didn’t. Mostly this was because I'd just made a AWS account and had been studying the AWS service offerings so I just made sense. The other thing that started to make sense was to deploy my current projects into the Cloud via AWS and in the same vain, put my linux servers in AWS. So that’s what I’m doing now.
I’ve moved two of my websites from hosted on a VPS to a shared managed system where I drive the SQL via phpMyAdmin and have some web space that I can access via the Web. Honestly its been 10 years and I so need this now more than having my own servers running all the time and maintaining them. Awesome really. And so cheap too. This site infact was transplanted from my Linux server to a shared hosting space and I think it runs faster(its optimised by the hosting provider). Did the same with my notes and poetry sites.
Some really cool things AWS offers in terms of writing your software : http://notes.stuartmathews.com/doku.php/cloud. These are my study notes. I’ll be using some of these services in moving my projects to AWS and the cloud. Speaking about the cloud and writing scalable applications for it ….
Asp.net Core 2.0
I’ve started to move my Asp.Net MVC 5 web application to Asp.Net Core 2.0. The reasons are two fold. First is that I’d like to get away from the tight coupling between the Web Site and the API because in Asp.Net MVC 5 they go hand in hand. If one goes down, they both go down. This leads me nicely into my next reason. I’d like to create the service as a scalable component in the cloud. So decoupling the API and website means I could replicate these components if one or both go down. Its basically all about scaling now.
in fact there is another reason. Linux. Asp.net Core 2.0 run on Linux so it makes sense if I’m putting this stuff on the cloud to have a cheap Docker container. No license costs to Windows! Smart.
My progress is here: https://github.com/stumathews/CoreInvestmentTracker
Angular 2/5
Now while I’ve been doing this, I’ve decided to go away from Razor and MVC for the front end and do the web part in AngularJS2/5. Now there are two things that are noticeable about this:
- Its faster to run your API in Asp.Net Core 2.0 using WebApi
- OData id not supported in Asp.net Core 2.0
- Many-to-many relationships are not automatically catered for in Entity Framework for .net Core 2.0 so you need to use a join table. Agh but I’d used this work around and its just that.
- I’ve added swagger support to the .Net Core 2.0 API but not my Asp.Net MVC 5 one (maybe I’ll do that later for fun).
- Dependency injection is native – so no more unity (as in my MVC 5 API)
Now I’ve quite enjoyed writing the front end in Typescript and angular. I’ve always hated JavaScript because its so incredible messy and you can get yourself in such a horrible mess if you don't pay attention. And after 1000’s of lines of codes and many components of a website, you start straying from the path of consistent because you can be lazy in JavaScript and so lazy that its like holding a shotgun to your nose and with every strike of the keyboard you pull the trigger a little bit more… I’m not going to talk about why this is the case but along with Angular, the structure and infrastructure afforded by these two technologies is outstanding.
My progress is here: https://github.com/stumathews/investments/tree/master/ASPNET_MVC5/angular
Excel 2016 Add-in
I’m also looking to research more into what it takes to control your excel interactions programmatically. I’ve been able to set up a very basic add-in based on AngularJS. This is basically a website that uses the ExcelApi JavaScript library to interact with the excel app itself. Quite cool. No UDFs yet but can use named ranges to select and work with values.
My progress is going here: https://github.com/stumathews/Angular2ExcelAddin
More Articles …
Subcategories
Game Development Article Count: 28
I discovered the realms of game development purely by accident, having picked up a book entitled 'Core Techniques and Algorithms in Game Programming' and discovered a surprising niche of innovation in programming quite unparalleled to my day-to-day needs as a developer. Here optimisation, graphics rendering, and algorithms are used on a totally different level and its very interesting.
Page 11 of 17