Skip to content

Instantly share code, notes, and snippets.

View dmarchuk's full-sized avatar

Daniel Marchuk dmarchuk

View GitHub Profile
@dmarchuk
dmarchuk / migrations.md
Created October 27, 2020 12:40 — forked from majackson/migrations.md
Django migrations without downtime

Django Migrations without Downtime

The following instructions describe a set of processes allowing you to run Django database migrations against a production database without having to bring the web service down.

Note that in the below instructions, migrations are all run manually at explicit points, and are not an automatic part of the deployment process.

Adding Fields or Tables

Adding a (nullable) field or a new table

  1. Make the model or column addition in your code.
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
/** Determines if an object is freed
@param obj is the object of interest
@param freeFn is a function that frees the object.
@returns a promise that resolves to {freed: boolean, memoryDiff:number}
@author Steve Hanov <steve.hanov@gmail.com>
*/
function isObjectFreed(obj, freeFn) {
return new Promise( (resolve) => {
if (!performance.memory) {
import django_filters
class CommaSeparatedValueFilter(django_filters.CharFilter):
"""Accept comma separated string as value and convert it to list.
It's useful for __in lookups.
"""
def filter(self, qs, value):
# JS
find . -name '*.js' | xargs wc -l | sort -nr
# SCSS
find . -name '*.scss' | xargs wc -l | sort -nr
@dmarchuk
dmarchuk / README.md
Last active July 24, 2019 08:24 — forked from stephenway/README.md
BEMIT Cheatsheet
#!/bin/bash
for i in `seq 1 50`;
do
rg -F id=$i\).price;
done

Grep string in logs

docker logs nginx 2>&1 | grep "127."

Create file from logs

docker logs nginx > stdout.log 2>stderr.log

Mac - clean docker orphaned volumes

docker volume rm $(docker volume ls -qf dangling=true)

import csv
import requests
result = ''
for i in range(195):
list_json = requests.get(url, headers={
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
'Accept': '*/*',
/**
* Override default 'renderItems()' function of selectivity
* to accept option with value='' (empty string, item.id === '') as a valid option.
*
* @param items Array of result items.
* @returns HTML-formatted string to display the result items.
*/
$.Selectivity.Dropdown.prototype.renderItems = function (items) {
const selectivity = this.selectivity;
const originalEl = selectivity.options.element;