Skip to content

Instantly share code, notes, and snippets.

@ellbur
ellbur / YoDawg.scala
Created May 31, 2013 04:50
Showing how react clobbers the stack and avoids a stack overflow
import scala.actors._
import Actor._
object YoDawg extends App {
val leonardo = actor {
def yo() {
println("yo")
reactWithin(1) {
case TIMEOUT => dawg()
@ellbur
ellbur / ActorContinuationTest.scala
Last active December 17, 2015 22:38
Passing continuations in an Actor to offload a long-running, multi-step computation without making a state machine.
import javax.swing._
import java.awt.{List => _, _}
import scala.util.Random
import scala.actors._
import Actor._
import java.awt.event._
object ActorContinuationTest extends App {
// The GUI
@ellbur
ellbur / bar.vhd
Created September 29, 2012 14:53
VHDL Testbench 2
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use ieee.std_logic_textio.all;
use ieee.std_logic_1164.all;
entity Bar is
end entity Bar;
@ellbur
ellbur / foo.vhd
Created September 29, 2012 14:52
VHDL Testbench 1
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use ieee.std_logic_textio.all;
use ieee.std_logic_1164.all;
entity Foo is
end entity Foo;
@ellbur
ellbur / Polygon.java
Created December 15, 2011 20:58
Polygonz
public class Polygon
{
// define fields here
private int numvertices;
Point[] vertices;
public Polygon(int numvertices)
{
this.numvertices = numvertices;
@ellbur
ellbur / Spiral.java
Created December 15, 2011 20:51
Spiral
public class Spiral {
public static void main(String[] args) {
Drawing d = new Drawing();
spiral(d, 4);
}
static void spiral(Drawing d, int n) {
// Base case
@ellbur
ellbur / Round.java
Created December 15, 2011 20:43
Rounding
public class Round {
public static void main(String[] args) {
System.out.println(round(3.124, 2));
}
static double round(double x, int n) {
double y = x * tenToN(n);
y = Math.round(y);
@ellbur
ellbur / Hotel.java
Created December 15, 2011 20:43
The HotelRoom class
public class Hotel {
public static void main(String[] args) {
HotelRoom room = new HotelRoom();
room.setGuestName("Joe");
HotelRoom room2 = new HotelRoom();
System.out.println(room.getGuestName());
room.setGuestName("Melissa");
@ellbur
ellbur / Back.java
Created December 15, 2011 20:31
Reverse with recursion
public class Back {
public static void main(String[] args) {
System.out.println(backRec("cs-111"));
}
static String back(String x) {
String y = "";
for (int i=0; i<x.length(); i++) {
@ellbur
ellbur / Triangle.java
Created November 15, 2011 20:25
Triangles
public class Triangle {
public static void main(String[] args) {
Turtle.setSpeed(1000);
x(6);
}
static void x(int n) {
if (n == 0) {