Skip to main content

Connecting Visual Studio to Github

I learned in the past, that it is always best to connect workspaces to source control, even for experiments and learning projects. Sometimes it’s because you’ve screwed something up terribly and you need to retreat to a last known good; sometimes it’s because you want to continue on a machine that’s different from the one you were working on earlier.

So, before I started learning react/redux (or anything else), I wanted to get my IDE connected up to Github, where I keep my source code. I’ve done this plenty of times on Linux and Mac (which is basically Linux), but never had to do it on Windows. Turns out it is a bit rough, but possible.

I am using Visual Studio Code (VSC) as my IDE for this kind of work for now. That comes out of the box with a git SCM extension, but the extension does not support using SSH AuthN to a remote server like Github. I prefer to use SSH because that’s what I know and use on other OSes. To get that to work with VSC, I first start a git-bash shell from Git for Windows, whose SSH environment is configured following the instructions in a gist from github user bsara. I then simply start the VSC executable from the shell using the command code so it inherits the SSH environment and can work with Github.

Apart from the small annoyance of having to start a shell to start VSC, this seems to work great and I am now happily interacting with my Github account directly from VSC.

Learning at O’Reilly

As a very long time member of the ACM, I’ve learned there are a few perks that come with it. The best, in my opinion, is the Learning Center, which provides ACM members with complimentary access to a number of useful resources, including the full content at O’Reilly Learning (formerly, Safari Books).

For the price of an ACM membership (currently $99) you can get access a resource that normally costs 5x that (currently $499).

Viral Motivation

At work, we have transitioned to everyone working from home, both to protect employee health and to comply with the coronavirus quarantine orders currently in effect in California. I work from home a day a week anyway, so this has not been nearly as big a transition for me as for many of my coworkers. I still have a work week just like always, I just get up a little later than normal because I don’t have to commute. Daily life doesn’t seem quite so different to me in the current situation (modulo finding food and paper products…)

Nevertheless, reading so many articles and posts about people taking up new hobbies or getting round to long neglected projects to fill up their now copious spare time brought me round this morning to thinking about reviving my outside-of-work programming habits and learning.

Now feels like a great time to dive into the front end web tech that’s always been my main coding blind spot.

At the same time, I realize that I need to dust off and re-energize the various modern artifacts of a programmer – namely my code repos (GitHub) and my tech blog (this site).

I’ve done a bang up job at work creating and regularly updating similar artifacts at work, so here’s hoping I can do something similar IRL.

Java Exceptions

  • Chain exceptions by passing the caught exception as the cause argument of the new exception.
  • Messages in exceptions are not chained. I have to do that myself if I want to how something went wrong.
  • toString() and toMessage() differ only in that toString() prepends the exception type to what it dumps out.
  • Most messages from Java are horribly terse, almost to the point of uselessness.
  • Use unchecked exceptions (i.e., subclassed from RuntimeException) when the caller did something wrong with the API; use checked exception (i.e., subclasses from Exception) when the call was made correctly, but something didn’t cooperate properly.
  • You have to reimplement all the constructor variations in subclasses, but can basically delegate everything to the superclass.
  • Gist to collect the transitive closure of Java exceptions into single message.

Getting a single file out of Github

Sometimes you just need to get a single file out of Github. You don’t care about the whole repo. Maybe you just need a snippet of code, or maybe just one language version, or whatever.

You can, of course, copy and paste with a UI clipboard, but that can be error prone and isn’t scriptable. You might think you could just curl <url> to the page, but you would just get the HTML for the page, rather than the file contents themselves.

Github actually can generate a number of views for your file. They follow this syntax

<site>/<owner>/<reponame>/<view>/<branch>/<pathToFile>

where the legal values for view are:

  • blob (basic HTML page)
  • raw (actual contents)
  • blame (annotated HTML page)

For example,

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

where https://github.com is the site, git is the owner, git is the repo, blob or raw is the view, master is the branch, and contrib/completion/git-completion.bash is the file

Since what you want is the actual file, rather than an HTML document with information and links to the file, select the “raw” option. Because you’re now dealing with actual content, the actual URL may redirect, so be sure to use curl’s -L option to interpret the HTTP Location header.

curl -L https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

Gaming PC Update

After a short delay, the gaming PC is a go and the parts are on their way. The delay was caused by a general shortage of Intel Skylake architecture CPUs. Everywhere seemed to be sold out, and the places that weren’t seemed to be marking the prices up as much as 50%.

I just waited a bit and, eventually, was able to find a reasonably priced, in-stock bundle of my CPU and motherboard choices at NewEgg. The rest quickly followed and now I just need to wait for the stuff getting shipped from New Jersey. While the guts were all priced cheaper and were more likely to be in stock at NewEgg, it turned out that the OS and peripherals were better to get from Amazon.

Let’s Build a Gaming PC!

Now that I work at a gaming company, I need to broaden my gaming horizons a bit more, so I’ve been looking into buying a few top titles from the RPG genre and trying them out. I wasn’t sure if I should buy them to play on a PC, or if I should buy a console. Fortunately, there are a few folks at work who know a thing or two about games, so I asked them what they would do. Most of them said get a gaming PC instead of a console, assuming I could afford the price difference.

This struck me as a great idea, not just to allow gaming, but to let me stream things like Netflix and Rhapsody, and also make better use of all my media stored on NAS. Then, while browsing gaming rigs online, I stumbled across a guide to building a mid-price gaming box and I had my epiphany. I’ve been a tech guy for many years and have owned and worked on many computers, but I have never built one despite always wanting to. With my wife’s blessing, I decided to go for it and bring the kids into the act as well. It will do them good to see what a computer is made of.

So here’s the preliminary build list:

  • CPU: Intel Core i5-6600K
  • Motherboard: ASUS Z170 Pro Gaming
  • Graphics: MSI GTX 970 4G
  • Memory: 8GB DDR4 2400
  • SSD: Samsung 850 Evo 25GB
  • Hard disk: repurposed Seagate
  • Optical drive: repurposed Samsung
  • Case: Fractal Design R5 Black Window
  • Cooler: Cooler Master Hyper 212 Evo
  • Power supply: Corsair CX600M 600W 80 Plus Bronze
  • Keyboard: Corsair K70 Cherry MX Red
  • Mouse: Razer Deathadder
  • OS: Windows 10 Pro

Now, I’m off to Amazon, Newegg, and Frys to buy my gear so it gets here in time for my company’s winter shutdown. Wish me luck!

Video Driver Mess

Ever since I upgraded to version 22, I’ve been encountering infrequent and mysterious video and mouse lockups on my Fedora box. Things will be running just fine and then – blam – everything just freezes and the only way to reset is by leaning on the power button for a hard reboot. Sound keeps working, but the everything else becomes unresponsive.

My first instinct, which lasted for about 3 weeks, was to ignore the problem and just live with the resets. Problems like GUI hangs are rarely simple things, there’s usually some version mismatch in a driver or some strange hardware incompatibility, and they often seem to require some deep machine fu to debug and understand. It seemed the only thing I could do was to try to describe and post the problem somewhere and maybe get lucky that someone responds. In my experience, helpful responses are rare, so I kept procrastinating.

But then I thought, even if nothing comes of it, maybe someone would see it and maybe it might end up helping someone. Unlikely, for sure, but possible. And then I reflected that part of being in an open source community is trying to identify and help resolve problems as best you can. How many times have you found questions and answers on forums or StackExchange that helped you figure something out? What if those people had all just figured help was unlikely, shrugged their shoulders, and lived with their difficulties?

So, I took a deep breath and headed on over to the Fedora Project forum to see what I could find out. The deep breath was needed because the first time venturing into a forum is usually a bit overwhelming. There are usually a bunch of sticky threads that you are expected to read through to understand the forum structure, the searching expressions, and the posting rules. Every forum seems to be a bit different and there is little to do about it except just get stuck in and spend the time needed.

Then comes the overwhelming scale of many forums. There are hundreds and thousands of threads, many of them years old, and many of them kind of similar but not the same as your issue. The thing you have to do is start to look for keywords and patterns in both the titles and posts of possibly related threads until you begin to get a feel for the right way to describe and frame your particular problem. Then, you go back and search again, this time looking for more focused results and adding in time filters to keep it to reasonably recent threads. I like a sieve of about 3 months, which is recent enough to weed out solutions to previous software versions but is still recent enough to cast a reasonable wide net.

So, while I originally went in looking for “gui hang”, after some time I realized that “freeze” was much more prevalent and that a large percentage of freeze-related threads were also about “nvidia” driver problems. A quick check of my PCI devices revealed that I did, indeed, have an nVidia video card in my box.

> lspci -k
...snip...
01:00.0 VGA compatible controller: NVIDIA Corporation NV41 [GeForce 6800] (rev a2)
Subsystem: NVIDIA Corporation Device 0245
Kernel driver in use: nouveau
Kernel modules: nouveau
...snip...

I could see the nVidia card and also that I was using the default Fedora nouveau driver. Many of the threads mentioned that there were, apparently, aspects of nVidia cards that are not accounted for by the nouveau driver, so the recommendation is to use a driver supplied directly by nVidia.

I went to the nVidia site and entered the information for my video card, and was able to figure out that I needed a driver from the 304 series of drivers. You can try to install drivers yourself, but it turns out that they are already packaged properly for dnf install on the nonfree side of the RPMFusion repository (including installation instructions).

> dnf -y update
> dnf install akmod-nvidia-304xx xorg-x11-drv-nvidia-304xx
> reboot

When I tried to reboot, however, the graphics would no longer start up correctly. It turns out there is one more step required to get the akmod you just installed to be rebuilt correctly. Since the graphics are now busted, you need to ssh into the machine and force the rebuild.

> akmods --force
> reboot

At this point, my graphics came up correctly, although the boot process for the GNOME shell seems glitchy, often crashing the shell. Fortunately, if I just wait a moment, eventually everything refreshes and the shell restarts and everything seems to run properly thereafter. I have not had any more screen freezes since I installed the driver, but only time will tell if the issue is properly fixed.

I am also a bit concerned that when I next run a dnf update that I will have to go through some or all of the process again to make the drivers work properly with any newer kernel, but that is material for a future post.