See http://blog.pamelafox.org/2022/08/porting-project-from-spaces-to-tabs.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"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}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |