Skip to content

Instantly share code, notes, and snippets.

View bay007's full-sized avatar
🏠
Working from home

egalicia bay007

🏠
Working from home
View GitHub Profile
@bay007
bay007 / app.module.ts
Created January 22, 2024 09:55 — forked from mafalt/app.module.ts
NestJS + TypeORM configuration
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getTypeOrmModuleOptions } from './config/orm.config';
import { CoreModule } from './core/core.module';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
@bay007
bay007 / check_db_connection-php
Created January 20, 2024 08:47
Check database php connection
try {
\DB::connection()->getPDO();
echo \DB::connection()->getDatabaseName();
} catch (\Exception $e) {
echo 'None';
}
@bay007
bay007 / bootstrap-sail.sh
Created June 15, 2023 11:10 — forked from njbair/bootstrap-sail.sh
Install Laravel Sail into an existing project without PHP & Composer
#!/bin/sh
# Installs Laravel Sail into an existing project
# The official Laravel Sail docs[1] provide instructions for installing Sail
# into an existing PHP application. But the official method requires invoking
# Composer locally. Part of Sail's appeal is that it removes the need to
# install PHP on your host machine.
# This script is lifted from laravel.build[2], and thus uses the same method
@bay007
bay007 / gist:ed7e35e3e70f2f1f33ade15ad35ac2c6
Created August 22, 2020 16:20 — forked from simonw/gist:7000493
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
from collections import OrderedDict
from rest_framework.response import Response
from rest_framework.exceptions import ErrorDetail
class ErrorResponse:
def __init__(self, error: list) -> None:
self.__error = error
@property
@bay007
bay007 / get_next_primary_key.py
Created August 16, 2020 06:31 — forked from kissgyorgy/get_next_primary_key.py
Django: Get next primary key for object.
from djangobb_forum.models import Post
from django.db.models import Max
# id__max is None if there are no Posts in the database
id_max = Post.objects.all().aggregate(Max('id'))['id__max']
id_next = id_max + 1 if id_max else 1
## TDD good habits manifesto
#### (principles)
- tests should test one thing only
- test one logical assertion
- don't mix assertions of state and collaboration in the same test
- modifications of production code should only break related test cases
- each test should be self-contained, including data
- ensure tests are independent of each other
- don't refactor with a failing test

Intro to Advanced Python

By Adam Anderson

adam.b.anderson.96@gmail.com

These notes are mostly just summaries of the provided references. The purpose of this document is to centralize the resources I found useful so they would be easy to find. Most definitions and explanations are paraphrased or quoted directly from the sources.

Table of Contents

@bay007
bay007 / killgunicorn.sh
Created January 7, 2020 01:36 — forked from jvorcak/killgunicorn.sh
Kill gunicorn with all of the workers
alias killgunicorn="ps aux | grep gunicorn | awk '{print $2;}' | xargs kill -9 2>/dev/null"