Skip to content

Instantly share code, notes, and snippets.

View potatowagon's full-sized avatar
🌈
http://www.biotele.com/qualia.htm

Sherry potatowagon

🌈
http://www.biotele.com/qualia.htm
View GitHub Profile
@potatowagon
potatowagon / int_float.py
Last active September 28, 2019 10:49
An implementation of python's int() and float()
import pytest
#============ PART 1: convert str to int ==============#
def map_char_to_int(char):
'''Maps char to int using a dict
Args:
char (str): a string representation of a digit eg. "1"
Raises:
@potatowagon
potatowagon / fib.py
Created September 29, 2019 17:08
Fibonacci sequence
import pytest
'''output nth (starting from 1) sequence of fibonacci series: 0,1,1,2,3,5,8. n = 7, output = 8'''
def fib(n):
seq = [0, 1] + [0] * (n - 2)
for i in range(2, n):
# dynamic programming
seq[i] = seq[i-1] + seq[i-2]
return seq[n-1]
@potatowagon
potatowagon / dist_install.md
Last active October 8, 2019 15:44
how does python decide where to install modules to?

TLDR:

os.path.join(sys.prefix, '/Lib/site-packages') on windows 

os.path.join(sys.prefix, '/Lib/site-packages') or os.path.join(sys.exec_prefix, '/Lib/site-packages') on unix

When run

setup.py install foo
@potatowagon
potatowagon / bold.py
Last active October 14, 2019 16:20
coding assessment question on glider. Given first input of substrings seperated by comma, bold the substrings in the second input, the main string. Combine the bolds if the substrings overlap or are consecutive.
import pytest
def escape_html(string):
char_map = {
"<" : "&lt",
">" : "&gt",
"&" : "&amp"
}
out = []
for char in string:

Stable vs unstable

stable: keys always remain in the same order after sorting equal values

Before:
key:0  1  2  3
   [3][0][2][2]
   
After:
key:0  1  2  3
 [0][2][2][3]
@potatowagon
potatowagon / pandas.md
Created November 7, 2019 09:29
Pandas
@potatowagon
potatowagon / setup.py
Last active November 8, 2019 22:37
setup.py template
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import re
def get_long_description():
''' use this if using readme for long description in pypi page'''
with open("README.md", "r") as fh:
readme = fh.read()
@potatowagon
potatowagon / rtfm.md
Last active April 6, 2020 00:09
RTFM?

RTFM?

RTFM? Really? We always expect other to do that, to read the readmes we painstakingly craft to be as detailed, concise and readable as possible. As a student, Ive even had that as a lecture topic before. However, reality is people dont RTFM as much as we ideally expect them to. People are lazy. Whats the solution to that?

Prompts

I realised this from working with others. Give them a repo. Theres a readme with detailed instructions. They try to run whats in the repo. They run into all sorts of problems: forgot to run with elevated rights, did not install so and so dependencies, etc. I give them the solution, then remind them that its in the README. This repeats. Very often. Maybe I'm not doing something right. The README alone prooves to not be the most effective and user friendly form of communicating information. Why do I have to repeatedly give manual prompts? Maybe this can be automated. OH YES! PROMPTS CAN BE AUTOMATED. Infact, when designing prompts to address help mes, we realise that pro

@potatowagon
potatowagon / halp-hhvm-composer.md
Last active April 14, 2020 03:26
Halp : hhvm composer install hangs with no output