Skip to content

Instantly share code, notes, and snippets.

View adamnew123456's full-sized avatar

Chris Marchetti adamnew123456

  • Chapel Hill, NC
View GitHub Profile
@adamnew123456
adamnew123456 / utils.js
Created August 16, 2016 17:09
Various Small DOM-manipulation Utilities
/*
* Returns a list of all the text nodes under the given node.
*
* The order should be depth-first, first-to-last across siblings.
*/
function findTextNodes(node) {
var HTML_TEXT_NODE = 3;
if (node.nodeType == HTML_TEXT_NODE) {
return [node];
}
@adamnew123456
adamnew123456 / diff.py
Last active March 4, 2024 08:03
An implementation of the Myers diff algorithm
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@adamnew123456
adamnew123456 / default.js
Last active June 8, 2016 16:12
Elevator Saga - Current Attempt
{
// NOTE: Only expect this to work on FF, Chrome or Edge.
// There are several arrow functions sprinkled around,
// and caniuse suggests that these are the only browsers
// that can handle them natively
init: function(elevators, floors) {
// The backlog is (an approximation of) the number of people currently waiting at
// the given floor.
//
@adamnew123456
adamnew123456 / TestDiGraph.java
Last active April 14, 2016 17:31
UNC COMP 410 - Assignment 6 Unit Tests
import static org.junit.Assert.*;
import org.junit.Test;
public class TestDiGraph {
/*
* Refactoring the commonalities of comparing toposorts with multiple
* valid results, into its own function.
*/
public void assertCorrectSort(DiGraphInterface graph, String... correct) {
String[] sorted = graph.topoSort();
@adamnew123456
adamnew123456 / BinaryHeapTest.java
Created March 21, 2016 17:00
UNC COMP 410 - Assn 5
import static org.junit.Assert.*;
import org.junit.Test;
public class BinaryHeapTest {
/**
* If you are expecting null, then don't use this function - it is not null
* safe.
*/
private void entryPairAssertEqual(EntryPair expect, EntryPair actual) {
if (expect.getPriority() != actual.getPriority() ||
@adamnew123456
adamnew123456 / compute-offsets.pl
Last active March 6, 2016 15:35
Calculate .data label addresses for simple MARS programs
# Computes the offsets of values in a MIPS .data segment
my $in_data = 0;
my $mem_offset;
my $current_label = "";
# Gets rid of C escapes like \n - note that this is only meant to preserve
# the length of the string, so it uses single-character placeholders rather
# than actually interpreting the escapes. For example, it would replace:
#
# Foo\'s bar\n
package a6.test;
import a6.Pixel;
import a6.ColorPixel;
import a6.Coordinate;
import a6.Region;
import a6.Frame2D;
import a6.ObservableFrame2D;
import a6.ObservableFrame2DImpl;
import a6.ROIObserver;
@adamnew123456
adamnew123456 / uKanren.scala
Last active March 15, 2017 02:36
microKanren In Scala
/**
* An implementation of microKanren (and probably most of miniKanren), with
* a few extras. Currently, it supports:
*
* - The essential core of microKanren: Unify, Fresh, Disjunction, Conjunction
* - Standard terms: Variables, Atoms, TermCons, EmptyTerm.
* - An implicit conversion from type T to Atom[T]. This makes writing programs
* much easier.
* - A decent reifier, which converts terms to strings.
*
@adamnew123456
adamnew123456 / fizzbuzz.s
Created May 13, 2015 20:59
FizzBuzz In x86 Assembly
// FizzBuzz in x86 assembly - written on 32-bit Linux using the GNU ASsembler
.data
FIZZSTR:
.asciz "Fizz"
BUZZSTR:
.asciz "Buzz"
NEWLINE:
.asciz "\n"
// strtoa stores its data here. Since FizzBuzz runs 1-100, it won't need more than 3 bytes
<canvas id="canvas" width="600" height="600">
</canvas> </br>
Method: <input id="algorithm" type="text"> </input> <br/>
Timestep (Hz): <input id="timestep" type="text"> </input> <br/>
<input id="start_stop" type="button" value="Start" onclick="run()"> </input> <br/>
<script>
////////////////////
var PERSON_RADIUS = 1;
var PERSON_SPEED = 5;