Skip to content

Instantly share code, notes, and snippets.

View pepasflo's full-sized avatar

Jason Pepas (FloSports.tv) pepasflo

View GitHub Profile
@pepasflo
pepasflo / demo.txt
Last active November 14, 2018 16:19
large test file generator for the "balanced parens" problem
$ for i in {1..10}; do ./gen-test-file.py 20 ; echo ; done
[{{}{[[(){}[[][[([[][()]])(())]][{}]]][{}]]}}]
{[{{}([{{({[[(({}{{}}()))]]})[{}]}}])}()]}
{[{[[{{[]}([{({(({([])}))}{[]})}]())()}]]}[]()]}
()[({({[]({[{()}{[()]}]}[])}{}()())})[]]
[[([]{}{([([[{(([{()[([])]}])[])[]}](){}(){[]}])])}[])]]
[({{[{[][({[]({[(){()[]}][]})}{}())]}]}{}})[]]
({[]{()}(((({({[]([[[]]])()})})){()}){}[])}()[])
[(){{{[((((([[{{}}({})]{}]([{}]())[])){})))]}}({}()[])}]
[{{{}}([[]([]()({}[]()))])}]
@pepasflo
pepasflo / README.md
Created November 7, 2018 00:30
Updated lexers
test: kth-from-end
./kth-from-end
kth-from-end: kth-from-end.c
gcc -Wall -Werror -o kth-from-end kth-from-end.c
clean:
rm -f kth-from-end
.PHONY: test kth-from-end
@pepasflo
pepasflo / pod
Created November 1, 2018 16:26
A pod wrapper script which uses 'bundle exec' if a Gemfile is found.
#!/usr/bin/env python
# A wrapper for 'pod' which detects if it should run 'bundle exec pod' or
# use the system 'pod' command, based on the presence of a 'Gemfile'.
# If a Gemfile exists in any directory above pwd, 'bundle exec pod' should
# be used. Otherwise, the system 'pod' is used.
# Expected behavior:
# $ pwd
@pepasflo
pepasflo / create-test-input-file.sh
Last active October 30, 2018 22:14
Basic lexers in javascript and python
#!/bin/bash
# use this to create a ~500,000 line C file for performance testing
set -e -o pipefail
if [ ! -e linux-4.19.c ]
then
curl https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz | unxz | tar x
cd linux-4.19
@pepasflo
pepasflo / lexer.js
Last active July 30, 2023 09:03
A regex-based javascript lexer / scanner / tokenizer
#!/usr/bin/env node
var assert = require('assert');
// Each lexed token is a array of three integers:
// 1. the "token type": an index into the list of token patterns.
// 2. the index into the input string marking the start of this token.
// 3. the length of the token.
// The list of "token types" which our lexer understands:
@pepasflo
pepasflo / .gitignore
Last active October 22, 2023 12:06
Scripts for encrypting / decrypting secrets (to prevent them from being accidentally checked into git)
secrets/
@pepasflo
pepasflo / egg-drop.md
Last active September 13, 2018 00:59
Some thoughts on the "egg drop" problem: https://www.interviewcake.com/question/python/two-egg-problem

Problem description:

https://www.interviewcake.com/question/python/two-egg-problem

A building has 100 floors. One of the floors is the highest floor an egg can be dropped from without breaking.

If an egg is dropped from above that floor, it will break. If it is dropped from that floor or below, it will be completely undamaged and you can drop the egg again.

Given two eggs, find the highest floor an egg can be dropped from without breaking, with as few drops as possible.

@pepasflo
pepasflo / output.txt
Created September 12, 2018 20:30
interviewcake.com problem: Detect if a given single-rifle shuffled deck is possible from the given two halves.
++ ./shuffle.py '[1]' '[2]' '[1,2]'
+ test True == True
++ ./shuffle.py '[1]' '[2]' '[2,1]'
+ test True == True
++ ./shuffle.py '[1,2]' '[3]' '[1,2,3]'
+ test True == True
++ ./shuffle.py '[1,2]' '[3]' '[1,3,2]'
+ test True == True
++ ./shuffle.py '[1,2]' '[3]' '[3,1,2]'
+ test True == True
@pepasflo
pepasflo / bowling.py
Created August 29, 2018 23:35
Bowling scoring system
#!/usr/bin/env python
import sys
import json
# Safe access for lists.
def lget(l, i, default=None):
if len(l) <= i:
return default
else: