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 / Example.scala
Last active October 11, 2015 03:47
Shuffled (Uniform Random) Range in Scala
import scala.util.Random
// print unshuffled range
(1 to 10) foreach { i => println(i) }
// print shuffled range
val r = new Random()
r.shuffle(1 to 10 toIterable) foreach { i => println(i) }
import scalation.linalgebra.VectorD
import scalation.random.Normal
object NaiveBayes extends App {
val miles = VectorD(1300, 900, 2000, 1450, 2190, 1600, 300, 3100, 1521, 1786)
val mean = milel.sum / miles.dim.toDouble
val variance = ((miles - mean) ~^ 2).sum / (miles.dim.toDouble - 1)
def PrMiles (x: Double) = Normal(mean, variance).pf(x)
/**
* A disjoint sets data structure.
*
* @author Michael E. Cotterell <mepcotterell@gmail.com>
* @param n the number of initial disjoint sets
*/
class OldDisjointSets (n: Int) {
// make sure we're using mutable sets
import scala.collection.mutable.{ BitSet, Set }
public class Armstrong {
public static void main(String[] args) {
for (int a = 0; a < 9; a++) {
for (int b = 0; b < 9; b++) {
for (int c = 0; c < 9; c++) {
int n = a * 100 + b * 10 + c;
int a3 = a * a * a;
int b3 = b * b * b;
int c3 = c * c * c;
if (a3 + b3 + c3 == n) System.out.println(n);
@mepcotterell
mepcotterell / gist:4548901
Created January 16, 2013 17:14
Add line numbers to Emacs
;; add line numbers
(global-linum-mode 1)
;; display line numbers and column numbers
(setq line-number-mode t)
(setq column-number-mode t)
;; make sure the line numbers don't touch the text
(setq linum-format "%d ")
@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;
@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 <mepcotterell@gmail.com>
* @param a the multiplier
* @param c the increment
@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 "your_email@youremail.com"
$ git config --global --add color.ui true
@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 / .gitignore
Last active December 13, 2015 17:18
Fun with Polymorphism
*.class
*~
\#*\#
semantic.cache