Blog

Will Faught

September 2013

Friction

Ben Thompson: With the loss of friction, there is necessarily the loss of everything built on friction, including value, privacy, and livelihoods. And that’s only three examples! The Internet is pulling out the foundations of nearly every institution and social more that our society is built upon. His blog is really good.

computing

Will Faught

1 minute

VirtualBox

I’m glad to see a viable open source virtual machine.

computing

Will Faught

1 minute

August 2013

Use Mprotect To Change Memory Page Permissions

I never knew this is how it’s done.

computing

Will Faught

1 minute

July 2013

I Couldn’t Help Myself

I also bought these games from the Steam Summer Sale: Terraria Garry’s Mod FarCry 2 Supreme Commander 2 Alan Wake I was tempted to buy StarForge too, which looks really cool, but I’m going to wait until it comes together more.

playing

Will Faught

1 minute

Primary, Secondary, And Tertiary Directories

Linux distributions should stop separating things into the three directory hierarchies at /, /usr, and /usr/local. Just put all the binaries in /bin, all the libraries in /lib, etc. Why can’t that work? There’s no need to have files on separate partitions nowadays; it’s not like it’s running on a toaster. Probably.

computing

Will Faught

1 minute

OpenSUSE Boot And Shutdown Scripts

If you want to run scripts on OpenSUSE when booting or shutting down, use /etc/init.d/boot.local and /etc/init.d/halt.local.

computing

Will Faught

1 minute

Steam Summer Sale

I just bought 17 games from the Steam Summer Sale: Supreme Commander 2 Alan Wake Empire: Total War Star Wars: KOTOR Arma II: Combined Operations Total War: Shogun 2 Left 4 Dead 2 Sins Trinity Castle Crashers Fallout New Vegas Ultimate Kerbal Space Program FTL: Faster Than Light The Walking Dead Sins of a Solar Empire Rebellion Hitman Absolution FEZ System Shock 2 The savings are addictive. I have enough games to last me a couple years!

playing

Will Faught

1 minute

June 2013

Erdogan On Twitter

Turkey Prime Minister Recep Tayyip Erdogan: There is now a menace which is called Twitter. The best examples of lies can be found there. To me, social media is the worst menace to society.

politics

Will Faught

1 minute

May 2013

The Xbox One: Hardware Analysis & Comparison To PlayStation 4

An excellent Xbox One hardware and software analysis by Anand Lal Shimpi: We’re still talking about over 5x the peak theoretical shader performance of the Xbox 360, likely even more given increases in efficiency thanks to AMD’s scalar GCN architecture (MS quotes up to 8x better GPU performance) - but there’s no escaping the fact that Microsoft has given the Xbox One less GPU hardware than Sony gave the PlayStation 4.

playing technology

Will Faught

2 minutes

Signatures For Built-In Python Methods

Ian Kelly: Methods implemented in C don’t really even have established argument specs. They just take tuples and dicts and use the PyArg_Parse* family of functions to unpack them. So effectively, all built-in methods have the argspec (self, *args, **keywords) The signature for Exception.__init__ seems to be (self, *args).

computation

Will Faught

1 minute

OS X Computer Name Is Not The Host Name

If you configure the OS X computer name in System Preferences, Sharing, Computer Name, but it’s not reflected by /bin/hostname, then execute sudo scutil --set HostName MYHOSTNAME and restart.

computation

Will Faught

1 minute

Exit Status-Colored Bash Prompt

My PS1 and PS2 Bash prompts: function colorprompt { status="$?" bold="\[\033[1m\]" cyan="\[\033[1;36m\]" red="\[\e[0;31m\]" off="\[\033[m\]" if [ “$status” -eq 0 ] then export PS1="$bold$cyan$$off " else export PS1="$bold$red$$off " fi export PS2="$bold>$off " } export PROMPT_COMMAND=colorprompt The color of the prompt is cyan if the last exit status was zero, otherwise it’s red. I disliked having little space to type commands in deeply nested directories, and I’m usually the same user on the same machine, so I only have the prompt $ terminator.

computation

Will Faught

1 minute

The Best OS X VNC Client

…is one that you already have.

computation

Will Faught

1 minute

My 2011–2012 Asia Backpacking Trip

Here are all the pictures of my 2011–2012 Asia backpacking trip: South Korea Japan Hong Kong Singapore Vietnam Taiwan Thailand Laos Cambodia Caution: A few pictures are not safe for work. Read the first post I made on the trip and browse from there.

asia travel

Will Faught

1 minute

OS X Terminal Meta Key

By default, there’s no meta key configured for OS X Terminal. For example, you can’t move backward one word in Bash. To configure the option key as the meta key, check “Use option as meta key” in Preferences, Settings, Keyboard.

computation

Will Faught

1 minute

April 2013

Homebrew And The OS X $PATH

I recently installed Homebrew on OS X and observed that the Homebrew binary path was added to the end of $PATH instead of the beginning, so even though I installed Python with Homebrew, python still resolved to the OS X version. Instead of fixing this in my ~/.profile with prepending the Homebrew path to $PATH, I edited /etc/paths and moved the Homebrew path to the first line. Now $PATH always has the Homebrew path first.

computation

Will Faught

1 minute

OS X Proxy Configuration

If you use OS X, and you use an HTTP forward proxy, and you use command line programs like curl or wget that use the HTTP or HTTPS protocols, then you must set the shell environment variables http_proxy and https_proxy (and their all-caps equivalents). An example of doing this in ~/.profile: export http_proxy="proxy.company.com:3128" export https_proxy="proxy.company.com:3128" export HTTP_PROXY=$http_proxy export HTTPS_PROXY=$https_proxy If you don’t do this, you’ll see errors like this: $ curl http://www.

configuration osx proxy technology

Will Faught

1 minute

Always Online Adam Orth Meme

Adam Orth resigned from Microsoft soon after the public relations shit storm he created. Here are some hilarious parodies that are part of a meme about him and his remarks. My favorite: I’m only an idiot when I’m online. And I’m always online. I feel bad for the guy. His remarks were obviously taken out of context. He shouldn’t have lost his job over this.

funny playing

Will Faught

1 minute

The Analytical Language Of John Wilkins

I was delighted to find a short story by Jorge Luis Borges that I hadn’t read before. I love his writings, and if you’re a software engineer, I bet you’d like them too: He divided the universe into forty categories or genera, these being further subdivided into differences, which were subdivided into species. He assigned to each genus a monosyllable of two letters; to each difference, a consonant; to each species, a vowel.

reading

Will Faught

1 minute

The Definitive C++ Book Guide And List

I decided to buy C++ Primer by Stanley Lippman et al.

computation reading

Will Faught

1 minute

March 2013

StarCraft II: Heart Of The Swarm Review

Tom Chick: And once again, the campaign is poorly written, poorly acted, erratically paced, full of pointless upgrades and meaningless choices, crammed full of overproduced cutscenes that fail to relate to the gameplay, and without a shred of creative insight into how to use a real time strategy game to tell a story, much less how to get me to click “next mission” without heaving a tired sigh. For all their incomparable game design smarts, Blizzard remains one of the worst storytellers in the business, partly for how hard they try and mostly for how spectacularly they fail.

playing

Will Faught

1 minute

Hacking A Google Interview

Some great software engineering job interview preparation materials.

computation

Will Faught

1 minute

The Beauty Of XOR

The beauty of XOR is that it’s commutative and doing the same XOR twice cancels it out: 1 XOR 0 XOR 1 = 0. 1 XOR 1 XOR 0 = 0. The solution to this problem is to XOR all the integers together: Given an unsorted integer array, where every integer occurs twice except one, which occurs once, find the single integer.

computation

Will Faught

1 minute

Simulate A Die Roll With Coin Tosses

Given an unbiased coin toss function, implement an unbiased die roll function. You can’t. Here’s an incorrect solution: Toss the coin three times. There are eight possible outcomes. If you get one of the first six possible outcomes, then use that to represent the die roll. If you get the seventh or eighth possible outcome, then try again. This solution ignores the premise that the coin toss is unbiased, and thus it isn’t guaranteed to halt in the case that you keep getting the seventh or eighth possible outcomes.

computation

Will Faught

1 minute

How To Generate A Random Number

I see what he did there.

funny

Will Faught

1 minute

Stack That Tracks The Minimum Element

Java: class MinStack<E> { private Stack<E> elements = new Stack<E>(); private Stack<E> mins = new Stack<E>(); public void push(E element) { elements.push(element); if (mins.isEmpty() || mins.peek().compareTo(element) > 0) mins.push(element); } public E pop() { if (elements.isEmpty()) throw new EmptyStackException(); E element = elements.pop(); if (mins.peek().compareTo(element) == 0) mins.pop(); return element; } public E min() { if (mins.isEmpty()) throw new EmptyStackException(); return mins.peek(); } }

code computation

Will Faught

1 minute

Finding Overlapping Axis-Aligned Rectangles

An interesting algorithm for finding a pair of axis-aligned rectangles that overlap. See also sweep and prune on Wikipedia.

computation

Will Faught

1 minute

Find A Substring

Java: boolean contains(String string, String substring) { if (string == null || substring == null) throw new NullPointerException(); int sublength = substring.length(); if (sublength == 0) return true; int length = string.length(); if (length < sublength) return false; char[] cs = string.toCharArray(); char[] subcs = substring.toCharArray(); for (int i = 0; i < length; ++i) { if (cs[i] == subcs[0]) { int j = 1; while (j < sublength && cs[i + j] == subcs[j]) ++j; if (j == sublength) return true; } } return false; }

code computation

Will Faught

1 minute

Can You Make A Ransom Note From A Magazine?

Java: boolean ransom(String note, String magazine) { if (note == null || magazine == null) throw new NullPointerException(); if (note.length() == 0) return true; if (magazine.length() == 0 || magazine.length() < note.length()) return false; char[] cs = note.toCharArray(); Map<Char, Integer> m = new HashMap<Char, Integer>(); for (char c: cs) if (m.containsKey(c)) m.put(c, m.get(c) + 1); else m.put(c, 1); cs = magazine.toCharArray(); for (char c: cs) if (m.containsKey(c)) { int i = m.

code computation

Will Faught

1 minute

Is An Integer A Power Of Two?

Java: boolean power2(int x) { return x != 0 && (x & (x - 1)) == 0; } A power of two must be greater than zero.

code computation

Will Faught

1 minute

Parse A Signed Integer

Java: int atoi(String s) { if (s == null) throw new NullPointerException(); int length = s.length(); if (length == 0) throw new NumberFormatException(); char[] c = s.toCharArray(); int n = 0; boolean negative = c[0] == '-'; for (int i = negative ? 1 : 0; i < length; ++i) { if (!Character.isDigit(c[i])) throw new NumberFormatException(); n = n - 10 + (c[i] - '0'); } return negative ? -n : n; }

code computation

Will Faught

1 minute

Member Variables In Outer Class Scopes

Refer to member variables that enclose larger scopes by the class name to which they belong. For example, the following statement accesses the member variable of the class ShadowTest from the method methodInFirstLevel: System.out.println("ShadowTest.this.x = " + ShadowTest.this.x); Just learned about this. I guess it doesn’t come up often.

computation

Will Faught

1 minute

Binary Tree Mirror Equals

Java: class Node { public int value; public Node left, right; public static boolean mirror(Node x, Node y) { if (x == null && y == null) return true; if (x == null || y == null) return false; return x.value == y.value && mirror(x.left, y.right) && mirror(x.right, y.left); } }

code computation

Will Faught

1 minute

Shuffling Arrays And Bias

Adrian Quark proving the Fisher–Yates shuffle is unbiased: Only later did I prove to myself that the current-or-later algorithm works. Think about the last element in an array of size n. What are the odds that it ends up at index 1? Obviously, 1/n. What about index 2? This is a bit trickier, since it’s a compound probability: we have to multiply the odds of not swapping with 1 by the odds of then swapping with 2, to find the probability of the element actually ending up at 2.

computation

Will Faught

1 minute

Remember To Shut Down ExecutorService

Methods that take a java.util.concurrent.Executor might not know if it’s an ExecutorService, so you have to call ExecutorService.shutdown() yourself.

computation

Will Faught

1 minute

First World Problems

My favorites so far: URL Husband Christmas Pillow Soda Computer Wi-Fi Poop HDTV Radio

funny

Will Faught

1 minute

Open And Shut

John Gruber: Where others offer choices, Apple makes decisions. What some of us appreciate is what so rankles the others — that those decisions have so often and consistently been right.

technology

Will Faught

1 minute

Method Return Types Should Be As Specific As Possible

Josh Bloch: In one sense, return values should have the opposite behavior of input parameters: It’s best to return the most specific applicable collection interface rather than the most general. For example, if you’re sure that you’ll always return a SortedMap, you should give the relevant method the return type of SortedMap rather than Map. SortedMap instances are more time-consuming to build than ordinary Map instances and are also more powerful.

computation

Will Faught

1 minute

Why You Shouldn’t Play Far Cry 3

Packed with funny lines like this: We start off with possibly the least-likable protagonist in the history of video games, Jason Brody, whose only previous work experience was as an Abercrombie & Fitch t-shirt tester. His distinguishing personality traits are “having white guy tribal tattoos” and “possibly wearing shorts.” I know personality seems like an odd thing to focus on in a first-person shooter, where the protagonists are traditionally mute and essentially invisible to the player.

playing

Will Faught

2 minutes

February 2013

Rename Files To Their Checksums

Bash: #!/bin/bash if [ -z “$1” ] then echo “renamehash: must specify a source directory” exit 1 fi if [ -z “$2” ] then echo “renamehash: must specify a target directory” exit 1 fi fromdir="$1" todir="$2" if [ ! -d “$fromdir” ] then echo “renamehash: path $1 is not a directory” exit 1 fi if [ -e “$todir” ] then echo “renamehash: path $1 already exists” exit 1 fi mkdir -p “$todir” find “$fromdir” -type f -not -name .

code computation

Will Faught

1 minute

Smoke Tests Vs. Sanity Tests

Software sanity tests are commonly conflated with smoke tests. A smoke test determines whether it is possible to continue testing, as opposed to whether it is reasonable. A software smoke test determines whether the program launches and whether its interfaces are accessible and responsive (for example, the responsiveness of a web page or an input button). If the smoke test fails, it is impossible to conduct a sanity test. In contrast, the ideal sanity test exercises the smallest subset of application functions needed to determine whether the application logic is generally functional and correct (for example, an interest rate calculation for a financial application).

computation

Will Faught

1 minute

Why Java’s Object.wait/notify/notifyAll Must Be Synchronized

Best explanation I’ve seen yet of why Java’s Object.wait/notify/notifyAll must be synchronized on the same Object instance, by Chris Smith: wait() isn’t strictly guaranteed to do anything at all. Something called “spurious wakeups” might occur. That is, a call to wait() can return at any time without any good reason. So a good rule of thumb for using wait() is that you should consider it to be nothing but an optimization.

computation

Will Faught

2 minutes

Nice Additions With Java 7

Strings in switch statements Binary number literals Integral literal digit group separators, e.g. 999_999_999 Generic type inference Catch statement handling multiple exception types

computation

Will Faught

1 minute

Performance Numbers Useful To Software Engineers

Time in nanoseconds of common operations like system calls, context switches, forks, L1/L2 cache references, disk seeks, etc.

computation

Will Faught

1 minute

January 2013

Longest Contiguous Subarray

Longest contiguous subarray of a signed int array that sums to zero or greater: int[] longest(int[] a) { if (a == null) return null; int longestIndex = -1, longestLength = 0; for (int i = 0; i < a.length; ++i) { int sum = 0; int length = 0; for (int j = i; j < a.length; ++j) { sum += a[j]; ++length; if (sum >= 0 && length > longestLength) { longestIndex = i; longestLength = length; } } } if (longestIndex == -1) return null; int[] b = new int[longestLength]; for (int i = 0; i < longestLength; ++i) b[i] = a[i + longestIndex]; return b; } I realize there’s a similar O(n log n) algorithm by Jon Bentley, but I haven’t studied it yet.

computation

Will Faught

1 minute

Binary Tree Sequentializations As Identities

The trace of a traversal [of a binary tree] is called a sequentialization of the tree. No one sequentialisation according to pre-, in- or post-order describes the underlying tree uniquely, but any combination of two types of sequentialisation does. Any two sequentializations of a binary tree can uniquely identify it, so you can directly compare those of any two binary trees to determine whether their structure and values are equal.

computation

Will Faught

1 minute

E Piss Bed

EPSBD is a mnemonic I use to remember five helpful approaches to solving algorithmic problems that I got from Cracking the Coding Interview by Gayle McDowell: Examplify: Derive rules from examples. To compute the angle between the hour and minute hands in a clock, first derive the rules for computing the angle of each hand separately, then derive the rule for computing the angle between the hands in terms of them.

code interviews technology

Will Faught

1 minute

IGN’s 2013 PC Game Predictions

Half-Life 3 will be announced as a multiplatform title as soon as Sony and Microsoft unveil their next-generation hardware plans. This sounds plausible. Concurrent launch windows would be perfect for a multi-platform release, and they’ve already done a few with the Orange Box and Left 4 Dead games. I’ve been awaiting this game for years. Bethesda Game Studios’ next role-playing game will be announced at E3 2013 and it’ll be Fallout 4.

playing

Will Faught

1 minute

Decide If A Binary Tree Is A Binary Search Tree

Java: Recursive solution 1: class Node { public Node left, right; public int value; private boolean first; private int previous; public boolean isBST() { first = true; return isBST(this); } private boolean isBST(Node n) { if (n == null) return true; if (!isBST(n.left)) return false; if (first) { first = false; previous = n.value; } else if (previous >= n.value) return false; previous = n.value; return isBST(n.right); } } Recursive solution 2:

code computation

Will Faught

1 minute

Partition Tree Nodes By Level

Java: class Node { public Node left, right; public LinkedList > traverse() { LinkedList<LinkedList<Node>> lists = new LinkedList<LinkedList<Node>>(); LinkedList<Node> list = new LinkedList<Node>(); Queue<Node> nodes = new LinkedList<Node>(); nodes.offer(this); int parents = 1, children = 0; while (parents > 0) { Node n = nodes.remove(); list.add(n); if (n.left != null) { nodes.offer(n.left); ++children; } if (n.right != null) { nodes.offer(n.right); ++children; } --parents; if (parents == 0) { lists.add(list); list = new LinkedList<Node>(); parents = children; children = 0; } } return lists; } } An even simpler solution:

code computation

Will Faught

1 minute

π