Skip to content

Instantly share code, notes, and snippets.

🤓
Trying to exit emacs

Brian Gordon briangordon

🤓
Trying to exit emacs
Block or report user

Report or block briangordon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@briangordon
briangordon / RecursiveThreadPoolExecutor.java
Created May 3, 2012
A ThreadPoolExecutor that shuts down when it runs out of tasks.
View RecursiveThreadPoolExecutor.java
public class RecursiveThreadPoolExecutor extends ThreadPoolExecutor {
private AtomicInteger count;
public RecursiveThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
count = new AtomicInteger(0);
}
public void execute(Runnable command) {
@briangordon
briangordon / gist:3382806
Last active Oct 8, 2015
JavaScript n-queens solution generator. This was written for an hour-long contest, so it's super sloppy.
View gist:3382806
var n = 40;
// Each row has exactly one queen. We have to determine which column to place each queen in.
var board = [];
function initBoard() {
// Put one queen in each row
board = [];
for(var row = 0; row < n; row++) {
board[row] = [];
@briangordon
briangordon / Text to pixel array
Created Mar 10, 2013
HTML5 JavaScript snippet for turning arbitrary text into a binary array of pixel on/off
View Text to pixel array
var buffer = document.createElement('canvas');
var bufContext = buffer.getContext("2d");
buffer.width = 60;
buffer.height = 20;
bufContext.fillStyle = "#FFFFFF";
bufContext.fillRect(0, 0, 60, 20);
bufContext.textBaseline = "top";
@briangordon
briangordon / gist:5374626
Created Apr 12, 2013
From Oracle's Class.java
View gist:5374626
/**
* Add a package name prefix if the name is not absolute Remove leading "/"
* if name is absolute
*/
private String resolveName(String name) {
if (name == null) {
return name;
}
if (!name.startsWith("/")) {
Class<?> c = this;
View covariant interfaces in java
interface Condiment {}
interface Ketchup extends ISuper {}
// This is a covariant interface
interface Kitchen<T extends Condiment> {
public void squirtCondiment(T covariant);
}
// This implements the Kitchen interface even though the implementation refers specifically to Ketchup in the type signature
class KetchupKitchen implements Kitchen<Ketchup> {
@briangordon
briangordon / Regex challenge
Last active Dec 20, 2015
This is a speed run. It's not how I would implement a more fully-featured regex engine. I was tripped up by a couple of bugs so the first one took me a total of 90 minutes to write. Later I had an idea for a simpler version that doesn't work in all cases. It took me 25 minutes to write.
View Regex challenge
Consider the subset of regular expressions that only use lowercase letters, parentheses, and the Kleene star *.
The presence of a Kleene star means that the preceding parenthesized phrase can appear zero or more times.
Parentheses are only valid around the text preceding a Kleene star. Write a program that takes such a regular
expression and a string and determines whether or not that entire string matches the regular expression.
For example, the string on the left matches the regular expression on the right:
hello hello
testtest (test)*
helllllllo he(l)*lo
View Horrifying code written when I was 14
P r o g r a m m i n g - a - M o d e - F i n d e r
-a guide to programming a mode finder-
By: Brian Gordon
____________
/Introduction\_________________________________
| |
|This guide will outline the technique I found |
|is the best way to determine a mode from a |
|set of data. It includes most of the source |
|code from the original program, then explains |
@briangordon
briangordon / gist:8656177
Created Jan 27, 2014
Encapsulation in JavaScript
View gist:8656177
function MyClass () {
var privateVariable = 5;
var privateMethod = function () {
return privateVariable;
};
this.publicMethod = function () {
return privateMethod();
}
}
@briangordon
briangordon / gist:8869639
Created Feb 7, 2014
English word frequencies
View gist:8869639
a,10144200
abandon,15323
ability,51476
able,103171
abortion,18925
about,208550
above,23866
abroad,8788
absence,13597
absolute,9622
View keybase.md

Keybase proof

I hereby claim:

  • I am briangordon on github.
  • I am brian (https://keybase.io/brian) on keybase.
  • I have the public key with fingerprint 41AA 1387 FA3D 5EAC 4F4B  18EE AE46 EFC0 2F3E 2BA8

To claim this, I am signing this object:

You can’t perform that action at this time.