Skip to content

Instantly share code, notes, and snippets.

View brenns10's full-sized avatar

Stephen Brennan brenns10

View GitHub Profile
@brenns10
brenns10 / curry.scm
Created April 10, 2015 02:35
Curry a function in Scheme
(define curryn
(lambda (func n)
(((lambda (f) (f f))
(lambda (f)
(lambda (function remaining args)
(if (zero? remaining)
(apply function args)
(lambda (v)
((f f) function (- remaining 1) (cons v args)))))))
func n '())))
@brenns10
brenns10 / interpreter.pl
Last active August 29, 2015 14:19
Interpreter for C-like language subset, in Prolog, by Dr. Connamacher.
% m_state for while
m_state([while, C, B], S, S0) :- m_boolean(C, S), !,
m_state(B, S, S1),
m_state([while, C, B], S1, S0).
m_state([while, _, _], S, S).
% m_state for assignment
m_state([L, =, R], S, S0) :- remove_binding(L,S,S1),
m_value(R,S,V),
@brenns10
brenns10 / newmirrors
Created May 20, 2015 13:56
Pacman Mirrorlist Updater
#!/bin/sh
# Pacman Mirrorlist Updater
# Stephen Brennan <stephen@stephen-brennan.com>
# Display help.
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "usage: newmirrors"
echo "All-in-one utility for dealing with pacman mirrorlist updates."
echo
echo "Steps:"
@brenns10
brenns10 / search.org
Last active July 11, 2022 00:20
Emacs Web Searching

Introduction

Sometimes I want to make a quick web search, and I’d prefer not to leave Emacs. Sure, I could switch over to a different workspace and open a browser, but I’d much rather do it in Emacs if possible. eww will let you search instead of enter a URL, but you only get one search engine (which is, by default, Duck Duck Go). I’m used to the wonderful interface of Chrome, which allows you to use a keyword to specify your search engine, right within the “Omnibox”. Anything else feels crude. So, I decided I would implement my own search solution!

@brenns10
brenns10 / sleepsort.c
Created July 1, 2015 20:49
Sleep Sort
/***************************************************************************//**
@file sleepsort.c
@author Stephen Brennan
@date Wednesday, 1 July 2015
@brief C Sleep Sort Implementation.
@brenns10
brenns10 / example.md
Created July 8, 2015 01:06
CKY Output

Example Output of CKY Lexer

Here is the lexer description file:

[a-zA-Z_]\w*	identifier
\d+	integer
\+	ADD
\-	SUBTRACT
@brenns10
brenns10 / repl.py
Created August 2, 2015 19:50
Embed REPL
"""Embed your most feature rich REPL."""
_embed_banner = '\n* BREAKPOINT: {filename}:{line}\n* Ctrl+D to continue...'
def _embed_ptipython():
"""
Embed a ptpython prompt using IPython.
PTPython has an IPython module supporting the exact same embedding API as
@brenns10
brenns10 / linkedlist.c
Last active September 22, 2015 15:41
Linked List in C
#include <stdio.h>
#include <stdlib.h>
struct node {
int value;
struct node *next;
};
void ll_print(struct node *list)
{
@brenns10
brenns10 / .travis.yml
Last active February 1, 2020 05:45
Travis Sphinx Auto-Doc
language: python
python:
- 3.5
install:
- pip install sphinx sphinx_rtd_theme
script: make html
after_success:
- ./push.sh
env:
global:
@brenns10
brenns10 / gambler.py
Last active October 16, 2015 12:06
Gambling Chip Algorithm
"""
Finds optimal strategy for gambling chip game.
Problem: two players (Alice and Bob) play a game where gambling chips (with
numeric values) are laid out in a line. They alternate turns. During their
turn, a player picks up a chip on either end of the line, but not from anywhere
in the middle, and adds that chip to their collection. At the end, the player
with the higher valued collection of chips wins.
This is a dynamic programming algorithm for solving the problem. It runs in