Thursday, 20 July 2017

Make local Git branch track a remote branch

Problem:

How do I get a local git branch to track a remote branch?

Solution:

The following examples assume a branch "thebranch" and a remote "myremote". They also assume you are using git in the command line.

For Git 1.8.0 and later:

If you've already checked out "thebranch" on your local, then:

git branch -u myremote/thebranch

If you haven't checked out "thebranch" on your local, then:

git branch -u myremote/thebranch thebranch

For Git 1.7.0 until 1.7.12.4, if you've checked out "thebranch" on your local, then:

git branch --set-upstream-to=myremote/thebranch

If you haven't checked out "thebranch" on your local, then:

git branch --set-upstream-to=myremote/thebranch thebranch

References:

Saturday, 8 July 2017

Make Google Play Music ignore a folder

Problem:

How do I make Google Play Music ignore a folder of audio files on my Android device?

I have a bunch of audio books, language lessons, and voice recordings that I do not want to play when listening to music.

Solution:

One solution is to add a new file and name it ".nomedia" into the folder you would like Google Play Music to ignore.

This file can be empty, and the period in the front front of the filename is necessary.

Notes:

This was tested to work on devices using Android 5 and Android 6.0.1. Your mileage may vary on other devices.

This trick will work with any app that uses a media scanner which ignores folders with ".nomedia". See some of the references below for other examples.

In order to create the .nomedia file, you can either use your computer or use a file manager on your Android (such as "Amaze" - turn on "show hidden files and folders" in the settings to see the results).

References:

Saturday, 24 June 2017

Show SSIDs in Windows 10 command prompt

Problem:

In Windows, what is one quick way that I can list nearby detected wifi networks, and related information about access points?

I am currently working on an app and need to see if several access points share the same SSID, and IT does not allow me to install network stumblers or similar programs.

Solution:

In the command prompt, you can use either "netsh wlan show networks" or "netsh wlan show all".

Example output of "netsh wlan show all":

More detailed instructions:

  1. Press the following key combination: [windows key] + R
  2. Type in "cmd" in the Run dialog that appears, then click OK
  3. Type in "netsh wlan show all" or "netsh wlan show networks"
  4. A list of nearby access points currently detected will appear if you have done this correctly

Friday, 3 February 2017

C# Ticks to human-readable date/time

Problem:

I'd like to get a human-readable date/time for a number of Ticks in C#.

Tool:

Try the tool below :)

Ticks:
DateTime(UTC):
DateTime(local):

(Please note that this might not work in all browsers due to limitations in number size that a browser can handle. Also, please let me know if I goofed up the calculation. Thanks!)

Notes on calculation:

  • ticks to microtime = ticks / 10000
  • microtime to Unix time = microtime - 62135596800000
  • then convert Unix time to human-readable using Javascript Date()

References:

Friday, 20 January 2017

Restore my Xamarin project's NuGet and Xamarin-Component dependencies using CLI

Problem:

How do I restore all of my Xamarin project dependencies when neither Visual Studio's "extensions and updates", nor NuGet package manager GUI have the versions my project requires?

Similarly, how do I restore these packages in the command line so Jenkins can automatically build my Xamarin project?

My questions apply to fresh clones of my team's Xamarin project from Git, where the NuGet nor Xamarin component 3rd party dependencies aren't included in the project's repository.

Before you start:

The solution below assumes that you have knowledge of Xamarin, Xamarin components, NuGet, (Jenkins), the command line, and have a valid account for Xamarin. (It was written as a quick reminder. Please refer to the referenced links if more detail is needed.)

One solution:

One solution is to use the nuget.exe and xamarin-component.exe command line tools to restore NuGet and Xamarin component dependencies.

You can get the Xamarin component CLI executable from here: https://components.xamarin.com/submit/ (you'll need to sign in with your Xamarin account, and follow the instructions Microsoft provided)

You can get the NuGet CLI executable from here: https://dist.nuget.org/index.html

When you have these CLI tools installed (or copied to your project's root - not ideal, but helps to troubleshoot), you can then use them or include them in your script as follows:

  • navigate to the directory where your solution file is (e.g. YourSolutionName.sln)
  • 
    nuget.exe restore
    xamarin-component.exe restore YourSolutionName.sln
    
    
  • (first time) enter your Xamarin account credentials (needed for xamarin-component)

At this point, the output should give an indication of all 3rd party dependencies that were successfully restored.

Notes:

This solution was tested to work on a project that has dependencies about a year old (and are no longer available via the Visual Studio GUI). The versions of the tools tested were Visual Studio 2015 (14.0.25431.01 Update 3), Xamarin 4.2.2.11 (with corresponding Xamarin.Android 7.0.2.42 and Xamarin.iOS 10.3.1.8). Additionally, all 3rd party libraries were originally installed using Visual Studio's "Extensions and Updates..." GUI and NuGet package manager's GUI. Your mileage may vary, depending on versions and how your team has setup your Xamarin project.

This solution also depends on Microsoft/Xamarin still providing the CLI tools, as well as the 3rd party dependency versions specified in your project still existing for download.

Nonetheless, hopefully this has at least come in handy or given some new ideas :)

References:

Thursday, 5 January 2017

Delay lock screen display sleep time in Windows 10

Problem:

In Windows 10, how do I prevent my displays from turning off shortly after locking my screen?

Power savings nor display life are an issue for my situation.

Reason: I have an external dock that causes all my windows to move to my primary display after the displays are turned off.

Cautions:

This how-to assumes you are comfortable with editing the registry. Serious damage can be done if you make a mistake!

Workaround:

  1. enable "Console lock display off timeout" in the Advanced Power Settings via the registry:
    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\7516b95f-f776-4464-8c53-06167f40cc99\8EC4B3A5-6868-48c2-BE75-4F3044BE88A7
    • set "Attributes (type DWORD)" to 2
    • (to hide, set Attributes back to 1)
  2. open advanced power options (or close then reopen, if it was already open before the registry change)
  3. change timeout to desired value (example screenshot below):

Notes:

  • This was tested to work in Windows 10 Pro.
  • Changing this setting is strongly discouraged in situations where power saving or monitor life are important.
  • This only works for lock screens while a user is signed in.

References:

Wednesday, 4 January 2017

Android screenshot to computer with adb

Problem:

How do I use adb to get a screenshot from an Android device or emulator?

I'd like to target a specific device when more than one are connected to adb.

I already know how to open adb shell and put a device in debugging mode.

Solution:

One method is the following:

  1. Get list of devices:
    adb devices -l
    

    You should get a list that looks like:

  2. Once you have a device identifier, such as "emulator-5554", you can use similar commands as below. (Replace "emulator-5554" with your device identifier).
    adb -s emulator-5554 shell screencap -p /sdcard/screencap.png
    adb -s emulator-5554 pull /sdcard/screencap.png
    
  3. (Optional) remove the last screencap from your device (in this example, named "emulator-5554"):
    adb -s emulator-5554 shell rm /sdcard/screencap.png
    

Other notes:

If you've only got one device accessible to adb, you can simply do the following:

adb shell screencap -p /sdcard/screencap.png
adb pull /sdcard/screencap.png
adb shell rm /sdcard/screencap.png

If you'd like to see a one-liner to do the above, check out the neat example here: http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html

References: