Skip to content

Instantly share code, notes, and snippets.

@mazz
mazz / sqlalchemy.py
Created February 25, 2018 01:57
sqlalchemy many-to-many query examples
## every leader at every church -- OK
##
##
## query = dbsession.query(Leader).join(LeaderChurch).join(Church).filter(LeaderChurch.leader_id == Leader.id and LeaderChurch.church_id == Church.id)
## every leader at a particular church -- OK
##
##
# query = dbsession.query(Leader). \
@mazz
mazz / ChatCollectionViewFlowLayout.swift
Created February 21, 2018 02:26 — forked from jochenschoellig/ChatCollectionViewFlowLayout.swift
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
@mazz
mazz / Flexible Dockerized Phoenix Deployments.md
Created February 16, 2018 17:16 — forked from jswny/Flexible Dockerized Phoenix Deployments.md
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

fatal: [kjvrvg_production]: FAILED! => {"changed": true, "cmd": ["/srv/pyramid/kjvrvg/venv/bin/ws-alembic", "-c", "/srv/pyramid/kjvrvg/faithfulaudio/kjvrvg/conf/generated.ini", "upgrade", "head"], "delta": "0:00:01.357724", "end": "2017-12-06 03:30:09.818628", "failed": true, "invocation": {"module_args": {"_raw_params": "/srv/pyramid/kjvrvg/venv/bin/ws-alembic -c /srv/pyramid/kjvrvg/faithfulaudio/kjvrvg/conf/generated.ini upgrade head", "_uses_shell": false, "chdir": "/srv/pyramid/kjvrvg", "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2017-12-06 03:30:08.460904", "stderr": "Traceback (most recent call last): File \"/srv/pyramid/kjvrvg/venv/bin/ws-alembic\", line 11, in <module>
load_entry_point('websauna', 'console_scripts', 'ws-alembic')()
File \"/srv/pyramid/kjvrvg/venv/src/websauna/websauna/system/devop/scripts/alembic.py\", line 21, in main
load_entry_point('alembic', 'console_scripts', 'alembic')()
File \"/srv/pyramid/kjvr
~/src/elixir/searchex (master ✘)✹ ᐅ ./searchex query genesis 'joseph'
Collection 'sample/genesis' Query 'joseph'
+----+-------+-------+-----------+-----------+---------------------------------+
| ID | Docid | Score | Startbyte | Doclength | Body |
+----+-------+-------+-----------+-----------+---------------------------------+
| 1 | 62294 | 0.856 | 141268 | 197 | Then there passed by Midianites |
| 2 | c1d12 | 0.749 | 137626 | 257 | These are the generations of Ja |
| 3 | dd0ad | 0.749 | 140563 | 145 | And it came to pass, when Josep |
| 4 | efad7 | 0.749 | 147385 | 161 | And he left all that he had in |
| 5 | 2c19f | 0.749 | 158406 | 172 | And Pharaoh called Joseph's nam |
import json
import uuid
import re
import datetime
from base64 import b64decode
import time
import jwt
import logging
logger = logging.getLogger(__name__)
"""Place your admin resources in this file."""
from websauna.system.admin.modeladmin import model_admin
from websauna.system.admin.modeladmin import ModelAdmin
# Import our models
from . import models
"""Place your SQLAlchemy models in this file."""
'''
PROD/live environment EXPORTING:
pg_dump -U postgres --no-owner --no-acl kjvrvg_production > kjvrvg_dev.pgsql
PROD/live environment IMPORTING:
sudo -i
defmodule TwitterKittensWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use TwitterKittensWeb, :controller
use TwitterKittensWeb, :view
defmodule Gadgety.Mixfile do
use Mix.Project
@target System.get_env("MIX_TARGET") || "host"
Mix.shell.info([:green, """
Mix environment
MIX_TARGET: #{@target}
MIX_ENV: #{Mix.env}
""", :reset])