Skip to content

Instantly share code, notes, and snippets.

View fabiosussetto's full-sized avatar

Fabio Sussetto fabiosussetto

View GitHub Profile
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,
import { when, reaction } from "mobx";
import { types, getParent, getRoot, getSnapshot, applySnapshot } from "mobx-state-tree";
import uuid from 'uuid/v4'
import request from '../api'
const AuthStore = types.model(
'AuthStore',
{
token: '',
isLoading: false