Skip to content

Instantly share code, notes, and snippets.

View DataGreed's full-sized avatar
👾
practicing magic

Alexey DataGreed

👾
practicing magic
View GitHub Profile
@DataGreed
DataGreed / receivers.py
Last active December 2, 2019 00:55
Django: update audio duration in database if the associated audio file was updated by user
# considering model has audio_field = FileField()
def some_pre_save_receiver(sender, instance, raw, using, update_fields, **kwargs):
file_was_updated = False
if hasattr(instance.audio_file, 'file') and isinstance(instance.audio_file.file, UploadedFile):
file_was_updated = True
if update_fields and "audio_file" in update_fields:
@DataGreed
DataGreed / wsgi_custom.config
Created December 13, 2019 18:46
fixes Authorization header passing to apache on elastic beanstalk. Put this in your .ebextensions directory
# insures auth headers are passed to flask
files:
"/etc/httpd/conf.d/wsgi_custom.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIPassAuthorization On
#
# Sample JSON Object
# "pending_renewal_info": [
# {
# "expiration_intent": "1",
# "auto_renew_product_id": "renew_product_id",
# "original_transaction_id": "1000000218147500",
# "is_in_billing_retry_period": "0",
# "product_id": "product_id",
# "auto_renew_status": "0"
@DataGreed
DataGreed / queries.py
Created January 16, 2020 15:53
See recent django SQL queries (converted to sql)
from django.db import connection
print(connection.queries)
@DataGreed
DataGreed / TextRevealer.cs
Created February 28, 2020 00:47 — forked from miguelSantirso/TextRevealer.cs
Letter by letter reveal a paragraph of text in a smooth way
using System.Collections;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class TextRevealer : MonoBehaviour
{
[UnityEngine.Header("Configuration")]
public int numCharactersFade = 3;
@DataGreed
DataGreed / ulimit.sh
Created March 16, 2020 13:05
file descriptors MacOS
# per terminal session
# check
ulimit -a
# set, e.g. 4096
ulimit -n 4096
@DataGreed
DataGreed / admin.py
Created March 31, 2020 14:47
Django admin action ith an intermidiate page with form example (this one uses django-push-notifications)
class ExtendedDeviceAdmin(DeviceAdmin):
actions = ("send_message", "send_bulk_message", "send_custom_message_bulk", "enable", "disable")
def send_custom_message_bulk(self, request, queryset):
form = None
# TODO: handle situation when results from multiple pages selected (or is it handled automatically in django 2?)
if 'apply' in request.POST: # if user pressed 'apply' on intermediate page
var angle = Mathf.PI/2 + Mathf.Atan2(-moveDirection.normalized.y, moveDirection.normalized.x);// * Mathf.Rad2Deg;
main.startRotation = angle; //this has to be set in radians apparantly
public static class Vector2Extension
{
public static Vector2 Rotate(this Vector2 v, float degrees)
{
return Quaternion.Euler(0, 0, degrees) * v;
}
}
@DataGreed
DataGreed / UnityNavMeshCheck.cs
Last active August 21, 2023 17:59
Checks that NavMeshAgent reached destination or gave up trying
public bool ReachedDestinationOrGaveUp()
{
if (!_navMeshAgent.pathPending)
{
if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance)
{
if (!_navMeshAgent.hasPath || _navMeshAgent.velocity.sqrMagnitude == 0f)
{
return true;