Skip to content

Instantly share code, notes, and snippets.

View spencer-p's full-sized avatar

Spencer Peterson spencer-p

View GitHub Profile
/*
* walloftext.c
*
* This is a hacky program to produce a paragraph of random text with
* parts of a quote highlighted and spaced through it.
* Don't judge, I didn't spend long on this.
*
* Usage:
* ./walloftext [file]
* where [file] contains the quote, with each section on a new line
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
@spencer-p
spencer-p / README.md
Created November 13, 2017 08:49
A Primer on Go, JSON, and More: Part 1

A Primer on Go, JSON, and More: Part 1

First, for those who will be writing software, I highly suggest first checking out some of the Go documentation. The website is available at golang.org, and I would encourage going through the interactive tutorial and watching this video, which goes over some of the topics I'm about to review.

If you can, try to go through more of the Go tour than just the "Welcome" section. Methods and Interfaces may be

@spencer-p
spencer-p / README.md
Last active November 14, 2017 00:49
traffic lib example

Early Traffic Simulator Example

This is an early example of how we might interface with the simulator libary I am building. Nothing about the library is finalized, however, so be aware that much is likely to change.

Most interfaces and such will likely be made private. The Edge interface may gain more methods but probably won't lose any.

This program exists more for testing and edification than actually usage.

Getting the thing

@spencer-p
spencer-p / 0-README.md
Last active October 21, 2023 15:18
Coding golf shell!

Coding Golf Shell

This is a fully functional UNIX shell implemented in minimal bytes. You may have to disable some compiler warnings to compile it.

Feature Set

  • Execution of single commands as expected
  • Piping commands arbitrarily with |
  • Redirecting both standard input and output with &lt; and &gt; respectively
# check if an array is monotonically increasing
# with recursion
def is_sorted(A):
n = len(A)
if n <= 1:
# arrays of no elements or one element are always sorted
return True
first_half = A[:n//2]
# This is a greedy algorithm.
# Proof of correctness left as an exercise for the reader.
# https://en.wikipedia.org/wiki/Greedy_algorithm
def make_change(N, D):
# Make sure the largest coins are first
D.sort()
D.reverse()
# Solution is a map from coin value to # of that coin
def maxSubArray(A):
T = A[0]
S = T
for i in range(1, len(A)):
T = A[i] + max(T, 0)
S = max(S, T)
return S
if __name__ == '__main__':
/*
* basechange.c
* This is a simple tool to display a number (from any base) in decimal, hexadecimal, octal, and binary.
*/
#include <stdio.h>
#include <stdlib.h>
void print_all_bases(int n);
void print_bits(int n);
package main
import (
"context"
"flag"
"log"
"net"
"time"
)