Skip to content

Instantly share code, notes, and snippets.

@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@joffilyfe
joffilyfe / README.md
Last active April 3, 2023 01:38
GITEA + Drone (0.7|0.8)

Compose file to setup and host a Gitea and Drone environment

This environment is dependent off a common network for docker/git plugin and gitea-server, so for this work fine in closed networks we have to create a custom network before run this composefile.

First create your network:

docker network create gitea-network
@qodot
qodot / pytest_flask_fixtures.py
Created November 10, 2016 01:30
Pytest Fixtures (Flask, SQLAlchemy, Alembic)
import sys
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from alembic.command import upgrade as alembic_upgrade
from alembic.config import Config as AlembicConfig
from wsgi import create_app
from config import config
@dmh43
dmh43 / grav.cpp
Last active September 28, 2022 05:38
A simple physics simulator with OpenGL
#include <GL/freeglut.h>
#include <vector>
#include <cmath>
const double pi = 3.141593;
typedef struct PhysVector {
float x;
float y;
};
@vovkab
vovkab / gist:d9f76e3429cdf20a4e0c
Created January 13, 2016 18:05 — forked from ohmrefresh/gist:55149f68c41a148ae673
How to Server-side verification of Google Play subscriptions
1.create google app (google console)
Example:
Client ID xxx.apps.googleusercontent.com
Email address xxx@developer.gserviceaccount.com
Client secret xxx
Redirect URIs
https://localhost/oauth2callback
Javascript Origins
https://localhost
@gustavorps
gustavorps / usb_backdoor.c
Created October 20, 2015 18:26
Arduino USB Backdoor
//Modifier Keys
#define LEFT_CTRL 0x01
#define LEFT_SHIFT 0x02
#define LEFT_ALT 0x04
#define LEFT_GUI 0x08
#define RIGHT_CTRL 0x10
#define RIGHT_SHIFT 0x20
#define RIGHT_ALT 0x40
#define RIGHT_GUI 0x80
#!/usr/bin/env python3.4
import urllib.request
import asyncio
def return_response(url):
return urllib.request.urlopen(url).read()
@asyncio.coroutine
def read_page(loop, url):
@eelsivart
eelsivart / heartbleed.py
Last active April 28, 2024 13:18 — forked from sh1n0b1/ssltest.py
Heartbleed (CVE-2014-0160) Test & Exploit Python Script
#!/usr/bin/python
# Modified by Travis Lee
# Last Updated: 4/21/14
# Version 1.16
#
# -changed output to display text only instead of hexdump and made it easier to read
# -added option to specify number of times to connect to server (to get more data)
# -added option to send STARTTLS command for use with SMTP/POP/IMAP/FTP/etc...
# -added option to specify an input file of multiple hosts, line delimited, with or without a port specified (host:port)
obj-m += rootkit.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
@dcousens
dcousens / heightmap.py
Last active June 9, 2017 23:53
Prototype of the midpoint displacement algorithm, also known as the diamond square algorithm.heightmap.py creates a triangular mesh represented as a list vertices and indices from a 2d normalized array of values and some parameters. Commonly used as a heightmap.
import itertools
def get_verts_indices_for_heightmap(heightmap, stepx, stepy, minz, maxz):
""" heightmap assumed to be normalized (values between 0 and 1)
"""
height = len(heightmap)
width = len(heightmap[0])
spanz = maxz - minz
# n_heightmap = width * height