Monday, February 12, 2018

Kruskal's MST Algorithm in Python

I needed this to create an algorithm that calculates base cycles in a graph. The code requires the disjoint set class from a previous post.

def kruskal_mst(vertices, edges):
  """Kruskal's algorithm that returns edge list of minimum spanning tree.

  For details see:
  http://en.wikipedia.org/wiki/Kruskal's_algorithm

  vertices - a list of the vertex names
  edges - a list of paired tuples representing edges e.g., ('v1', 'v2')

  """
  span = []
  spanAdd = span.append
  data = DisjointDataStruct(vertices)
  for v1, v2 in edges:
    if data.find(v1) != data.find(v2):
      spanAdd((v1, v2))
      data.union(v1, v2)
  return span


Note: This is not a weighted graph implementation. To make it such, have the edges come in with weights as the first value in a tuple triplet. Call edges.sort() after data assignment and make the for statement read:

for w, v1, v2 in edges:
  ...

Tuesday, November 14, 2017

Tensorflow ImportError When Using Screen

When trying to use Tensorflow in a remote setting using screen, I ran into the following error:

ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory

I forget where I found the fix, but the issue had to do with how screen preserves the environment variables of the system (It doesn't). Here's the fix:

screen env LD_LIBRARY_PATH=$LD_LIBRARY_PATH bash

This opens a new screen instance running bash with the appropriate shared libraries.

Wednesday, April 26, 2017

Tweaking Keyboard from the Command Line

I love swapping my CAPS and CTRL keys, and I never found the tweak tool solution to be very elegant. I found this quick solution, which didn't require me to install anything. I've included it below for reference. Great fix!

Open the following for editing:
sudo nano /etc/default/keyboard

And edit
XKBOPTIONS="ctrl:swapcaps"

Then, reconfigure:
sudo dpkg-reconfigure keyboard-configuration

And just go through the prompts as they are.

For more options you can change, check here.

Monday, April 3, 2017

General Installation Failure Fix AMD GPU R9 3XX

Symptoms:
R9 390 drivers would not install via auto-detect software. Failed at 99% with SUCCESS everywhere except at the "Final" step (in log). 

OS:
Windows 8.1

Solution:
1. In Device Manager, disable (not uninstall) Display adapters > Microsoft Display Adapter
2. In Device Manager, disable (not uninstall) Monitors > Generic PnP Monitor
3. Make sure all partial installations of AMD drivers are uninstalled
4. During installation, keep device manager open and disable any drivers that revert to a normal state (i.e., no longer disabled)

Monday, April 25, 2016

Netflix Not Working on Chromium with Chrome OS

I ran into the following error while trying to get Netflix running on the Chrome OS with the Chromium browser. The error was some variant of: C7121-1331-P5 (I also got C7121-1331-P7). Netflix was unable to solve the problem. After checking it out, I found that it had to do with widevine and I then found this rather elegant solution from Neverware (which was the underlying software that I was running). Hopefully this will streamline the process for someone else!

Wednesday, March 16, 2016

Effectively Destroying the Gnome Screen Lock/Shield

I ran into an annoying problem with Gnome and GDM... the notorious screen lock/shield. Anyway, I seem to have fixed it with the following commands. Note that my goal was to get rid of the lock and many of the other techniques did not work.

gsettings set org.gnome.desktop.session idle-delay 4000000000

This effectively delays the screen lock for 126 years! Perfect.

Gentoo Commands

Below is a list of commands that I found I was often using during setup of the Gentoo Linux distro with brief descriptions of what they do. I will not always explain all the flags nor will the commands be in their most generic form. However, I will link to the full help files where appropriate. This list is largely for me, but I thought that the community might also find it helpful.

The backslash is used to indicate a multiline command as per Linux syntax.

Basic but useful for editing text without linewraps:
nano -w <file>

Obvious ping syntax for 3 calls.
ping -c 3 <website>

Checking out networks and taking them up/down
ifconfig <wifi name> [up/down]

Remove a package (lots of other emerge hints here).
emerge -aC <package>

Check status of package: R is it exists. U is update. N means new.
emerge -p <package>

Update system with new USE flags:
emerge --update --deep --newuse @world

Remove obsolete dependencies (good to check with -p flag first):
emerge --depclean

Reverse check dependencies:
revdep-rebuild

This is also good (and more powerful) for package status as described here.
equery --quiet l <package>

List of USE flags for package.
equery uses <package>

Start up wpa_supplicant in the background based on .conf file
wpa_supplicant -B -i<wifi name> \
-c/etc/wpa_supplicant/wpa_supplicant.conf

Basic .conf file should read:
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="<SSID>"
    psk="<passkey>"
}

But make sure that dhcpcd is up:
dhcpcd

Alternative wifi setup with dhclient and NetworkManager (nmcli website):
systemctl start NetworkManager
nmcli dev wifi connect <ssid> password <password>

A set of <type> actions (first is enable at boot):
systemctl enable <service>
systemctl stop <service>
systemctl start <service>
systemctl restart <service>
systemctl reload <service>
systemctl status <service>
systemctl disable <service>
systemctl is-active <service>
systemctl list-units --type service --all

Where the main types I'm interested in are devices, mounts, paths, and services. The rest are listed here.

Quick kernel update of the available sources.
genkernel --no-clean --menuconfig all

Useful folders and files:

USE, VIDEO_CARDS, DEVICE_INPUTS, etc.
/etc/portage/make.conf

Name of computer.
/etc/hostname

Grub file for boot parameters
/etc/default/grub