Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View traviskaufman's full-sized avatar

Travis Kaufman traviskaufman

View GitHub Profile
@traviskaufman
traviskaufman / ReverseBinary.java
Created February 21, 2013 23:33
My Solution to Spotify's [Reversed Binary Numbers](https://www.spotify.com/us/jobs/tech/reversed-binary/) problem that's apparently wrong for reasons unknown to me. -_-
import java.util.Scanner;
/**
* Class that contains logic to reverse the bits of an integer and spit it
* back out.
*/
public class ReverseBinary {
/**
* Reverse the bits of an integer between 1 ≤ n ≤ 1000000000.
@traviskaufman
traviskaufman / cats_vs_dogs.py
Last active December 14, 2015 04:19
My best go at Spotify's Heavy Metal question.
"""
I apologize this isn't more well-documented :/
"""
#!/usr/bin/env python
"""
Plays the game of cat vs. dog
"""
from sys import stdin
@traviskaufman
traviskaufman / play_framework_testing_async_responses.md
Last active June 8, 2023 09:09
Testing Asynchronous HTTP Responses in Play Framework

Testing Asynchronous Responses in Play! Framework

TL;DR

The Background

I came across this issue while I was working on a functional test for JAMLive!, a Play! application I'm currently working on obsessing over in my free time. I have a controller with a connect method that looks like this:

@traviskaufman
traviskaufman / fe_techinterviewq.md
Last active November 1, 2016 20:09
Comprehensive Front-End Technical Interview Question

###Comprehensive Technical Interview Question

Consider the following javascript module:

/**
 * A module for tracking when a user visits the page.
 */
window.VisitingDateTracker = {
  /**
 * Initialize the tracker.
@traviskaufman
traviskaufman / jasmine-this-vars.md
Last active September 19, 2022 14:35
Better Jasmine Tests With `this`

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {
@traviskaufman
traviskaufman / protobuf_2_6_0_ubuntu_install.sh
Created December 29, 2014 18:33
Shell Script to Compile and Install protobuf v2.6.0 on Ubuntu
# Installs protobuf 2.6.0 on Ubuntu (currently not a deb package ugh)
protodir=protobuf-2.6.0
filename="$(protodir).tar.gz"
known_md5=9959d86087e64524d7f91e7a5a6e4fd7
builddir="$(mktemp -d $TMPDIR/protobuild.XXXXXX)"
if [ ! -d $builddir ]; then
echo "$0: Can't create temp build dir! WTF??!"
exit 1
@traviskaufman
traviskaufman / logback_disable_in_unit_tests.md
Last active March 20, 2023 08:38
Logback: Disable all logging in unit tests

After scouring the internet and piece-mealing together the correct way to do this, here is a step-by-step, all-in-one-place guide to making logback STFU when running your unit tests.

Here's how to do it

Save the following as logback-test.xml under src/test/resources:

<configuration>
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <pattern>%msg%n</pattern>
@traviskaufman
traviskaufman / hapi-i18n.js
Created February 12, 2015 03:33
Minimal i18n plugin for HapiJS using node-i18n
'use strict';
import _ from 'lodash';
import i18n from 'i18n';
import {version} from '../../package.json';
registerI18n.attributes = { name: 'i18n', version };
export default registerI18n;
@traviskaufman
traviskaufman / group-rename-yosemite-translation.md
Created May 2, 2015 13:41
(Translation) How to Easily Rename a Group of File on OS X Yosemite

This is an english translation of http://www.guideitech.com/apple/come-rinominare-facilmente-un-gruppo-di-file-su-os-x-yosemite/ While I translated it mostly to practice my Italian, it's a great article and shows a cool feature on Yosemite if you don't want to deal with doing this at the command line :) Also please let me know if you find any mistakes or bad translations!

How to rename a group of files on OS X Yosemite

I’m sure there are hundreds of unorganized files on your macs right this moment. Vacation photos, PDF documents, downloads, TV series, or whatever. The first step in organizing these contents is to give them proper names.

@traviskaufman
traviskaufman / merge-intervals.js
Last active May 14, 2020 17:06
Merge Intervals - O(n) average case time rather than THETA(nlogn)
// See: http://www.programcreek.com/2012/12/leetcode-merge-intervals/
console.log(mergeIntervals([[1,3],[2,6],[8,10],[15,18]]));
console.log(mergeIntervals([[1,8], [2,10], [3,6]]));
console.log(mergeIntervals([[1,8], [2, 8], [3, 6]]));
function mergeIntervals(intervals) {
if (intervals.length < 2) {
return intervals;
}