Skip to content

Instantly share code, notes, and snippets.

@m0xb
m0xb / cli.md
Created October 11, 2017 16:30

Consider the difference between:

  1. Bash command to run a Python script which takes multiple file name arguments:
python script.py file1.txt file2.txt file3.txt
  1. Bash command which runs a Python script multiple times:
$ cat countdown_recursive_debug.py
def countdown(n):
print(f"DEBUG: enter countdown({n})")
print(n)
if n > 1:
countdown(n - 1)
print(f"DEBUG: exit countdown({n})")
countdown(5)
$ cat countdown_iterative.py
def countdown(n):
while n > 0:
print(n)
n -= 1
countdown(5)
$ python3 countdown_iterative.py
5
$ cat countdown_recursive.py
def countdown(n):
print(n)
if n > 1:
countdown(n - 1)
countdown(5)
$ python3 countdown_recursive.py
5
[
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
$ python quiz.py
Birdman (film)
What year was Birdman released?
A. 2015
B. 2014
C. 2000
D. 1978
Enter Answer(s): ab
@m0xb
m0xb / decode.py
Created September 18, 2017 05:57
import json
class ObjectEncoder(json.JSONEncoder):
def default(self, o):
return o.__dict__
class Address:
class QuestionA:
def __init__(self, question_dict):
self.question_dict = question_dict
class QuestionB:
def __init__(self, question_text, answer_dict):
self.question_text = question_text
self.answer_dict = answer_dict
from sqlalchemy import Table, MetaData, Column, Integer, String, ForeignKey, Date, DateTime, Numeric, Interval, Text
from sqlalchemy.orm import mapper
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pathlib import Path
import sqlite3
metadata = MetaData()
credit_card_offer = Table('credit_card_offer', metadata,