본문 바로가기

나는 이렇게 학습한다575

JavaScript _ 콜백 함수를 알아보자 들어가며 자바스크립트에서 비동기 프로그래밍의 기초 개념 중 하나인 콜백 함수에 대해 알아보자. 본 글에서는 콜백 함수의 개념부터 동기 콜백과 비동기 콜백의 차이, 콜백 지옥과 한계, 그리고 콜백 함수 작성 팁까지 다루겠다. 또한 콜백 함수의 대안으로 선호되는 프로미스와 async/await에 대해서도 간략하게 소개하겠다. 콜백 함수란? 콜백 함수란 다른 함수에 인자로 전달되어, 어떤 작업이 완료된 후에 실행되는 함수이다. 콜백 함수는 자바스크립트에서 흔히 사용되는 패턴으로, 특히 비동기 작업을 처리할 때 유용하다. 비동기 작업이란, 작업의 실행과 완료 시점이 일치하지 않는 작업을 말하는데, 예를 들어 서버에서 데이터를 가져오는 작업이나 타이머를 사용한 작업 등이 비동기로 이루어질 수 있다. 콜백 함수의 .. 2023. 5. 9.
SQLAlchemy _ ForeignKey 로 연결된 개체 한 번에 삭제하기 SQLAlchemy에서는 cascading 옵션을 활용하여 관계된 개체(Entity)를 한 번에 삭제할 수 있다. 방법 1. 부모 relationship 에서 cascade 매개변수 지정 두 테이블 간의 관계를 정의할 때, 상위 개체와 하위 개체가 함께 삭제되도록 cascade 매개변수를 지정할 수 있다. from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy.orm import relationship class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) children = relationship('Child', cascade='delete') .. 2023. 3. 24.
SQLAlchemy _ ForeignKey 필드에 name 을 넣어주어야 Alembic 이 downgrade 해줌 한 줄 요약 *ForeignKey 필드에 name을 넣어주어야 *Alembic 이 *downgrade 해줌. *ForeignKey 필드는 다른 테이블의 기본 키를 참조하는 테이블 필드를 의미함 *Alembic은 Python용 데이터베이스 마이그레이션 도구임 *downgrade는 이전 version으로 되돌리는 것을 의미함 문제상황 부모 record 를 지우면 자식 record 도 지워지도록, 자식 parent_id 필드에 ondelete="CASCADE" 옵션을 추가했다. class Child(Base): __tablename__ = "child" id = sa.Column(UUID(as_uuid=True), primary_key=True) parent_id = sa.Column( UUID(as_uuid.. 2023. 3. 23.
0212. Reversed sequence Build a function that returns an array of integers from n to 1 where n>0. Example : n=5 --> [5,4,3,2,1] Solution: reverse_seq = lambda n: sorted(range(1, n+1), reverse=True) def reverseseq(n): return list(range(n, 0, -1)) 2023. 2. 13.
0211. Remove duplicates from list Define a function that removes duplicates from an array of numbers and returns it as a result. The order of the sequence has to stay the same. Solution: def distinct(seq: list[int]) -> list[int]: result = [] for i in seq: if i not in result: result.append(i) return result def distinct(seq: list[int]) -> list[int]: return sorted(set(seq), key=seq.index) def distinct(seq: list[int]) -> list[int]: .. 2023. 2. 12.
0210. Is it a number? Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not. Valid examples, should return true: isDigit("3") isDigit(" 3 ") isDigit("-3.23") should return false: isDigit("3-4") isDigit(" 3 5") isDigit("3 5") isDigit("zero") Solution: def isDigit(string: str) -> bool: return string.strip().lstrip("-").replace(".", "").isd.. 2023. 2. 10.