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 / 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 / .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 / 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 / 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 / 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
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 / README.md
Created November 7, 2018 00:30
Updated lexers
@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 / c_output.txt
Last active November 15, 2018 17:22
programming puzzle: matching parens.
$ gcc -O3 -std=c99 -Wall parens.c
$ ./a.out parens-tests/100k.txt
answer: 1
elapsed time: 13.773000ms
$ ./a.out parens-tests/1million.txt
answer: 1
elapsed time: 125.703000ms
@pepasflo
pepasflo / C char frequency (Linux kernel)
Last active November 28, 2018 23:19
Find the frequency of characters in Swift source files.
./charfreq.py c linux-4.19.5
' ' 9.38%
e 5.59%
t 4.79%
_ 4.57%
\t 4.30%
r 3.82%
\n 3.68%
i 3.64%
s 3.41%