Skip to content

Instantly share code, notes, and snippets.

View nmchenry01's full-sized avatar

Nicholas McHenry nmchenry01

  • Boulder, CO
View GitHub Profile
@nmchenry01
nmchenry01 / sqlalchemy_1.py
Created November 23, 2021 20:13
A synchronous SQLAlchemy example
from sqlalchemy import create_engine, Column, Integer, String, select
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# Create database schema
Base = declarative_base()
class Task(Base):
__tablename__ = "task"
task_id = Column(Integer, primary_key=True)
title = Column(String)
@nmchenry01
nmchenry01 / coroutine_5.py
Last active November 23, 2021 20:12
Running multiple coroutines concurrently
import asyncio
import time
async def me_first():
await asyncio.sleep(1)
return "I'm first!"
@nmchenry01
nmchenry01 / coroutine_4.py
Last active November 23, 2021 20:11
Running multiple coroutines sequentially
import asyncio
import time
async def me_first():
await asyncio.sleep(1)
return "I'm first!"
async def me_second():
await asyncio.sleep(1)
@nmchenry01
nmchenry01 / coroutine_3.py
Last active November 23, 2021 20:08
A working example of running a coroutine
import asyncio
async def something_async():
# Wait 3 seconds
await asyncio.sleep(3)
return "Now we're cooking with fire!"
async def main():
result = await something_async()
@nmchenry01
nmchenry01 / coroutine_2.py
Last active November 23, 2021 20:09
A second example of creating and printing a coroutine
import asyncio
async def something_async():
# Wait 3 seconds
await asyncio.sleep(3)
return "I'm async (sortof) now!"
def main():
result = something_async()
@nmchenry01
nmchenry01 / coroutine_1.py
Last active November 23, 2021 20:09
An example of creating and printing a coroutine
from pprint import pprint
async def something_async():
return "I'm not really async!"
def main():
coroutine = something_async()
print(f"{coroutine}\n")
pprint(dir(coroutine))
@nmchenry01
nmchenry01 / launch.json
Last active August 31, 2020 21:31
Jest debug configuraiton "Debugging NestJS with VSCode"
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"--coverage",
"false"
@nmchenry01
nmchenry01 / nodemon-debug.json
Created August 31, 2020 11:37
Nodemon debug configuration "Debugging NestJS with VSCode"
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register src/main.ts "
}
@nmchenry01
nmchenry01 / launch.json
Created August 31, 2020 10:56
Launch configuration for NestJS for "Debugging NestJS with VSCode"
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"args": [
"${workspaceFolder}/src/main.ts"
],
@nmchenry01
nmchenry01 / nest-cli.json
Created August 25, 2020 15:05
NestJS CLI Swagger plugin "NestJS with Swagger"
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": ["@nestjs/swagger/plugin"]
}
}