Skip to content

Instantly share code, notes, and snippets.

View DataGreed's full-sized avatar
👾
practicing magic

Alexey Strelkov DataGreed

👾
practicing magic
View GitHub Profile
@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 / queries.py
Created January 16, 2020 15:53
See recent django SQL queries (converted to sql)
from django.db import connection
print(connection.queries)
#
# 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 / 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
@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 / swagger-ui.html
Created November 30, 2019 03:07
Swagger-UI for django-rest-framework (DRF) with CSRF and log in/log out support
{% load rest_framework %}
<!DOCTYPE html>
<html>
<head>
<title>Swagger</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@3/swagger-ui.css" />
<style>
@DataGreed
DataGreed / filters.py
Created November 30, 2019 02:35
Simple customized filter names for django-rest-framework (DRF)
from django.template import loader, Template, Context
from rest_framework.filters import SearchFilter
browsable_api_filter_template = """{% load i18n %}
<h2>{{ title }}</h2>
<p>{{description}}</p>
<form class="form-inline">
<div class="form-group">
<div class="input-group">
@DataGreed
DataGreed / JoystickDeadZone.cs
Created September 18, 2019 12:52
Implements proper deadzones for joystick or gamepad sticks for Unity
using UnityEngine;
namespace datagreed.input
{
/// <summary>
/// Implements proper deadzones for joystick or gamepad sticks.
/// Based on http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html
///
/// Example usage:
///
# example of threads working on a queue
from Queue import Queue
from threading import Thread
num_worker_threads = 10
# items to work on
def source():
return xrange(400)
@DataGreed
DataGreed / port.sh
Created July 30, 2019 13:32
Find out what process listens to the port on OSX/nix
lsof -n -i4TCP:8080 | grep LISTEN