Quick Edits Using VS Code

I’ve been working in Visual Studio pretty heavily in the last two weeks, but every once in a while I need to make quick edits to my .gitignore file, which isn’t in my project directory.

I usually open up a small text editor right from PowerShell and now that VS Code is out I thought ‘why not use that?’

Here’s how you can easily open files using code from PowerShell in three steps:

1.Find the path to VS Code
2. Edit your PowerShell profile
3. Open Files!

1. Find the VS Code Path

First thing we need to do is find where VS Code is in our directory.

If you have Code pinned to your start menu or on your desktop simply right click the icon and ‘select open file location’.

File explorer should now open to the location of the .exe.
Right click the Code.exe file and select ‘properties’.

If you selected a Shortcut Icon you should see a screen like this:

vscodeshortcutpath

If you navigated to the actual location in directory of VS Code it should look like this:

vscodelocationpath

Now right click and copy the path.

In my case: C:\Users\tireilly\AppData\Local\Code\app-0.1.0

2. Edit our PowerShell profile

To edit our profile we need to find the Microsoft.PowerShell_profile.ps1 file.

My file is located here:

profilelocationpowershell

I open the file in notepad to make my edits:

notepadpowershellprofile

Now that we have our profile open we’ll create an alias for labeled code followed by the path to our .exe
eg: Set-Alias code ‘C:\Users\user\AppData\Local\Code\app-0.1.0\Code.exe

noticed how I added the Code.exe to the path so the program will launch!

Here’s a photo of my current PowerShell profile for reference:

powershellprofile

Now we can save and close this file and open a new PowerShell window!

3. Edit some files!

Let’s edit our PowerShell profile with Code this time!

symmetryisgood

Something oddly satisfying about getting exactly what you want with words.

codeeditorpowershellprofile

And there we go. The brand new Code editor at your fingertips whenever you need it!

Let me know if you have any comment or questions!

Amazing Dude
Professor Chang Yun is an excellent man with an amazing imagine cup record. His mentorship has led teams to US finals for 8 years straight. With 6 teams making it into the World Finals.

Getting Django Models into SQLite3 DB with VS

I ran into some troubles migrating/configuring my tables for a new app in my Django project.

I’ve been following this excellent tutorial, and ran into a bump I thought needed some clarification/update. As I’m not sure if the guide is up to date with the current version of Django.

Things I searched:
no module named models
manage.py sqlall
django not creating db
models are not being created in sqlite3 Django
sqlite3 not creating table django
No migrations to apply
django sqlite3 unable to create tables
manage.py shell
sqlite3 python package

Do these correlate with what you’re having issues with?
If so this was my solution.

First Install SQLite3 and add it too your Environment Variables -> Path
Install Page — Select: Source Code -> Zip for windows machines
I extracted it to C:/.
Now I have SQLite.exe in my root directory.
This is what the end of my Path looks like:
C:\Program Files\Microsoft\Web Platform Installer\;C:\SQLITE3.EXE\;

Sweet, now we can use SQLite in Powershell.

Configuration of Visual Studio:
Create a new app by right clicking on your Project file.
Then “Add” -> Select “Django App”
In this case my app is named book.

DjangoApp Solution Explorer

Sweet, now we have another Python app.
Go into your settings file and add it to the INSTALLED_APPS tuple.
eg. ‘book’,

Okay, now we’re configured make sure you’re SQLiteDB is properly configured as well.

eg:
‘ENGINE’: ‘django.db.backends.sqlite3’,
‘NAME’: path.join(PROJECT_ROOT, ‘db.sqlite3’),
‘USER’: ”,
‘PASSWORD’: ”,
‘HOST’: ”,
‘PORT’: ”,

Sweet, db all locked and loaded.

Next we’ll create a model.
Following along with the tutorial.
We go into: book -> models.py and create our models.
Eg:
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

Sweet. Model made. Let’s get it into our SQLite DB.

Alright now in DjangoProject1Hack (Where ‘ls’ will show db.sqlite3 among others)
We’ll be doing the migration.

1. Validate:
Run- C:\Python27\python.exe manage.py validate
2. makemigrations
Run- C:\Python27\python.exe manage.py makemigrations
Output:
Migrations for ‘book’:
0001_initial.py:
– Create model Author
– Create model Book
– Create model Publisher
– Add field publisher to book
3. Sync (This just makes sure we add what’s missing)
Run- C:\Python27\python.exe manage.py syncdb
Output:
Operations to perform:
Apply all migrations: book
Running migrations:
Applying book.0001_initial… OK

Sweeeeeeet!

Okay now we manage the db:
Run- C:\Python27\python.exe manage.py shell

Sample workflow in Shell:

>>> from book.models import Publisher
>>> p1 = Publisher(name=’Apress’, address=’2855 Telegraph ave’, city=’berkely’, state_province=’CA’, country=’USA’, website=
‘http://www.apress.com/’)
>>> p1.save()
>>> p2 = Publisher(name=”o’reilly”, address=’10 Fawcett St.’, city=’Cambridge’, state_province=’MA’, country=’USA’, website=
‘http://www.oreilly.com/’)
>>> p2.save()
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
Publisher: Publisher object, Publisher: Publisher object

Yeehaa, let me know if you have any other questions!

What is it?
If you can guess what pun this represents, I’ll venmo you a dollar.

Python and Visual Studio in 5 minutes

Python is an excellent teaching programming language. It has all the tools to inspire students out of the box with plenty to grow on.

Development requires a basic understanding of computer science  but will teach essentials for large scale software development, object oriented design, polymorphism, and development environments.

I like python. The Zen is magnificent. It inspires me every time I practice and learn.

Microsoft arrives in the form of PTVS (Python Tools for Visual Studio) a powerful extension for Visual Studio that can be installed in all Versions of VS.

PTVS turns Visual Studio into a Python Dev Environment. Complete with Debugging, in window REPL (with autocomplete assistance), IntelliSense, configurable environments and virtual environments.

Its an extremely powerful tool.
While getting into PTVS I would recommend watching these two videos:


The second one especially will help you get a grip on how to configure development environments in Python, one of the most crucial parts of taking development to the next level.

Also, configuration of PIP, Setuptools, and virtualenv is all handled for you from there. Its freakin sweet. You can do all of this for free with Visual Studio Express.

Other helpful resources:
Python the Hard Way
Scott Hanselman’s Blog about PTVS
Pluralsight Subscribers
Python Tools for Visual Studio
Somasegar’s Post!

Let me know if you have any other questions!

9 Frisbees on Thumbtacks
We’ve started a Frisbee wall! FUNctional storage.