Skip to content

Instantly share code, notes, and snippets.

@raheelahmad
raheelahmad / gist:1436073
Created December 6, 2011 00:24
PL Project
<p>There are three threading problems listed <a href="http://www.d.umn.edu/~cprince/courses/cs5631spring10/lectures/ThreadAndSynch.pdf">here</a>. Do all three of them (separately).</p>
<p>This will be due by next Wednesday, Dec. 14th. But, I want you to show me the running code instead of submitting it. Let me know before Monday when you can see me next week.</p>
@raheelahmad
raheelahmad / gist:1304311
Created October 21, 2011 16:56
Partitioning an array: bare bones
// partition2.java
// demonstrates partitioning an array
// uses highest-index (right) element as pivot
// to run this program: C>java PartitionApp
////////////////////////////////////////////////////////////////
class ArrayPar
{
private long[] theArray; // ref to array theArray
private int nElems; // number of data items
//--------------------------------------------------------------
@raheelahmad
raheelahmad / gist:1299069
Created October 19, 2011 17:42
Midterm Exam
class LineDrawer {
float x1, y1, x2, y2;
boolean movingForward;
void drawItself() {
line (x1, y1, x2, y2);
}
void update() {
if (movingForward) {
@raheelahmad
raheelahmad / gist:1281971
Created October 12, 2011 17:51
Mouse Inside Ball Objects
class MovingBall {
float x, y, w, maxW, speed; // variables for drawing the ellipse
boolean movingForward;
boolean movingUp;
boolean expanding;
boolean mouseInside;
float r, g, b;
void drawItself() {
@raheelahmad
raheelahmad / gist:1275956
Created October 10, 2011 17:51
Veritcal Boxes
class Box {
float x, y, w, h, speed;
boolean movingForward, movingUp;
void drawItself() {
rect(x, y, w, h);
}
void update() {
if (movingForward)
@raheelahmad
raheelahmad / gist:1275840
Created October 10, 2011 17:18
Circle Drawer
class CircleDraw {
float x, y, r, a;
void drawSelf() {
fill(255);
noStroke();
ellipse(x + r * cos(a), y - r * sin (a), 5, 5);
a += 0.1;
if (a >= 2 * PI) {
@raheelahmad
raheelahmad / gist:1259699
Created October 3, 2011 17:35
Drawing boxes
class Box {
float x, y, w, h;
void drawItself() {
rect(x, y, w, h);
}
}
Box myBox;
@raheelahmad
raheelahmad / gist:1259647
Created October 3, 2011 17:20
Circles with variable speed, size, and color
class MovingBall {
float x, y, w, maxW, speed; // variables for drawing the ellipse
boolean movingForward;
boolean movingUp;
boolean expanding;
float r, g, b;
void drawItself() {
fill(r, g, b);
@raheelahmad
raheelahmad / gist:1248966
Created September 28, 2011 19:29
Problem 2.68
/*
* Mask with least signficant n bits set to 1
* Examples: n = 6 --> 0x2F, n = 17 --> 0x1FFFF
* Assume 1 <= n <= w
*/
int lower_one_mask(int n) {
/*
* 2ˆn-1 has bit pattern 0...01..1 (n 1’s)
* But, we must avoid a shift by 32
@raheelahmad
raheelahmad / gist:1248645
Created September 28, 2011 17:49
Drawing MovingBalls
class MovingBall {
float x, y, w; // variables for drawing the ellipse
boolean movingForward;
boolean movingUp;
void drawItself() {
ellipse(x, y, w, w);
}