Skip to content

Instantly share code, notes, and snippets.

@bgschiller
bgschiller / count.py
Created October 12, 2012 05:30 — forked from MorganBorman/count.py
Counting using a generator which returns the digits of an arbitrary number system
def count(digitgen):
"Takes an iterator which yields the digits of a number system and counts using it."
def subcount(digitgen, places):
if places == 1:
for d in digitgen():
yield d
else:
for d in digitgen():
for ld in subcount(digitgen, places - 1):
@bgschiller
bgschiller / na_ww_brute.hs
Created December 6, 2012 02:41
Brute force solution to Ninja Assassin Wonderwall problem
import Data.List (elemIndex)
-- | The 'permutations' function returns the list of all permutations of the argument.
--
-- > permutations "abc" == ["abc","bac","cba","bca","cab","acb"]
permutations :: [a] -> [[a]]
permutations xs0 = xs0 : perms xs0 []
where
perms [] _ = []
perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is)
@bgschiller
bgschiller / servertests.py
Last active December 14, 2015 10:39
Server tests for CSCI 367 Network Blackjack. Description and usage is in a comment following the code.
import string
import pexpect
import sys
import random
import argparse
import os
from utils import colors
def is_server_running(host,port):
'''Try to connect to the server, send a join and expect a conn'''
@bgschiller
bgschiller / rayage
Last active December 16, 2015 20:39 — forked from philipbjorge/rayage
Front End:
Run tests functionality (we can run every time they hit run)
[X] Test output tab has a line for every line in the reference
[x] Modify the html in static/custom/templates/Rayage.html to mess with test output contents
[X] 'Test' button sends a message asking for a diff. Server responds with a JSON object
[ ] downgrade Test output from terminal to something simpler
[ ] change 'Logout' to 'Unspoof' when we are spoofing. (Can't figure this one out. I have code that should do this at static/custom/RayageMenu.js:70. It's not very high priority for me)
Submit assignment
message to server: "submit_assigment"
@bgschiller
bgschiller / prime_iterator.cpp
Last active December 17, 2015 19:29
A lazily evaluated infinite list of primes, implemented in C++ but inspired by the Haskell at http://www.cs.tufts.edu/~nr/comp150fp/archive/melissa-oneill/Sieve-JFP.pdf
#include "prime_iterator.h"
#include <vector>
#include <algorithm> //std::binary_search
//allocation and initialization of the static member variable
std::vector<unsigned int> PrimeIterator::prime_list{2,3};
PrimeIterator::PrimeIterator() : position{0} { }
PrimeIterator::PrimeIterator(unsigned int pos) : position{pos} {
aecho -n "Enter the last number to check for prime-iness: "
read MAX
while [ -n "$(echo ${MAX} | sed -E "s/[0-9]*//g")" -o ${MAX} -ge 274 ]
if [ ${MAX} -ge 274 ]
aecho "Sorry, the line buffers are too short to hold that many numbers."
aecho -n "Please enter a number: "
else
aecho -n "'${MAX}' is not a number. Please enter a number: "
end
read MAX
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Draggable - Events</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<style>
.wrapper{
overflow:hidden; /*make sure the wrapper has no dimension*/
text-align: center;
@bgschiller
bgschiller / three_elems.py
Last active December 27, 2015 07:49
Three Elements that Sum to Zero solution
A = [-6, -8, 0, 3, 10, -8, 18]
def three_elems(A):
hashed_a = { val : index for (index, val) in enumerate(A) }
for i in range(len(A)):
for j in range(i+1,len(A)):
third_index = hashed_a.get(-1*(A[i] + A[j]))
if third_index is not None and third_index not in (i,j):
@bgschiller
bgschiller / sieve_class.pynb
Created November 15, 2013 19:27
Python Sieve of Eratosthenes class
{
"metadata": {
"name": "Sieve of Eratosthenes"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@bgschiller
bgschiller / Makefile
Created December 13, 2013 04:03
A thread-based pseudorandom number generator, and two adversaries that defeat it. Code for the blog post at http://brianschiller.com/blog/2013/12/12/pthreads-and-prngs-oh-my.html
all: thread_prng adversary Makefile advantages
thread_prng: thread_prng.c
gcc --std=c99 -o thread_prng -lpthread thread_prng.c
adversary: adversary.c
gcc --std=c99 -o adversary adversary.c
advantages: adversary thread_prng
for option in r m; do \