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 socket | |
import threading | |
# define the host and port for the chat server | |
HOST = 'localhost' | |
PORT = 12345 | |
# create a new socket for the chat server | |
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
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 typing import TypedDict | |
# Define a regular dictionary | |
my_dict = { | |
"foo": 1, | |
"bar": "hello", | |
"baz": True, | |
} | |
# Create a TypedDict class by passing the dictionary keys and their corresponding types to the TypedDict 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
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const WorkerPlugin = require('worker-plugin'); | |
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin"); | |
const smp = new SpeedMeasurePlugin(); | |
const Dotenv = require('dotenv-webpack'); | |
const TerserPlugin = require("terser-webpack-plugin"); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({ | |
template: __dirname + '/public/index.html', |
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 * as nodemailer from 'nodemailer'; | |
import * as fs from 'fs'; | |
import handlebars from 'handlebars'; | |
import Mail from 'nodemailer/lib/mailer'; | |
type EmailClientArgs<TemplateData> = { | |
to: string; | |
subject: string; | |
templatePath: string; | |
templateData: TemplateData; |
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 multiprocessing import Manager | |
class ContextLock: | |
def __init__(self) -> None: | |
self.manager = Manager() | |
self.lock = self.manager.Lock() | |
def __enter__(self) -> bool: |
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
declare module 'express-session' { | |
export interface SessionData { | |
userName: string; | |
} | |
} |
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 { cookies, headers } from 'next/headers'; | |
import { createServerComponentSupabaseClient } from '@supabase/auth-helpers-nextjs'; | |
const supabase = createServerComponentSupabaseClient({ | |
supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL, | |
supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, | |
headers, | |
cookies | |
}); |
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
# Add Logging to specific data | |
from django.contrib.admin.models import CHANGE, LogEntry | |
from django.contrib.contenttypes.models import ContentType | |
LogEntry.objects.log_action( | |
user_id=request.user.id, | |
content_type_id=ContentType.objects.get_for_model(self.model).pk, | |
object_id=object_id, | |
object_repr=object_id, |
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
# ref: https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-instance-methods-release-object | |
import functools | |
import weakref | |
def memoized_method(*lru_args, **lru_kwargs): | |
def decorator(func): | |
@functools.wraps(func) | |
def wrapped_func(self, *args, **kwargs): | |
# We're storing the wrapped method inside the instance. If we had |
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
<?php | |
$start = '2022-07-10'; | |
$end = '2022-07-12'; | |
function randomDate($start_date, $end_date) | |
{ | |
// Convert to timetamps | |
$min = strtotime($start_date); | |
$max = strtotime($end_date); |