Skip to content

Instantly share code, notes, and snippets.

View mavant's full-sized avatar

Matthew Avant mavant

View GitHub Profile
{-# LANGUAGE OverloadedStrings #-}
import Data.Conduit.List (sinkNull, mapMaybe)
import Numeric (showFFloat, showInt)
import System.Console.GetOpt.Simple
import Data.Conduit
import Data.List.Split (splitPlacesBlanks)
import Data.List (isSuffixOf)
import Network.Pcap.Conduit (Packet, sourceOffline, sourceLive)
import Network.Pcap.Base (hdrSeconds, hdrUseconds)

Keybase proof

I hereby claim:

  • I am mavant on github.
  • I am mavant (https://keybase.io/mavant) on keybase.
  • I have a public key whose fingerprint is 7D92 673E 93A1 2E1D EF57 8D0E D4D2 5B06 7EDA 7470

To claim this, I am signing this object:

@mavant
mavant / generate-pdf.py
Created December 11, 2013 20:31
As a christmas present for a friend, I'm making a leatherbound copy of "The Bro Code" from How I Met Your Mother. This script generates the formatted pdf document of all the articles - takes a csv file with a list of articles and a .tex file showing the format of a single article page, and spits back out a finished PDF. Extremely quick and dirty.
import csv
import re
from subprocess import call
outputfilename = 'BroCode.pdf'
articlecsv = 'Articles.csv'
formatfilename = 'page.tex'
output = open('latextemp.tex','w')
formatfile = open('page.tex', 'r')
@mavant
mavant / PrisonersDilemma.scm
Created December 2, 2013 10:14
Writing this seemed more appealing than packing for a flight.
(define (prisoners-dilemma player1 player2) ;;Payoffs correspond to years in prison (lower is better)
(let ((p1 (player1 player2 prisoners-dilemma)) ;;Each player is given the other player's source code and the game's source code
(p2 (player2 player1 prisoners-dilemma)))
(cond
((and (equal? p1 'C) (equal? p2 'C)) (cons 1 1))
((and (equal? p1 'C) (equal? p2 'D)) (cons 3 0))
((and (equal? p1 'D) (equal? p2 'C)) (cons 0 3))
((and (equal? p1 'D) (equal? p2 'D)) (cons 2 2)))))
(define (nicebot . z) 'C) ;;nicebot ignores the opponent and game; it always cooperates
@mavant
mavant / BattleofWits.scm
Last active December 29, 2015 20:59
So I was reading The Princess Bride today...
(define (generic-agent put drink survive) (lambda (arg)
(cond ((null? arg) put) ;; output a glass to put poison into
((boolean? arg) (survive arg)) ;; output whether you survive given poison
((procedure? arg) (drink arg)) ;; output a glass to drink given the other player's source
(else (error "Input type must be one of: Null, boolean, or procedure")))))
(define (contains? list element) (if (member element list) #t #f))
(define (battle-of-wits p1 p2)
@mavant
mavant / gist:7592872
Last active December 29, 2015 01:28
A dice roller with logging written for ninja-academy-online.com. MySQL server information removed. This was my first piece of PHP, many many moons ago.
<html>
<head>
<title>Dice Roller</title>
</head>
<body>
<?php
#first things first - if the user didn't specify a name, die.
IF ($_POST['name'] != null){
#looks like they gave a name!
@mavant
mavant / gist:7592828
Created November 22, 2013 00:55
Project Euler problem 22
import csv
names = []
sum = 0
with open ('names.txt', 'rb') as csvfile:
namereader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in namereader:
names = names + row
names.sort()
for i in range(len(names)):
@mavant
mavant / gist:7592822
Created November 22, 2013 00:55
Project Euler problem 24
import itertools
ints = range(10)
perms = list(itertools.permutations(ints))
print (perms[999999])
@mavant
mavant / gist:7592810
Created November 22, 2013 00:54
Project Euler problem 20
import math
a = math.factorial(100)
b = str(a)
d = 0
for c in b:
d += int(c)
print (d)
@mavant
mavant / gist:7592816
Created November 22, 2013 00:54
Project Euler problem 21
import math
def d(n):
sum = 0
for i in range(1, int(math.sqrt(n)+1)):
if (n % i == 0):
sum += i
return sum
amicable = []