TIP: Obliterate a file from GIT Repository (including history)

I did something stupid, and accidentally pushed some .pubxml files to a public GitHub repo that contained passwords.

I fixed up my .gitignore file, which took care of part of it, but if you viewed the history, the password were still exposed.

After much mucking about, this magical line, obliterated any trace of the file in my repo.

git filter-branch --index-filter "git rm --cached --ignore-unmatch *.pubxml" --prune-empty --tag-name-filter cat -- --all

Then this line, forced an update of the entire repo to GitHub, history and all.

git push origin --force --all

…that was a close call.

TIP: Partial screenshots made easy

I have to take partial screenshots when creating emails or documentation almost every day. I’m not a fan of installing extra tools unless they’re simple, and truly save me time. A few seconds isn’t enough. This is one of those cases, typically I’ll just take the screenshot with PrintScreen, or Alt-PrintScreen, paste it into mspaint, select and copy the part I need, and move on.

However, windows already has a tool for taking partial snapshots of the screen, it’s called “Snipping Tool“. It works for most cases, and that’s enough for me.

We just need a quick way to open it. So, hit the windows key to open the start menu and type Snipping Tool, right click on it, and select properties. Focus in Shortcut key, and hit a key combination to open it. Mac has a similar tool already bound to Cmd-Shift-4, so I bound the snippet tool to Ctrl-Shift-4.

SnippingTool

Now, I just hit Ctrl-Shift-4, and the screen goes partially opaque. I highlight a section of the screen, and it’s automatically put in my clipboard. It’s also opened in the snipping tool, but I just close it without saving changes (Alt-F4). Then paste the partial screenshot in my email or document.

Simple.

Getting started with Hybrid development with Ionic – Part 1: System Setup

So, let’s just dive in and get the dev machine setup. We are going to be using Apache Cordova, Ionic, and AngularJS frameworks. And we’ll get Jasmine and Karma setup for testing. We will also use npm (node package manager) to install these libraries, so let’s get that installed first.

Install nodejs using the install link at nodejs.org. Then let’s ensure we have the latest version by running this as administrator.

npm install npm -g

We also need the Java JDK (not just JRE). That can be downloaded and installed from here. Just follow the instructions, and ensure it’s in your PATH when complete.

Now let’s get Apache ANT from here, and install it.

Also required is the Android SDK. Just follow the instructions, and run the Android SDK Manager to install the latest SDK Platform. Cordova requires the ANDROID_HOME environment variable. This should point to the android-sdk directory.

Now that we have npm, let’s install cordova and ionic as administrator.

npm install -g cordova
npm install -g ionic

Now, navigate to the location you want to create your application. And generate a blank ionic app with

cd c:\source\
ionic start helloworld blank

NOTE: I had a problem here, I received the following error: “Unable to add plugins. Perhaps your version of Cordova is too old. Try updating (npm install -g cordova), removing this project folder, and trying again. (CLI v1.3.2)”. However, nothing I did solved the problem. Turns out, for some reason, my helloworld/config.xml was blank. You can fetch a new config.xml here, replace the empty one, and things should start working.

Open the helloworld folder and let’s add the android platform, and run the blank app

cd helloworld 
ionic platform add android
ionic serve

ionic_serve

Or connect your android device by usb, and load the application on it with

ionic run android

You can also run it in the Android emulator, but I don’t recommend it, as it’s slooooooow.

ionic build android
ionic emulate android

Next we’ll start adding some code and tests.

Completely remove Printer Driver

I recently had to keep retesting an installer, part of it’s actions were to install a print driver, but to be able to keep testing, I had to remove the driver from the computer, not just the printer. So, here’s how it’s done, in case someone else needs to do this.

  1. Find your driver name. (ex.“Brother MFC-J6520DW Printer”)
  2. In “Devices and Printers” remove all printers using the driver from step 1
  3. Open Regedit.
  4. Navigate to (on 32 bit(x86) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3”
  5. Or (on 64 bit(x64) computers) “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3”
  6. And then remove the folder that matches the printer driver name.
  7. Open Services, and restart the print spooler service

That’s it.

TIP: Always run Visual Studio as an Administrator

If you’re like me, you always want Visual Studio opening as Administrator, allowing it to install services, and do whatever you need it to do. But you often forget to right click and “Run as Administrator”. Or you just want to be able to use the pinned shortcuts on the task bar. It’s really amazingly simple to make it always run as an administrator, just follow these simple steps:

  1. Right Click on “devenv.exe” in Explorer
  2. ClickTroubleshoot compatibility
  3. ClickTroubleshoot program
  4. CheckThe program requires additional permissions
  5. ClickNext
  6. ClickTest the program…“. It should launch Visual Studio as Administrator
  7. ClickNext
  8. ClickYes, save these settings for this program
  9. ClickClose the troubleshooter

You can revert by following the same steps, but unchecking “The program requires additional permissions”

Yet another “Books you should read” list

These lists are everywhere, every blogger at some point puts up there list of “must read” because … because they’re important. Some of the best books I’ve read have been off people’s lists. When you look at a few dozen lists, you notice the same books over and over and over…and you realize, “I should read this book!”. If all these people I respect and follow are recommending it, it must be worth reading. So here’s my list, with commentary, hopefully containing some suggestions that you haven’t already read, and enjoy when you do.

  1. Pragmatic Thinking and Learning: Refactor Your Wetware

    Pragmatic Thinking and Learning: Refactor Your Wetware

    This book literally changed the way I think about my day. Lots of examples about how your mind works, tricks to help you let your mind solve problems for you in the background, and why. It generated a lot of interesting discussion at during our companies book club meeting.

  2. The Phoenix Project: A Novel About IT, DevOps, and Helping Your Business Win
  3. The Phoenix Project: A Novel about IT, DevOps, and Helping Your Business Win

    This is probably my favourite book on the list, it describes a fictional company that has horrible internal practices, and one employees attempt to change that. It feels so real, and I can relate so much of the story to places I have worked. It offered some insights into how we can affect change for the better in the companies we work for.

  4. Clean Code: A Handbook of Agile Software Craftsmanship

    Clean Code: A Handbook of Agile Software Craftsmanship

    A great book that changed how I write software. It really brought refactoring, and proper program structure to the front of my mind. Before reading this book, I didn’t realize how bad a programmer I really was. I got things done…but not as well as I could have.

  5. The Clean Coder: A Code of Conduct for Professional Programmers

    The Clean Coder: A Code of Conduct for Professional Programmers

    Along the same lines as Clean Code, but this book isn’t about writing code, it’s about how to be a professional in the workplace. How and when to say no. How to estimate, and when not to. It confirmed many of my practices, and caused me to understand better some of the mistakes I’ve made in the past.

  6. Dreaming in Code: Two Dozen Programmers, Three Years, 4,732 Bugs, and One Quest for Transcendent Software

    Dreaming in Code: Two Dozen Programmers, Three Years, 4,732 Bugs, and One Quest for Transcendent Software

    This was another great story, the author’s original intent, was to follow this company as they created a piece of softare and document how great people can write revolutionary software…however, that’s not quite what happened.

  7. Leaders eat Last: Why Some Teams Pull Together and Others Don’t

    Leaders Eat Last: Why Some Teams Pull Together and Others Don't

    This book isn’t about tech at all, it’s about what makes a good leader, and why. It goes into a lot of detail about the chemicals in your brain, when they are released, their short and long term effects, and why we’ve evolved to have them. It generated a LOT of fantastic converstaion in our book club meetings.

  8. The Drunkard’s Walk: How Randomness Rules Our Lives

    The Drunkard's Walk: How Randomness Rules Our Lives

    If you’re interested in math, and statistics, you’ll enjoy this book. Great stories and examples helping to understand how randomness works. And some history about statistics, and how we generally misinterpret so much of what we see because we don’t understand how to properly calculate the probability of something happening. The math is also, very easy to follow, it’s not big complicated formulas.

Now for a couple books that have nothing to do with IT, they are just so great that you should read them. They should appeal to the same crowd as the above books, as everyone I know who has read them, has LOVED them.

  • The Martian: A Novel

    The Martian: A Novel

    I read this book in the span of 24 hours, I started one evening, was done the next. It’s gripping. The first lines of the book are “I’m pretty much fucked. That’s my considered opinion. Fucked.” It’s written as a journal, as a person keeps a log about being stranded on Mars. It’s about the struggle to stay alive after being left for dead when a sandstorm forces the rest of the crew to evacuate.

  • Ready Player One: A Novel

    Ready Player One: A Novel

    If you grew up in the 80’s this is a must read. It’s page after page of 80’s movie, video game, and television references. Every paragraph takes you back to your childhood (or whenever you were alive in the 80s). And it’s all wrapped in a great story set in the real world in 2044 after a global energy crisis; and in a virtual world, the OASIS. Once I picked up this book, I could barely put it down, I think I’ve only read The Martian faster.

I hope you read or have read these books and enjoy them as much as I have. Let me know in the comments, if you have recommendations for further reading, I’d love to hear them! There’s so much out there it’s hard to find quality.

Have a great day!

It’s a great day to be a .Net developer

What more is there to say?  Microsoft opensourced Roslyn (.NET Compiler Platform), source is avaiable on CodePlex!!!

It’s fantastic news, to quote Eric Lippert

What astonished me was that its not just a “reference” license, but a full on liberal Apache 2.0 license. And then to have Miguel announce that Xamarin had already got Roslyn working on linux was gobsmacking.

It’s a huge step, and something I hope Microsoft does more of.  I can’t wait to find some time to dig into this code, and see how it all works.

Getting Started with Android Development

Last fall I purchased a Nexus 7 (2013) and have really enjoyed the pure Android experience.  I’ll be retiring my S3 and buying a Nexus phone to replace it in the near future.  Anyhow, one thing that’s always lacking is a way to develop on the tablet…or so I thought!  Enter AIDE, an Android IDE that allows you to develop and run applications right from your tablet!

aide-devices

It comes with the code for  Tetris, a Clock Widget, and a Hello World app.  I started hacking together my first native app.  And tried to run it.  Of course, it crashed. So, Google, and I download a few logcat readers.  None seem to work. I do some more research and learn that as of the Jelly Bean update, apps can no longer read each others logs. This was added for security reasons, as some applications (facebook) were logging passwords in the log file, meaning, a maliscous app could easily read your facebook password from it’s logfile. Which now means, you need to connect your tablet to a pc to read the logs, and determine why your application is crashing.  At first, this annoyed me.  It took a while to get that work, and I’ll show you how. But if you plan to deploy your app, you’re going to want to have log files sent to you anyway. After showing you how to read logcat from your PC, I’ll show you how to write your first app in AIDE, that will email (or change it to write to a file you can open) it’s logcat after it crashes. It will allow you to develop, without the need for a PC.

First, you need to enable developer mode on your tablet. It used to just be in the settings, but now it’s more complicated.  Open your settings and scroll down to “About tablet” (phone, or whatever).  Scroll down to the Build number, and click it 7 times.

about tablet

You’ll see a message that developer mode is now enabled. Success. Back in the Settings screen you’ll now see Developer Options.

dev options

In there, turn on USB Debugging

USB Debugging

Next we need to install drivers, you can get the latest Google USB Driver from http://developer.android.com/sdk/win-usb.html. Unzip them to a location your machine, I chose c:\Android Tools\Usb_Driver. Now, open Device Manager, and find your device under “Other devices”

Update Nexus 7 Driver

Choose “Browse my computer…” and navigate to the folder you extracted the drivers into. Make sure “Include Subfolders” is checked. And install them, you should now see the device installed correctly.

Nexus-7-Driver-Installation-Completed

So, now that the drivers are installed, let’s get adb installed, you can download r19.0.1 for windows here which is currently the latest version. Just extract the files onto your computer, I stored them at “C:\Android Tools\platform-tools” on mine.

Open a command prompt, go to the directory you just extracted adb.exe into, and try issuing the command “adb devices“, you should see a result listing the attached device.

C:\Android Tools\platform-tools>adb devices
List of devices attached
06e96062 device

If nothing is attached, you many need to change the Connection type with your computer, on your Android device, go to Settings -> Storage, and click the elipses in the top right, you’ll come to this screen, try changing between the two modes, one should work. On mine it was Camera, others have reported differently.

USB Computer Connection

If all is working correctly, you should be able to dump the logcat contents with the command

adb logcat

Or to a file

adb logcat -d > logcat.txt

This logcat grows quickly, if you want to clear the logcat of your device, issue the command

adb logcat -c

And that’s all for now. My next article should be a walkthrough of using AIDE to get a simple app up and running, with logging, so you can do do your development without needing adb to view logs, and thus, remove the tether to your computer.

Now, back to coding!

TIL: How to use adb to take a screenshot from Android

I was writing up another article and needed screen grabs from my device, and wanted a simple way to grab them, well, adb to the rescue!


adb shell /system/bin/screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png screenshot.png

It’s that easy.

The first line saves the screenshot on the device, the second pulls a file from the device to the local machine.

All of this assumes you have adb working and the drivers setup for your device. Which I will be showing how to do in a future post.