Skip to content

Instantly share code, notes, and snippets.

View fabiosussetto's full-sized avatar

Fabio Sussetto fabiosussetto

View GitHub Profile
{
"info": {
"_postman_id": "ec-storefront-checkout-seatsio",
"name": "Eventcube Storefront API — Checkout Fields & Seats.io",
"description": "Storefront API (`/api/v1`) endpoints added/extended on this branch:\n\n- **Checkout fields** — CRUD for custom checkout questions\n- **Cart custom fields** — resolved on `GET /carts/{id}` for checkout UX\n- **Seats.io** — event config, cart seat holds, seat selections, order booking\n\n## Setup\n1. Set collection variables `store_domain` and `api_key`.\n2. `base_url` defaults to `http://{{store_domain}}/api/v1`.\n3. Run folders top-to-bottom; scripts save `event_id`, `ticket_id`, `cart_id`, etc.\n\n**Auth:** Bearer token (`store.api_key`). Requests resolve the store from the domain in `base_url`.\n\n**Note:** Store must have Seats.io connected (admin: store `seatsio` meta) before reserved seating works.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"auth": {
"type": "bearer",
"bearer": [
set -x
set -e
PREVIOUS_CONTAINER=$(docker ps --format "table {{.ID}} {{.Names}} {{.CreatedAt}}" | grep web | awk -F " " '{print $1}')
docker-compose up -d --no-deps --scale web=2 --no-recreate web
sleep 30
docker kill -s SIGTERM $PREVIOUS_CONTAINER
sleep 1
docker rm -f $PREVIOUS_CONTAINER
docker-compose up -d --no-deps --scale web=1 --no-recreate web
package main
import (
"fmt"
"math/rand"
"os"
"os/signal"
"sync"
"syscall"
"time"
select to_json(a)
from (
select d1.*,
(
select to_json(t) from
(select * from document d2
where type = 'author'
and d2.id = (d1.body->>'author_id')::int
) t
@fabiosussetto
fabiosussetto / pg_experiments.sql
Last active June 21, 2018 16:21
pg_experiments.sql
-- my table is called 'document', is has a type (text) and a document (jsonb) colum
select d1.*,
(
select to_json(t) from
(select * from document d2
where type = 'author'
and d2.id = (d1.body->>'author_id')::int
) t
@fabiosussetto
fabiosussetto / json_norm_query.py
Last active November 30, 2017 11:42
json_norm_query.py
answer_options_table = Q()\
.tables(ModuleAnswerOption.s)\
.fields(ModuleAnswerOption.s.pk, ModuleAnswerOption.s.answer, ModuleAnswerOption.s.is_correct) \
.where(ModuleAnswerOption.s.question == ModuleQuestion.s.pk)\
.as_table('g')
answer_options_json_q = Q() \
.tables(answer_options_table) \
.fields(func.json_agg(answer_options_table).as_('options'))
from sqlbuilder.smartsql.expressions import func
from sqlbuilder.smartsql import Q
from core.models import AppLicenseGroup, AppLicenseGroupUser
from core.utils.db import fetch_many, fetch_one, norm_sum
from itrain.models import ModuleResponse, Module, ModuleAssignee
def fetch_average_to_complete(company_id, start_date, end_date):
company_filter = Module.s.company_id == company_id
from sqlbuilder.smartsql.expressions import func
from sqlbuilder.smartsql import Q
from core.models import AppLicenseGroup, AppLicenseGroupUser
from core.utils.db import fetch_many, fetch_one, norm_sum
from itrain.models import ModuleResponse, Module, ModuleAssignee
def fetch_average_to_complete(company_id, start_date, end_date):
company_filter = Module.s.company_id == company_id
joins = (Sale.s & Product.s).on(Sale.s.product == Product.s.pk)
where = (Product.s.company_id == company_id) & \
(Sale.s.created_at.between(func.date(start_date), func.date(end_date)))
inner_table = Q()\
.tables(
(joins + CategoryAssignment.s).on(CategoryAssignment.s.product == Product.s.pk)
)\
.fields(
{
"tot": 1,
"date": "2017-09-08",
"category_id": 3,
"name": "Uniform Issues"
},
{
"tot": 1,
"date": "2017-09-06",
"category_id": 3,