Skip to content

Instantly share code, notes, and snippets.

View mepcotterell's full-sized avatar
💭
I may be slow to respond.

Michael Cotterell mepcotterell

💭
I may be slow to respond.
View GitHub Profile
@mepcotterell
mepcotterell / Multinomial.scala
Last active December 15, 2015 01:19
Linear-Time Multinomial Coeffiecients
object Combinatorics {
/** Computes the multinomial coefficient (n; k_1, .., k_m)
* where n = the sum of k_1, .., k_m.
*
* This is a variadic convenience function that allows
* someone to invoke <code>multi</code> without using an
* array. Note, however, that the variadic parameter is
* transformed into an array when this version of
* <code>multi</code> is invoked.
@mepcotterell
mepcotterell / Driver.java
Last active December 14, 2015 14:38
Java Swing Starter Kit (sbt)
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class Driver {
public static void createAndShowGUI() {
@mepcotterell
mepcotterell / Form.java
Last active December 14, 2015 07:28
Swing examples from class.
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Form {
#!/usr/bin/env python3
'''
subnet -- phatty tools for dealing with subnets
@author: Michael E. Cotterell <[email protected]>
'''
import struct
import sys
@mepcotterell
mepcotterell / README.md
Last active July 14, 2020 17:28
Fun with tcpdump and hexdump...

Fun with tcpdump and hexdump

Here is some information that I've found/discovered from playing around with packets. The following is presented in an adhoc tutorial style. Hopepully you find it interesting.

tcpdump

Something that I found useful was the ability to actually capture the raw UDP packet using tcpdump utility. In the following example, we'll capture a DNS query packet and save it to a file.

Open up two terminal windows. In one window, type the following:

@mepcotterell
mepcotterell / .gitignore
Last active December 13, 2015 17:18
Fun with Polymorphism
*.class
*~
\#*\#
semantic.cache
@mepcotterell
mepcotterell / examples.md
Last active December 12, 2015 02:59
Some C++ utility functions...

Assume the following:

include "range.h"

using namespace mepcotterell;

Then you can do cool stuff like this:

@mepcotterell
mepcotterell / Examples.md
Last active December 11, 2015 23:08
Examples from class...

Git Examples

Configuration

The first thing you'll want to do is configure git on your nike account.

$ git config --global user.name "Your Name Here"
$ git config --global user.email "[email protected]"
$ git config --global --add color.ui true
@mepcotterell
mepcotterell / LCG.scala
Created January 27, 2013 00:12
Stream-based Linear Congruential Generator in Scala
/**
* Linear Congruential Generator
*
* This implementation allows you to grab an individual number by its index. It
* also provides a stats object for displaying statistics about the lcg.
*
* @see http://en.wikipedia.org/wiki/Linear_congruential_generator
* @author Michael E. Cotterell <[email protected]>
* @param a the multiplier
* @param c the increment
@mepcotterell
mepcotterell / gist:4567532
Last active December 11, 2015 07:38
Intermediate Programming with Java

Pass by Value in Java

Variable Declaration and Memory

When you declare a variable of any type (including class/reference types), some space is reserved in memory in order to hold the value of the variable. The variable is just a symbolic name for this value in memory.

Let's say we declare a long.

long x;