Skip to content

Instantly share code, notes, and snippets.

View zspine's full-sized avatar
🎯
Focusing

M#3 zspine

🎯
Focusing
View GitHub Profile
@zspine
zspine / fastapi-magic.py
Last active November 10, 2023 02:16
Detecting File Mime Types in FastAPI Using the Python Magic Library
"""
Using `magic` library to detect the MIME type of uploaded files.
"""
from typing import Annotated
from fastapi import FastAPI, File, UploadFile, APIRouter
import magic
app = FastAPI()
@zspine
zspine / QuasarStripeJs.vue
Last active May 8, 2022 01:40
Stripe integration with quasar (vue), uses custom form elements and error messages with quasar q-field
<template>
<div id="payment-form">
<div class="q-mt-md q-mb-md text-negative" v-if="submissionError">
<div id="card-errors" role="alert">{{ submissionError }}</div>
</div>
<q-field label="Card Number"
stack-label
class="q-mb-md"
@zspine
zspine / docker-compose.sh
Last active August 11, 2020 12:52
Frequently used fullstack developer commands
# DOCKER COMPOSE
####################################################################
docker-compose exec {CONTAINER_ID} sh
@zspine
zspine / Money.php
Created April 10, 2020 10:23
Doctrine brick money value object
<?php
namespace App\Entity\Embeddable;
use App\Model\Intl\MoneyInterface;
use Brick\Math\BigNumber;
use Brick\Math\Exception\NumberFormatException;
use Brick\Math\RoundingMode;
use Brick\Money\Context\CustomContext;
use Doctrine\ORM\Mapping as ORM;
@zspine
zspine / .env
Created October 4, 2019 12:34
API Platform json_login with separate domain SPA
APP_COOKIE_DOMAIN=.example.test
CORS_ALLOW_ORIGIN=^https?://app.example.test(:[0-9]+)?$
@zspine
zspine / Account.php
Created September 25, 2019 13:31
Symfony User Management
<?php
namespace App\Entity;
use App\Model\Account\MembershipInterface;
use App\Model\Resource\TimestampableTrait;
use App\Model\Resource\ToggleableTrait;
use App\Model\Resource\UuidTrait;
use App\Model\User\UserInterface;
use Doctrine\Common\Collections\Collection;
@zspine
zspine / SuperAdminGroupContextBuilder.php
Last active March 23, 2023 08:46
API Platform custom ContextBuilder and Denormalizer
<?php
namespace App\Serializer\ApiPlatform;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use App\Entity\User;
@zspine
zspine / rabbitmq-ubuntu-16.04.sh
Created April 29, 2019 09:13
Quick Install RabbitMQ Server on Ubuntu 16.04
sudo apt-get update
sudo apt-get upgrade
#Instruct apt to trust packages signed by rabbitmq signing key
wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add -
#Enable apt HTTPS Transport
sudo apt-get install apt-transport-https
#Add the apt repository to the source list directory
from twisted.internet import defer, reactor
from jasmin.vendor.smpp.pdu.operations import DeliverSM
from jasmin.queues.configs import AmqpConfig
from jasmin.queues.factory import AmqpFactory
from jasmin.routing.jasminApi import SmppServerSystemIdConnector
from jasmin.routing.content import RoutedDeliverSmContent
from jasmin.queues.test.test_amqp import waitFor
@defer.inlineCallbacks
def connect_and_publish(pdu, dc):
"""Convert submit_sm to deliver_sm and reinject it back in rabbitmq
as coming from connector's CID same as submit_sm's uid
Design is diagrammed here: https://sketchboard.me/nAvXcoQqcbIt#/"""
import cPickle as pickle
import logging
import uuid
import pika
from datetime import datetime