Skip to content

Instantly share code, notes, and snippets.

View ninapavlich's full-sized avatar

Nina Pavlich ninapavlich

View GitHub Profile
@evantahler
evantahler / dmx.js
Last active July 26, 2018 19:59
enttec open dmx + nodejs
#!/usr/bin/env node
// A simple DMX example which will turn all the lights on and off every second
// You can use this as a fork within another application as well (cluster-awareness)
////////////
// dmx.js //
////////////
var ftdi = require('ftdi');
@specialunderwear
specialunderwear / meta.py
Last active July 22, 2019 12:12
Override model fields of an abstract model baseclass in django, by removing them from the abstract model.
def AbstractClassWithoutFieldsNamed(cls, *excl):
"""
Removes unwanted fields from abstract base classes.
Usage::
>>> from oscar.apps.address.abstract_models import AbstractBillingAddress
>>> from koe.meta import AbstractClassWithoutFieldsNamed as without
>>> class BillingAddress(without(AbstractBillingAddress, 'phone_number')):
... pass
@ninapavlich
ninapavlich / auto_deploy.sh
Last active March 4, 2020 22:20
Bash script that will check a directory for a new commit in a remote repository, and deploy if detects an update
#!/bin/bash
# This script will watch a given directory with a .git checkout and execute a deployment if it detects an update.
# You can set this up with CRON so that deployments happen automatically.
#
# Example CRON usage:
# crontab -e
# */5 * * * * bash /path/to/scripts/deploy.sh
#
# Example manual usage:
# bash /path/to/scripts/deploy.sh force
@vladiibine
vladiibine / swap_django_auth_user.md
Last active March 9, 2020 20:59
Swap django auth.User with custom model after having applied the 0001_initial migration

Swapping the django user model during the lifecycle of a project (django 1.8 guide)

I've come to a point where I had to swap django's user model with a custom one, at a point when I already had users, and already had apps depending on the model. Therefore this guide is trying to provide the support that is not found in the django docs.

Django warns that this should only be done basically at the start of a project, so that the initial migration of an app includes the creation of the custom user model. It took a while to do, and I ran into problems created by the already existing relations between other models and auth.User.

There were good and not so good things regarding my project state, that influenced the difficulty of the job.

Things that made the swap simpler
  1. My custom user also had an id field, that's just a usual default django id
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
def compute_skew(image):
image = cv2.bitwise_not(image)
height, width = image.shape
@LTGIV
LTGIV / ubuntu-mosquitto.yml
Last active July 5, 2021 05:42
Ansible playbook: install Mosquitto on Ubuntu (14.04 LTS) from PPA (alpha)
---
#
# Ansible playbook: install Mosquitto from PPA on Ubuntu v201502131346
# Louis T. Getterman IV (@LTGIV)
# www.GotGetLLC.com / www.opensour.cc
#
# Thanks to @jpmens for insight on cert locations ( https://twitter.com/jpmens/status/565513595644313600 )
#
# Example Usage:
# [user@host ~$] ansible-playbook /etc/ansible/playbooks/ubuntu-mosquitto.yml --extra-vars 'target=nameFromHostsFile'
@transitive-bullshit
transitive-bullshit / image-service.js
Last active November 12, 2021 12:22
Angular service to resize images with antialiasing for use with canvas.
angular.module('demo').service('imageService', function ($http, $q, $timeout) {
var NUM_LOBES = 3
var lanczos = lanczosGenerator(NUM_LOBES)
// resize via lanczos-sinc convolution
this.resize = function (img, width, height) {
var self = { }
self.type = "image/png"
self.quality = 1.0
@DominikSerafin
DominikSerafin / 01_info
Last active July 10, 2022 21:34
Django Slack Logger
This Gist supplements article available at https://serafin.io/article/slack-django-errors
@aaugustin
aaugustin / admin.py
Last active August 7, 2022 19:39
Read-only ModelAdmin for Django
from django.contrib import admin
class ReadOnlyModelAdmin(admin.ModelAdmin):
"""
ModelAdmin class that prevents modifications through the admin.
The changelist and the detail view work, but a 403 is returned
if one actually tries to edit an object.
@kevinthompson
kevinthompson / .env
Last active August 18, 2022 13:39
Litmus Example – Tweets in CSS
TWITTER_CONSUMER_KEY=""
TWITTER_CONSUMER_SECRET=""
TWITTER_SEARCH_STRING="#tedc15 -rt"