Friday, February 10, 2017

First time connecting to Azure with Powershell - error

While I was following Microsoft's tutorial for connecting to Azure via Powershell I got an error message when trying to run this command: Login-AzureRmAccount


The error message was:


Login-AzureRmAccount : The 'Login-AzureRmAccount' command was found in the module 'AzureRM.Profile', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Profile'. At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule




In order to fix this issue I had to follow these steps:
  1. Open command prompt (cmd) as administrator
  2. type powershell Set-ExecutionPolicy RemoteSigned and press Enter
After this, the Login-AzureRmAccount command worked normally.

According to Microsoft, the Set-ExecutionPolicy command does the following (source):

The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies: 
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

Saturday, August 20, 2016

Installing NodeJs on a Linux Mint OS

I had to run a project in Visual Studio Code on a Linux machine (Mint) that needed NodeJs installed so I tried to follow the steps on the official page.

I realized, after some errors, that I was actually missing some things.

On the official page, the commands for the install are listed like this:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Before you can run this (successfully) you also need to install curl: sudo apt-get install curl

Apparently, curl, is a client tool used to get files over different kind of protocols, like http(s) and ftp without too much interaction. The legend goes that it can also support authentication (I'm kidding, it isn't a legend, it's true, check the official page) :).

Another thing that baffled me was the last "-" at the end of the first line. Because of it I thought there was just one command so I copied them both and tried to run them... with no success.

So, first take the first line:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

and when it is done, run the next command:
sudo apt-get install -y nodejs

After this you can check what version was installed with the command node -v. When you install Node you also get npm, which is the package manager for npm, basically where all the goodies come from.

Adding Node to PATH

After the installation is complete it is necessary that we add Node to PATH so that all the packages will be installed in that location. The first thing to do is to create a folder named npm in the home folder.

Open .bashrc file with a text editor. This file is also in the Home folder, but it is hidden. Right-click show hidden files.

Add at the end of the file: export PATH="$HOME/npm/bin/:$PATH".

If the terminal window is open, close it and open it again, then type echo $PATH and you should see the path to npm/bin listed.


Monday, July 4, 2016

Running the Angular 2 Quickstart tutorial in Visual Studio Code on Mac OS

In this post I will go through the steps that I took in order to complete the Angular 2 Quickstart tutorial (with Typescript) using Visual Studio Code on Mac OS. The versions for the software are as follows:

  • VS Code: 1.2.1
  • Mac OS: 10.11.5 (El Capitan)
The Angular 2 quickstart can be found at this link: https://angular.io/docs/ts/latest/quickstart.html.

We start by creating a new solution, which in VS Code is opening a folder. In the tutorial they named the folder angular2-quickstart. It doesn't really matter, so just make a new folder.

After this we need to follow the next few steps in order to have the solution up and running in VS Code.

1. Compiling the Typescript code to Javascript.

Open Command Palette with ⇧⌘P (or View -> Command Palette) and start typing Configure Task Runner.
Then, select Tasks: Configure Task Runner and you will get the next list:

From here you need to select TypeScript - tsconfig.json. This will create a tsconfig.json under the .vscode folder.


2. Installing NodeJs and npm (if you don't already have it).

This tutorial states that you need to have at least version 5.x.x for NodeJs and 3.x.x for npm. To check if you have the required version, open a terminal window (or the Integrated Terminal in VS Code) and type node -v for NodeJs and npm -v for npm.

From here on I have followed the steps in the tutorial. 

In order to be able to run the application from VS Code a few additional steps are required:

1. Click on the Debug icon on the left side.

2. Click on the cog icon and select NodeJs from the list. This will create a file called launch.json under the .vscode folder.
Note: if you click the cog icon again, nothing will happen. If you want to see the available options again, delete the launch.json file.

3. In the launch.json file, edit the program property so that it looks like this: ${workspaceRoot}/node_modules/lite-server/bin/lite-server

4. Click on the start icon and the application should start.

Wednesday, August 26, 2015

Integrating Swift with Objective C

I started to implement the new design for Jano (Japano) and I decided to do some small refactoring of the code.

In the Achievements screen I am displaying a list of levels that the user can achieve by taking tests in a UIScrollView. It's a maximum of 4 levels and each of the views needs to have a background image.

Initially I subclassed UITableViewCell and I wrote the code inside the class for the arranging of the GUI elements.
Now I want to use another class that will take care of the GUI only. I will do this using Swift and in this post I will write about how to combine the two types of files.

First thing, add a new file from the menu File - New - File and select Swift File. After naming it, Xcode will ask you if you want to add bridging header. Click Yes.

I have named the class LevelCellInterfaceTool. By default the class is not public, so I had to modify the access level of the class to public:


public class LevelsCellInterfaceTool: NSObject {

}
Inside the class I then created a public method (func) that just shows a simple UIAlertView:

public class LevelsCellInterfaceTool: NSObject {
public func ShowSimpleMessage()
    {
        let message = "This is a UIAlerView declared in Swift!"
        let v = UIAlertView(title: "Swift UIAlertView", message: message, delegate: nil, cancelButtonTitle: "Ok")
        v.show()
    }

}
The next challenge was to call ShowSimpleMessage from a class declared in an Objective C file (.h and .m). This was accomplished in 3 simple steps:

1. Forward declare LevelCellInterfaceTool in the interface file (.h) of the class that needs it: 
@class LevelsCellInterfaceTool;

@interface LevelsListCellTableViewCell : UITableViewCell

{
        
}

@end

2. In the implementation file (.m) use an #import directive for all the classes declared with Swift. In the official documentation it is saying to use a particular naming convention: ProductModuleName-Swfit.h.
In my case, ProductModuleName is the name of the project. So, it becomes Jano-Swift.h:

#import "LevelsListCellTableViewCell.h"
#import "Jano-Swift.h"

@implementation LevelsListCellTableViewCell
...
@end

3. Calling the method.
After writing a new method (func) in the Swift class it is necessary to first build the project so that the Objective-C class sees it (at least in Xcode 6.3.2).
Somewhere in the class instantiate the Swift class as you would with a regular Objective-C class:

LevelsCellInterfaceTool *guiTool = [[LevelsCellInterfaceTool alloc] init];
        [guiTool ShowMessage];
        [guiTool release];

Wednesday, September 17, 2014

How to install a Windows service from the command prompt

Installing a Windows service from the command prompt is a fairly simple task, only a few steps to follow.


  1. Build the project in Release mode
  2. Go to the Release folder and copy the full address from the address bar
  3. Open Visual Studio Command Prompt (On Windows 7 you can find it under Start - All programs - Visual Studio - Visual Studio Tools; on Windows 8 click start and start typing Visual Studio Command Prompt )*
  4. Install the service using the command installUtil and passing the path you copied at step 2: installUtil pathToFolder

If the service is already installed you will need to uninstall it first:
installUtil /u pathToFolder

*If on the machine where you need to install it you don't have Visual Studio, you will have to find the executable installUtil. On my Windows 8 (but I believe it is the same on Windows 7) it is in C:\Windows\Microsoft.NET\Framework\v4.0.30319


Monday, September 8, 2014

Creating a custom setter and getter for a property in Objective C


When creating the mobile application Jano I had to show different statistics in a special menu. It had to appear in a label (of course) and I wanted to format it according to the phone's style.

The best solution for me was to add a string property to the model that would return the NSNumber property formatted accordingly.

In the .h file I defined the public properties as follows:


@property (nonatomic, strong) NSString *ValueAsString;

@property (nonatomic, strong) NSNumber *Value;


In the .m file, the code appear like this:
@synthesize Value = _value, ValueAsString = _valueAsString; 


//Getter for ValueAsString
-(NSString*) ValueAsString
{
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setGroupingSeparator:[[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator]];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *result = [formatter stringFromNumber:_value];

    return result;
}

-(void)setValueAsString:(NSString*)value
{
_valueAsString = value;
}
Although I had no use for the setter, I added it here so that it would be a full example.

Thursday, August 28, 2014

JavaScript runtime error: Unable to get property 'call' of undefined or null reference

I got this error after I had installed a NuGet package with editor templates for Bootstrap for ASP.NET MVC 5.

The solution consisted of 2 steps:
First, install package JQuery Migrate. Second, edit the method RegisterBundles in class BundleConfig from App_Start folder and change the part where it adds the bundle jqueryval.

Initially, in my project, it looked like this:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                          "~/Scripts/jquery.validate*"
                        ));


Here you have to add a line to include the jquery-migrate files:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery-migrate*",
                        "~/Scripts/jquery.validate*"
                        ));