Skip to content

Instantly share code, notes, and snippets.

def profile(func):
from functools import wraps
@wraps(func)
def wrapper(*args, **kwargs):
from line_profiler import LineProfiler
prof = LineProfiler()
try:
return prof(func)(*args, **kwargs)
finally:
profiler = cProfile.Profile()
profiler.enable()
main()
profiler.disable()
stats = pstats.Stats(profiler).sort_stats('tottime')
stats.print_stats()
def square_my_num():
universe = np.arange(100000)
numbers = np.random.rand(100000)
filtered_nums=[]
for number in numbers:
if number in universe:
filtered_nums.append(number)
@CrimsonScythe
CrimsonScythe / calc.c
Last active September 21, 2022 07:03
#include <stdio.h>
#include <time.h>
#define INTERVALS 10000000
double a[INTERVALS], b[INTERVALS];
int main(int argc, char **argv)
{
double time2;
/* COPYING:
* Dave Patterson at UCB modified this code from a program by Andrea
* Dusseau of U.C. Berkeley,which was based on a description in
* Saavedra-Barrera [1992]:
* Saavedra-Barrera, R. H. [1992]. CPU Performance Evaluation and
* Execution Time Prediction Using Narrow Spectrum Benchmarking,
* Ph.D. Dissertation, University of Calif., Berkeley (May).
* Patterson has given permission to use and modify this code as long
* as these people and the U. of Cal., Berkeley get proper credit.
*/
import json
from constructs import Construct
from aws_cdk import (
Stack,
aws_ecs as ecs,
aws_ecs_patterns,
aws_rds as rds,
aws_ec2 as ec2,
aws_secretsmanager as secretsmanager
)
#!/usr/bin/env python3
import aws_cdk as cdk
import os
from ecs.ecs_stack import EcsStack
app = cdk.App()
EcsStack(app, "ecs", env={"region": "eu-central-1", "account": os.environ['CDK_DEFAULT_ACCOUNT']})
app.synth()
services:
server:
build: .
command: uvicorn main:app --reload --host 0.0.0.0
volumes:
- .:/app
ports:
- 8000:8000
environment:
# Dockerfile
# pull the official docker image
FROM python:3.9
# set work directory
WORKDIR /app
# install dependencies
from pydantic import BaseModel
class Book(BaseModel):
name: str
author: str
class Config:
orm_mode = True