Enable Web Proxy On OSX Using Shell Script

Terminal icon osx 150x150

I’ve been using a VPN Tunnel to get me a US ip address so I can watch Netflix. My VPN provider, Ironsocket has a Web proxy I can configure on my browser to enable me to access Netflix and other sites that checks for ip location. Once I’m done watching Netflix I would like to disable the web proxy. It’s very easy in OSX to disable or enable the web proxy in your browser System Preference -> Network -> Advanced -> Proxies, but its easier if it will be done through a shell script. Here is how to enable web proxy on OSX using shell script.

Creating the shell script

You can use any text editor you’d like in OSX. I use vi to create mine. Here is the script:

Shell Script Content

echo "Setting proxy to" $1
networksetup -setwebproxystate Wi-Fi $1
networksetup -setsecurewebproxystate Wi-Fi $1

The important command is the networksetup. Its the system command to use if you want to do anything with your OSX network setup.

I’ve just passed in the protocol I want to configure, this case its only the Web Proxy (-setwebproxystate) and Secure Web Proxy (-setsecurewebproxystate). I also passed in the name of the network adapter I want to configure which (Wi-Fi) and the $1 is just the parameter I passed in from the command line.

Running the shell script

Running the shell script will require you to have Admin rights since this will change a system setting. To run the script as Admin use the command sudo. Here is how I run the script.

Running the script with result

The echo command in the script will be print the last command you made.

That’s it. You now can enable web proxy on OSX using shell script. Hope this helps!

Permission Denied Error On Npm Install For Yeoman

Yeoman 007

I was trying to create a simple ASP.Net 5 project by using generator like Yeoman on my Mac. The instructions on ASP.Net docs website are simple and easy to follow. However I encountered a permission denied error on npm install for Yeoman.

Npm Error Permission Denied

Initially I thought I was not running an updated npm version so I tried to execute npm upgrade, but it did not work. I also tried to install again npm getting the installing from nodejs.org but the same error occurs.

Looking closely at the log, it was a permission error on a mkdir on /usr/local/bin folder. This was verified when I go to that folder and tried to create a folder but a permission error occurs. Getting closer to the root of the problem!

Wheels

When I looked into the owner and group permissions in the folder, the group owner for node_modules (where the install is targeting the mkdir) is a group name wheel. The group name wheel seems to have been related to the roots of MAC OS X from Unix.

Wheels MacOS Permission

I issued two commands to gain permission to the folder.

sudo chgrp -R admin node_modules

sudo chown -R whoami nodel_modules

After gaining permission to the folder, I once again tried to install Yeoman using npm and the installation went through this time.

Npm yo Ok now

I hope this will save you time if ever you encounter the same problem on your way to trying more ASP.Net 5 samples.

Mirroring On MacBook Causes Page To Shrink

Here is the background

I usually stream movies on my MacBook Pro and then mirror it to my TV to make the viewing much enjoyable, obviously because of the screen size. Here is the setup, my Macbook Pro connected to my TV through a mini display port to HDMI cable. It’s a common setup when you want to connect your laptop to your TV or any display.

The problem?

The problem is when I connect my Macbook Pro to the TV, the Macbook Pro’s display will refresh and you should expect the display to be mirrored to the TV display. Yes, the mirroring happens but page turns into a display shrank into half. The shrank page is also mirrored in the TV display which does not happen to the rest of the open tabs. See below what I mean.

Page Shrank in Half

There are times I preload the movie like in Netflix or other stream sites so you can buffer the whole movie before starting to watch. Then the shrinking happens when you connect it to your TV. Not good.

It worked! Here is the trick

You can alway close and then open again the page that shrank but in case you encounter the issue you can always to do this trick to solve the issue. I tried to move the page, resize the page, minimize/maximize the page but it does not work. Then I tried to open the Developer Tools (Option + Command + I) and then close it.

Chrome Developer Tools Options Bar

It worked, the page goes back to full screen mode without opening or closing the page. Saving anything I buffered in the page. Cool.

Taking Visual Studio Code and ASP.Net 5 For A Spin

Visual Studio Code Setup

Visual Studio Code Download

https://code.visualstudio.com/Download

Visual Studio Code (VSCode) is the latest free cross platform lightweight IDE from Microsoft. Visual Studio Code and ASP.Net 5 are being released as free and open source.

Initial Impressions for Visual Studio Code

Pros:

  • Lightweight IDE
  • Support for many Languages with IntelliSense
  • Git Integration
  • Open Folder
  • Easy Split Window Navigation
  • User and Workspace settings in JSON

Cons:

  • Does not support regions for C#
  • Keeps hanging when you use on large .Net solutions (Open Folder)

ASP.Net 5 Setup

According to Microsoft, DNX was built entirely from the ground up. The ASP.Net 5 was also created from the ground up, meaning all ASP.Net 5 projects are DNX projects. Good thing to note is that ASP.Net 5 is not anymore based from System.Web.dll. Things are built around the concept of packages and on demand references.

Windows

In order to install and run ASP.Net 5 from Windows, you will need to install the DNVM (Version Manager), DNU (Utility) and DNX (Execution Engine). The steps to install them can be found from this link.

OSX

A very cool new feature of ASP.Net 5 is that it can run and be developed in other platforms. I was very excited to try and develop ASP.Net on a non-Windows machine. It gave me enough reason to buy and upgrade my MacBook Pro 2008 to MacBook Pro 2015 ;).

Just like in Windows, you will need to install the DNX, DNVM and DNU. But this time, since its on OSX, everything will be dependent on Mono (.Net Open Source Project). You can get Mono by installing through Homebrew (package manager) in OSX. Actually, it works backwards, in Homebrew when you install the latest ASP.Net and DNX it installs Mono automatically since its a required package of ASP.Net.

Linux soon!

I do not have now a Linux machine to try and install ASP.Net 5 so next time I will post my ASP.Net 5 adventures with Linux!

Sample Project ASP.NET 5

Omnisharp log – Error logged on opening the sample project

When opening the sample ASP.Net 5 DNX project with VS Code without first installing DNX, you will encounter an error logged under the Omnisharp log. This is a good way to know the sequence where it looks for the DNX framework.

Omnisharp log

The DNX framework can be installed on your system like what I did when I followed the steps to initially setup DNVM, DNU, DNX amongst others. But you can also, make available the different DNX versions in your local by getting and compiling them from the Github repository. This way, you can test different versions of DNX from your system. Running DNVM list will show you different versions installed in your machine.

Two versions of DNX

Running the sample apps

There are sample projects up in the ASP.NET repository. You can download or clone them from Github.

I tried to open and run the web application under the HelloMVC sample folder. This is a sample MVC ASP.NET 5 project which you can open in VSCODE.

Inside the project folder, you can execute

dnu restore

to make download the dependencies of the sample project. Visual Studio Code will also prompt you to do the restore.

DNU Restore VSCode Window

DNU Restore Complete

To execute and start the hosting of the project run the command

 dnx . web 

DNX WEB

Open a browser and go to http://localhost:5001/ and you will see the sample MVC ASP.NET 5 project running.

Sample ASP NET 5 Website running

You can do the same steps to setup, compile and run the web project in OSX. As long as you have DNX installed you can start and run ASP.NET 5 projects. I’m trying to follow the latest in DNX and ASP.NET as a whole in Github – http://www.github.com/aspnet and try to contribute if possible 🙂 Thanks and until my next post!