Skip to content

Instantly share code, notes, and snippets.

View drozdowsky's full-sized avatar
💭
🎬

drozdowsky drozdowsky

💭
🎬
View GitHub Profile
# https://stripe.com/docs/sources/sofort#testing-the-redirect-process
client.Source.create(
type="sofort",
currency=currency.lower(),
amount=int(str(c.get_total().gross.amount).replace(".", "")),
# xxx_chargeable@example.com : The source will be created as pending,
# but automatically transition to chargeable within seconds of its creation.
owner={"email": "xxx_chargeable@example.com"},
redirect={"return_url": "https://test.com"},
sofort={"country": country},
@drozdowsky
drozdowsky / find_silk_traceback.py
Created June 24, 2020 09:23
Get most costly places (in terms of sql queries) in code
from collections import defaultdict
from silk import models
def should_ignore_traceback(traceback):
should_have = ["File", "ecommerce-backend"]
should_not_have = [
"wsgi/health_check.py",
"core/middleware.py",
"graphql/views.py",
Section "Device"
Identifier "Configured Video Device"
Driver "dummy"
EndSection
Section "Monitor"
Identifier "Configured Monitor"
HorizSync 31.5-48.5
VertRefresh 50-70
EndSection
@drozdowsky
drozdowsky / freebsd-xorg-on-xhyve.md
Last active February 8, 2020 16:05
FreeBSD with xorg on xhyve (macOS)

Tutorial how to use FreeBSD (with X11) on macOS using: xhyve + x11vnc + vnctiger + xorg-dummy-driver

  1. Install xhyve (e.g. brew install xhyve)
  2. Use this script to start installation of FreeBSD using xhyve https://github.com/machyve/xhyve/blob/master/xhyverun-freebsd.sh
  3. Add new user in FreeBSD so you won't run Xorg as root (also don't forget to add this user to group video)
  4. To boot up FreeBSD change script so BOOTVOLUME=$IMG
  5. Install essential packages pkg install xorg-minimal xorg-fonts x11vnc xf86-video-dummy
  6. Create /etc/X11/xorg.conf with dummy driver (example configuration https://gist.github.com/divinity76/ce210b5dbcd9ea7d0585ac403caef577)
  7. In your home folder create/change .xinitrc to start some window manager e.g. exec dwm
  8. Start xorg startx & (and pray for no errors)
import django.apps
def related_info(field):
if field.related_model is None:
return ''
start = '===========>'
if field.__class__.__name__ == 'ManyToOneRel':
#!/bin/sh
#
# Check if there is a migration conflict in django apps.
# no need for python/django
# drozdowsky & oliwa
#
NEW_MIGRATIONS=$(git diff --name-only origin/master | grep -o ".*/migrations/[0-9]*")
MASTER_MIGRATIONS=$(git ls-tree -r --name-only origin/master | grep ".*/migrations/.*.py")
CURRENT_BRANCH_MIGRATIONS=$(git ls-tree -r --name-only HEAD | grep ".*/migrations/.*.py")
from app.models import SomeModel
from collections import defaultdict
def tree_from_values(queryset, parent_field_id):
root = defaultdict(lambda: defaultdict(list))
for d in queryset:
# no need to pop but we don't need it anyway
parent = d.pop(parent_field_id)
pk = d['pk']