Skip to content

Instantly share code, notes, and snippets.

View Object905's full-sized avatar

Zverev Konstantin Object905

View GitHub Profile
@jaysonsantos
jaysonsantos / main.rs
Last active April 29, 2024 15:16
rust ring example
extern crate ring;
use ring::aead::*;
use ring::pbkdf2::*;
use ring::rand::SystemRandom;
fn main() {
// The password will be used to generate a key
let password = b"nice password";
@mjhea0
mjhea0 / audit_mixin.py
Created December 7, 2016 14:12 — forked from techniq/audit_mixin.py
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@UedaTakeyuki
UedaTakeyuki / mh_z19.py
Last active March 19, 2021 13:31
MH-Z19 CO2 Sensor reading.
# http://eleparts.co.kr/data/design/product_file/SENSOR/gas/MH-Z19_CO2%20Manual%20V2.pdf
# http://qiita.com/UedaTakeyuki/items/c5226960a7328155635f
import serial
import time
def mh_z19():
ser = serial.Serial('/dev/ttyAMA0',
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
@pardo
pardo / debounced_celery_task.py
Last active September 8, 2023 08:04
Debounced celery task in python
def debounced_wrap(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
key = kwargs.pop("key") # it's required
call_count = kwargs.pop("call_count", 1)
count = cache.get(key, 1)
if count > call_count:
# someone called the function again before the this was executed
return None
# I'm the last call
@sehmaschine
sehmaschine / models.py
Created November 23, 2015 12:27
Signals for FileBrowseUploadField
from apps.images.signals import image_callback
def entry_upload_path(instance, filename):
return os.path.join("uploads", "blog", str(instance.id), filename)
class Entry(models.Model):
image = FileBrowseUploadField(max_length=250, upload_to=entry_upload_path)
post_save.connect(image_callback, sender=Entry)
@aisamanra
aisamanra / callbacks.rs
Last active May 3, 2024 20:24
Creating a HashMap of closures in Rust
#![feature(unboxed_closures)]
#![feature(core)]
#![feature(io)]
use std::old_io::stdio::{stdin};
use std::collections::HashMap;
// This is our toy state example.
#[derive(Debug)]
struct State {
@shymonk
shymonk / customize-save-in-django-admin-inline-form.org
Last active April 14, 2024 02:55
How to customize save in django admin inline form?

Customize Save In Django Admin Inline Form

Background

This is a common case in django ORM.

from django.db import models

class Author(models.Model):
@mikhailov
mikhailov / gist:9639593
Last active November 10, 2023 22:04
Nginx S3 Proxy with caching
events {
worker_connections 1024;
}
http {
default_type text/html;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;