This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def async_wrap( | |
loop: Optional[asyncio.BaseEventLoop] = None, executor: Optional[Executor] = None | |
) -> Callable: | |
def _async_wrap(func: Callable) -> Callable: | |
@wraps(func) | |
async def run(*args, loop=loop, executor=executor, **kwargs): | |
if loop is None: | |
loop = asyncio.get_event_loop() | |
pfunc = partial(func, *args, **kwargs) | |
return await loop.run_in_executor(executor, pfunc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const spdy = require('spdy'); | |
const PORT = 8000; | |
const app = express(); | |
app.get('/', (_, res) => { | |
res.send('hello world'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Ratelimit } from '@upstash/ratelimit'; | |
import { Redis } from '@upstash/redis'; | |
import type { NextRequest, NextFetchEvent } from 'next/server'; | |
import { NextResponse } from 'next/server'; | |
type MiddlewareFactory = (middleware: NextMiddleware) => NextMiddleware; | |
export const withRateLimit: MiddlewareFactory = | |
next => async (request: NextRequest, _next: NextFetchEvent) => { | |
const url = process.env.UPSTASH_REDIS_REST_URL!; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bapk() # build android apk (Must run inside react-native project) | |
{ | |
apk_path="./android/app/build/outputs/apk/debug" | |
if [ ! -f package.json ]; then | |
echo "package.json was not found. Run command inside root dir of your project." | |
return 1 | |
fi | |
if ! grep --quiet '"react-native":' package.json; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import logging | |
import logging.handlers | |
try: | |
# Python 3.7 and newer, fast reentrant implementation | |
# without task tracking (not needed for that when logging) | |
from queue import SimpleQueue as Queue | |
except ImportError: | |
from queue import Queue | |
from typing import List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require('child_process'); | |
const pythonCode = `def hello_world(): | |
print("Hello, World!")`; | |
exec(`echo "${pythonCode}" | python -m flake8 -`, (error, stdout, stderr) => { | |
if (error) { | |
console.error(`exec error: ${error}`); | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from django.test import TestCase | |
def raise_nplusone_decorator(cls): | |
original_setup_class = getattr(cls, 'setUpClass') | |
original_teardown_class = getattr(cls, 'tearDownClass') | |
@classmethod | |
def new_setup_class(cls): | |
# Perform setup steps before the test class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
# Define a dictionary | |
my_dict = { | |
"foo": 1, | |
"bar": 2, | |
"baz": 3, | |
} | |
# Create an Enum class by passing the dictionary to the Enum constructor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
# define a sample function | |
def foo(): | |
try: | |
x = 1 / 0 | |
except ZeroDivisionError: | |
pass | |
# parse the function into an AST tree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
import compile | |
# define the source code | |
src = ''' | |
def foo(x): | |
return x + 1 | |
print(foo(1)) | |
''' |
NewerOlder