Skip to content

Instantly share code, notes, and snippets.

View seanballais's full-sized avatar

Sean Francis N. Ballais seanballais

View GitHub Profile
@seanballais
seanballais / NOTES.txt
Last active March 25, 2020 09:57
Relevant Files for StackOverflow Question #60835314
- Entity is an alias to, at the moment, a size_t.
- Signature is an alias to an STL bitset.
@seanballais
seanballais / face_detection.py
Last active June 6, 2018 14:35
Facial Detection Test using face_recognition
# The image you will detect faces in must be named 'test.jpg' and
# must reside in the same directory where you placed this script.
#
# Resulting image, where the detected faces are drawn a white rectangle
# over, is saved in the same directory where you placed this script and
# has the file name, 'result.jpeg'.
from PIL import Image, ImageDraw
import face_recognition
import time
@seanballais
seanballais / whole_number_to_roman_numerals.py
Created May 17, 2018 03:45
Converts a whole number to roman numberals.
import sys
def main():
roman_numerals = {
0: '', 1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V',
6: 'VI', 7: 'VII', 8: 'VIII', 9: 'IX',
10: 'X', 20: 'XX', 30: 'XXX', 40: 'XL', 50: 'L',
60: 'LX', 70: 'LXX', 80: 'LXXX', 90: 'XC',
100: 'C', 200: 'CC', 300: 'CCC', 400: 'CD', 500: 'D',
if (some condition)
var x <- Reachable so I should create a binding to this variable x.
else <- Assume relatively unreachable.
var y <- Unreachable. But I can't be sure if it's reachable (prolly related to Halting Problem?).
So, I must create a binding so that the expressions that operate on y will run without an error and
to take into account cases that this branch is actually reached.
This seems like a waste of memory especially in large codebases.
var z <- Same as above with var y.
@seanballais
seanballais / semiprime_factors.py
Created April 28, 2018 14:29
Obtaining the Prime Factors of a Semiprime
import math
def obtain_pq(n):
p = 0.1
k = math.ceil(math.sqrt(n))
while not p.is_integer():
p = k - math.sqrt((k ** 2) - n)
k += 1
def pair_balance(parentheses):
missing_pairs = 0
for parenthesis in parentheses:
if parenthesis == '(':
missing_pairs += 1
elif parenthesis == ')':
if missing_pairs == 0:
return False
missing_pairs -= 1
@seanballais
seanballais / number_palindrome
Created February 7, 2018 13:09
Generates a number palindrome starting from 1 to a given length.
import sys
def horizontal_pyramid(current_value, limit):
if current_value == limit:
return str(current_value)
return str(current_value) + horizontal_pyramid(current_value + 1, limit) + str(current_value)
print(horizontal_pyramid(1, int(sys.argv[1])))
@seanballais
seanballais / HappyIndependenceDay.bf
Created July 29, 2015 13:34
Prints "Happy Independence Day!"
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set cell #1 to 60
> +++++ + add 6 to cell #1 (Capital letters)
> +++++ ++++ add 9 to cell #2 (Lowercase letters)
> +++ add 2 to cell #3 to represent space
> + add 1 to cell #4 to represent a new line
<<<< - decrement counter (cell #0)
]
>>>> . go to cell #4 and print a new line
def main():
numberOfBottles = 99
while numberOfBottles != 0:
firstVerseLine = getFirstOrLastLine(numberOfBottles)
print(firstVerseLine)
print(firstVerseLine + ", take one down pass it around.")
numberOfBottles = numberOfBottles - 1