Skip to content

Instantly share code, notes, and snippets.

View jdavis's full-sized avatar
💾

Josh Davis jdavis

💾
View GitHub Profile
@jdavis
jdavis / open_port.py
Created November 8, 2012 17:26
Find an open port in Python.
import socket
def find_open_port():
"""
Use socket's built in ability to find an open port.
"""
sock = socket.socket()
sock.bind(('', 0))
@jdavis
jdavis / terrariad
Created December 28, 2013 21:23
Simple init.d Service script to start a tshock Terraria Server
#!/bin/sh
#
# Terraria Config
#
# Tmux session ID
SESSION=terraria
# Username to run as
# Rename a file and keep it in the same location
rename() {
if [ "$#" -ne 2 ]; then
echo "usage: $0 path/to/file/old_name new_name"
return
fi
mv $1 `dirname $1`/$2
}
@jdavis
jdavis / AREADME.md
Last active December 28, 2015 17:59

CS311 Homework 6 Tests

Downloading

To use these tests, just use Git and clone them into the directory you have your project.

You can do this using:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jdavis
jdavis / Project2Tests.sh
Last active December 16, 2015 11:29
Set of simple tests for the second project of Computer Science 352 at Iowa State University.
#!/usr/bin/env sh
#
# Project 2 Tests
# Josh Davis
#
# Overview:
# A few quick and crude tests for project 2.
#
# Running:
# To run it, make sure it has the right permissions:
@jdavis
jdavis / adapter.py
Created April 17, 2013 12:03
Example of the Adapter Design Pattern in glorious Python code.
"""
Example of the Adapter Design Pattern
"""
class RocketShip(object):
def turnOn(self):
raise NotImplementedError()
@jdavis
jdavis / ternary.c
Created April 11, 2013 05:18
Code sample showing the wonkiness of the precedence of the ternary statement in C.
#include <stdio.h>
char identity(char x);
int main(int argc, const char *argv[]) {
int compound;
printf("For reference:\n");
printf(" the ASCII value of %c is %d\n", ';', ';');
printf(" the ASCII value of %c is %d\n", '}', '}');
@jdavis
jdavis / solution.pdf
Last active December 14, 2015 21:49
Homework #4 for Computer Science 331 - Theory of Computing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jdavis
jdavis / puzzle.py
Created March 31, 2015 20:43
Python Functional Puzzle
def cons(x, y):
return lambda f: f(x, y)
def car(x):
# Fill out this function
pass
if car(cons(1, 5)) == 1:
print 'Solved!'
else: