Skip to content

Instantly share code, notes, and snippets.

View devxoul's full-sized avatar
👨‍💻
Always coding

Suyeol Jeon devxoul

👨‍💻
Always coding
View GitHub Profile
@devxoul
devxoul / delete_lambda_function_revisions.py
Created March 29, 2023 19:38
Delete AWS Lambda function revisions in parallel
import asyncio
import subprocess
import time
from asgiref.sync import sync_to_async
async def delete_revision(function_name, revision):
cmd = f"aws lambda delete-function --function-name {function_name}:{revision}"
print(cmd)
@devxoul
devxoul / hashid_num.py
Created February 24, 2023 18:04
Find how many numbers Hashids can cover within the minimum length.
import sys
from math import ceil, floor
from hashids import Hashids
target_length = 8
hashids = Hashids(min_length=target_length)
print(f"target_length={target_length}")
@devxoul
devxoul / fastapi_camel.py
Created February 4, 2023 13:48
Camelize FastAPI path params and query params.
"""
Camelize FastAPI path params and query params.
For body params and responses, use pydantic model's alias_generator config.
"""
from fastapi import FastAPI
from fastapi.dependencies.models import Dependant
from fastapi.routing import APIRoute
from humps import camelize
@devxoul
devxoul / partial.py
Last active February 3, 2023 11:27
Pydantic Partial Model
from copy import copy
from typing import Generic, Optional, TypeVar, get_args, get_type_hints
from pydantic import BaseModel
from pydantic.errors import ConfigError
from pydantic.typing import convert_generics
T = TypeVar('T', bound=BaseModel)
const getFileFromURL = async (url: string): Promise<File> => {
const result = await fetch(url)
const buffer = await result.arrayBuffer()
const blob = new Blob([buffer])
const file = new File([blob], url.split('/')[1])
return file
}
// Usage
const someFile: File
- node_modules/metro/src/node-haste/DependencyGraph/assets/empty-module.js
+ ../MyApp/node_modules/metro/src/node-haste/DependencyGraph/assets/empty-module.js
_getFileData(file) {
const relativePath = fastPath.relative(this._rootDir, file);
+ if (file.endsWith('node_modules/metro/src/node-haste/DependencyGraph/assets/empty-module.js')) {
+ console.log('rootDir:', this._rootDir);
+ console.log('file:', file);
+ console.log('relativePath:', relativePath);
+ }
return this._files.get(relativePath);
}
@devxoul
devxoul / ApolloMockedProviderDynamicVariables.tsx
Last active February 23, 2021 09:11
Use expect matcher in Apollo MockedProvider variables
jest.mock('@wry/equality', () => ({
equal: (lhs: any, rhs: any) => {
const equals = require('expect/build/jasmineUtils').equals(lhs, rhs)
return equals || jest.requireActual('@wry/equality').equal(lhs, rhs)
}
}))
const mocks = [
{
@devxoul
devxoul / Spy.ts
Created February 12, 2021 12:24
Jest Spy type
type Spy<T extends {}, M extends jest.FunctionPropertyNames<Required<T>>> = Required<T>[M] extends (...args: any[]) => any
? jest.SpyInstance<ReturnType<Required<T>[M]>, jest.ArgsType<Required<T>[M]>>
: never;
@devxoul
devxoul / nonnull_connection.py
Created December 18, 2020 07:18
Graphene NonNullConnection
class NonNullConnection(graphene.relay.Connection):
class Meta:
abstract = True
@classmethod
def __init_subclass_with_meta__(cls, node=None, **options):
if node is not None and not isinstance(node, graphene.NonNull):
node = graphene.NonNull(node)
super(NonNullConnection, cls).__init_subclass_with_meta__(