Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / opcodes_parser.py
Created February 20, 2023 00:21
Parse opcodes
opcode_links = {}
file = open("Include/patchlevel.h", "r")
for line in file.readlines():
if line.startswith("#define PY_VERSION"):
full_version = line.split()[2].strip('"')
major_version = full_version.rsplit(".", 1)[0]
break
file.close()
@pamelafox
pamelafox / country_capitals.json
Last active March 29, 2023 12:25
country_capitals.json
[{"id":"AD","country":"Andorra","capital":"Andorra la Vella","lat":42.5063174,"lng":1.5218355},
{"id":"AF","country":"Afghanistan","capital":"Kabul","lat":34.5553494,"lng":69.207486},
{"id":"AG","country":"Antigua and Barbuda","capital":"St. John's","lat":17.1274104,"lng":-61.846772},
{"id":"AL","country":"Albania","capital":"Tirana","lat":41.3275459,"lng":19.8186982},
{"id":"AM","country":"Armenia","capital":"Yerevan","lat":40.1872023,"lng":44.515209},
{"id":"AO","country":"Angola","capital":"Luanda","lat":-8.8146556,"lng":13.2301756},
{"id":"AR","country":"Argentina","capital":"Buenos Aires","lat":-34.6036844,"lng":-58.3815591},
{"id":"AT","country":"Austria","capital":"Vienna","lat":48.2081743,"lng":16.3738189},
{"id":"AU","country":"Australia","capital":"Canberra","lat":-35.2801903,"lng":149.1310038},
{"id":"AZ","country":"Azerbaijan","capital":"Baku","lat":40.4092617,"lng":49.8670924},
@pamelafox
pamelafox / calc_bnf_part1.py
Created April 22, 2022 05:43
BNF-based Calculator interpreter, 3 ways
# A Simple Calculator Using Scheme Syntax.
# Implemented using the Lark package in Python.
import sys
from lark import Lark
grammar = """
?start: calc_expr
?calc_expr : NUMBER | calc_op
@pamelafox
pamelafox / animals.sql
Created November 22, 2021 21:11
Animals SQL
CREATE TABLE animals (name TEXT, legs INTEGER, weight INTEGER);
INSERT INTO animals VALUES ("dog", 4, 20);
INSERT INTO animals VALUES ("cat", 4, 10);
INSERT INTO animals VALUES ("ferret", 4, 10);
INSERT INTO animals VALUES ("parrot", 2, 6);
INSERT INTO animals VALUES ("penguin", 2, 10);
INSERT INTO animals VALUES ("t-rex", 2, 12000);
@pamelafox
pamelafox / songs.sql
Created November 17, 2021 20:50
pamela's favorite songs SQL
CREATE TABLE songs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
artist TEXT,
title TEXT,
release_year INTEGER,
views NUMERIC
);
INSERT INTO songs (artist, title, release_year, views)
VALUES ("Lil Nas X", "Old Town Road", 2018, 851);
@pamelafox
pamelafox / compiled_slide.html
Created November 8, 2021 04:10
compiled_slide.html
<section>
<h3>Compiled vs. interpreted</h3>
<p class="padded">When a program is <strong>compiled</strong>, the source code is translated into machine code,
and that code can be distributed and run repeatedly.</p>
<p class="smaller"><code>Source code → Compiler → Machine code → Output</code></p>
<p>When a program is <strong>interpreted</strong>, an interpreter
runs the source code directly (without compiling it first).</p>
<p class="smaller"><code>Source code → Interpreter → Output</code></p>
@pamelafox
pamelafox / edit_post_autosave.html.erb
Created September 28, 2021 20:18
Auto-saving Rails form example
<!-- Auto-saving for Rails blog example -->
<h1>Editing Post</h1>
<p>Last saved:
<span id="last-saved-display" data-last-saved="<%= @post.updated_at.iso8601 %>">
</span>
<span id="save-status">
</span>
</p>
@pamelafox
pamelafox / funky_case.py
Created September 24, 2021 05:59
fUnkyCaSe
def fUnKyCaSe(text):
"""Returns TEXT in fUnKyCaSe
>>> fUnKyCaSe("wats up")
'wAtS Up'
"""
def toggle_case(letter, should_up_case):
return letter.upper() if should_up_case else letter.lower()
def up_down(text, should_up_case):
if len(text) == 1:
@pamelafox
pamelafox / prime_factors.py
Created August 30, 2021 19:51
Prime Factors
def is_prime(n):
"""Return True iff N is prime.
>>> is_prime(1)
False
>>> is_prime(2)
True
>>> is_prime(8)
False
>>> is_prime(21)
False