Profile Picture

Sirwan Afifi

Stories from a web developer.

© 2017. Sirwan Afifi All rights reserved.

Running PowerShell on macOS

It’s been a while I have been using macOS as my primary operating system, you can read about my expreince here.

Today I wanted to run a PowerShell script, I searched around and figured out Microsoft has made PowerShell open source open source and the good news is that PowerShell is now cross-platform! this means that you can also run PowerShell scripts on Linux, macOS.

Actually to get PowerShell to work all you need to do is installing it using Homebrew:

brew cask install powershell

Before preceding, make sure you have already installed Homebrew-Cask on your machine.

Homebrew-Cask extends Homebrew and brings its elegance, simplicity, and speed to macOS applications and large binaries alike. It only takes 1 line in your shell to reach 3759 Casks maintained by 4856 contributors.

That’s it, now PowerShell is installed, so you can use it in your terminal:

There’s also a great VSCode extension to write, debug PowerShell scripts:

SQL Server on Linux in Docker on a Mac

Over the last few months, I have been working on a couple of ASP.NET Core projects, it’s been great experience so far becuase I can easily work on different platforms while working on these projects. I recently bought a MacBook Pro and have decided to do .NET projects on macOS since then.

Fortunately working with projects is not a pain in the neck anymore, with help of Docker you can easily setup up a complex development environment in minutes. It actually simplifies the process of building and shipping, running your apps on differente environments.

The first challenge I faced when using macOS was connecting to and using SQL Server. Thanks to Docker and SQL Server for Linux. It’s an instance of SQL Server as a docker container and it’s super-fast so that it runs in seconds.


Installing Docker for Mac

In order to get Docker to work you will need to install Docker for Mac, you can follow these steps to install it. Once Docker installation is done, it will automatically be started:

You can also run docker --version to verify that Docker is working as expected.


Pulling and running Docker image

Next, you can install and run SQL Server on Linux docker image using following command:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passowrd’ -p 1433:1433 -d microsoft/mssql-server-linux

This command will install and run the SQL Server image. Now SQL Server is running locally in Docker container:

You can use its connection string in your ASP.NET Core application:

public class MvcMovieContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(@"Data Source=localhost;Initial Catalog=MovieDB;User ID=sa;Password=StrongPassword");
    }

    public DbSet<Movie> Movies { get; set; }
}

Now if we run migration, the MovieDB database will be created in the running docker container:

dotnet ef database update

Connecting and quering the databse

There are several ways to connect and query a database running in Docker container, one way is using a command line tool called sqlcmd:

Personally I use mssql extension for Visual Studio Code. becuase it’s really easy to use so you don’t have to write your queries in command line mode. If you have not already installed this extension, all you need to do is press ⌘ + P and type ext install mssql then press enter to install it.

In order to connect and query your database first, you need to write your SQL queries into a SQL file in VS Code then press ⌘ + Shift + P then choose Create Connection Profile, follow the prompts to specify the connection properties for the new connection profile. At the end you should have following settings:

{
    "mssql.connections": [
        {
            "authenticationType": "SqlLogin",
            "server": "localhost",
            "database": "MovieDB",
            "user": "SA",
            "password": "",
            "savePassword": true,
            "profileName": "MovieDB"
        }
    ],
}

As you can see mssql.connections takes an array, it means that you can define as many connection profiles as you want. Once you defined your profile, you can use it to execute your queries then the result will be shown as a seperate window:

As you can see working with SQL Server on macOS is really straightforward. Something like this was not possible in .NET before but nowadays you can develope .NET applications on OS of your choice. that’s why I’m more excited about .NET more than ever.

Working remotely

It has been 8 months and so that I have been working remotely for a startup out there. It’s been my pleasure to work with a team of great and talented members. over the past few months, I have learned a lot both in terms of technical stuff and working as a team member.

For some, this might not seem a big deal. But for me, it’s a pretty big one. So I thought it would be great to share my experiences so far.

New technology, new tools

For this project we are using .NET core and ASP.NET MVC core on top of it. The main benefit of using cutting edge technologies is that you always keep yourself updated, but you might argue that working with new and shiny things is overwhelming because the product is not mature enough to work with. But I believe that’s also another great benefit because when you encounter a bug you easily open a GitHub issue and report it. So I think it’s best of both worlds.

Estimation

At first, I couldn’t deal with an accurate estimation, after a while I figured out that the problem was the task itself, not me, if a task is a big one then estimation most likely will be accurate, so the solution of having an accurate estimation is to break the task into smaller ones.

Documentation

A key point to have a good documentation is that, it needs to be updated after the requirement is changed. In our case, there are too many changes in requirements, this makes new team members confused. In my opinion, there must be a section called changelog in the documentation so that it will be really easy to know what was the previous changes at first place. you might say it’s better to use git log but I think sometimes you don’t need to go through several file changes in git history in order to understand a small change. Another good thing for new members is having mockups. I have been always a big fan of this type development, because as you know a picture worth a thousand words.

Working in different time zones

From my point of view working in different time zones makes remote working a little bit difficult, suppose you are given a task, now you have some questions and no one is online, so in this case, you have to leave your messages on Slack or Jira in order to get your questions answered. this is really big deal for small teams.

Collaboration

Another key point in agile development is collaboration. Working in a team is not just about delivering your product as soon as possible in some sprints. the best part of an agile team is having daily/weekly standup with other members. By other members I mean Mobile developers, Backend developers, Database developers, … I think the standup shouldn’t be held separately. As a web developer, I need to know what’s going on in other parts of the application, because I think it gives developers a really good big picture.

Conclusion

All in all, it has been a great journey for me so far. because working remotely not only improves your technical ability but gives you a cultural perspective.