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 / gist:34cd27959a74540a1a9fc9e74cb7b253
Created March 7, 2018 00:12
Arduino sketch for spelling out "S.O.S." in morse code
int led_pin = 13;
void setup() {
pinMode(led_pin, OUTPUT);
}
int dit_high = 60;
int dit_low = 120;
int dash_high = 120;
@pepasflo
pepasflo / fade.ino
Created March 7, 2018 00:37
An Arduino sketch which fades an LED in and out.
int led_pin = 13;
void setup() {
pinMode(led_pin, OUTPUT);
}
void loop() {
int on_time;
int off_time;
@pepasflo
pepasflo / Makefile
Created April 27, 2018 16:38
Given an array of random numbers, Push all the zero's of a given array to the end of the array. For example, if the given arrays is {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0}, it should be changed to {1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0}. The order of all other elements should be same. Expected time complexity is O(n) and extra space is O(1).
push-zeros: push-zeros.c
gcc -Wall -Werror -o push-zeros push-zeros.c
test: push-zeros
./push-zeros
clean:
rm -f push-zeros
.PHONY: test clean
test: hical
./hical
hical: hical.c
gcc -Wall -Werror -o hical hical.c
clean:
rm -f hical
.PHONY: test clean
@pepasflo
pepasflo / Makefile
Created June 27, 2018 00:34
"Matching parens" problem from interview cake, see https://www.interviewcake.com/question/python/matching-parens
test: paren
./paren
paren: paren.c
gcc -Wall -Werror -o paren paren.c
clean:
rm -f paren
.PHONY: test paren
@pepasflo
pepasflo / parse.py
Last active July 21, 2018 00:05
Python script which parses HTML, looks for a specific iframe, and replaces it with a div. Oops, this only works properly on XHTML.
#!/usr/bin/env python
# read in the HTML via stdin:
import sys
input = sys.stdin.read()
# define the set of toknes which our lexer knows about:
import re
symbol_table = (
("opentag", re.compile(r'<[a-zA-Z].*?>')),
@pepasflo
pepasflo / meta.swift
Created August 3, 2018 18:26
I can store the type of an object in a dictionary, but I can't seem to match against it in a switch statement. Halp?
var dict: Dictionary<String, Any> = ["window.rootViewController": UIViewController.self]
switch dict["window.rootViewController"] {
// Expression pattern of type 'UIViewController.Type' cannot match values of type 'Any'
case .some(UIViewController.self):
print("yay!")
default:
print("boo!")
}
test: reverse
./reverse
reverse: reverse.c
gcc -Wall -Werror -o reverse reverse.c
clean:
rm -f reverse
.PHONY: test reverse
@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:
@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