Skip to content

Instantly share code, notes, and snippets.

@se1983
se1983 / serde_deserialize_constructor.rs
Last active October 31, 2022 11:25
rust constructors creating structs
use serde::{Deserialize, Serialize};
pub trait SerdeDeserializeObject {
fn new<'de>(data: &'de str) -> Self
where
Self: Deserialize<'de>,
{
let serialized_data: Self = serde_json::from_str(&data).unwrap();
serialized_data
}
@sainipray
sainipray / filter.py
Created February 27, 2020 09:53
Custom Django rest framework Ordering Filter
from rest_framework.filters import OrderingFilter
class CustomOrderFilter(OrderingFilter):
allowed_custom_filters = ['user_city', 'user_country']
fields_related = {
'user_city': 'user__city__name', # ForeignKey Field lookup for ordering
'user_country': 'user__country__name'
}
def get_ordering(self, request, queryset, view):
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active July 10, 2024 12:43
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@piboistudios
piboistudios / parent-children-tree.rs
Last active December 31, 2023 14:15 — forked from rust-play/playground.rs
[RUST]Parent-Children Tree (#2)
// we will use weak references with the Rc<T> (reference counting pointer) type
// weak references allow us to make references to a value that will -not- keep it alive
// this is perfect in the intsance of children, as we will soon see
use std::rc::{Rc,Weak};
use std::cell::RefCell;
// this example builds upon the last by storing a vector of children as well as a parent
#[derive(Debug)]
struct Node {
@vjousse
vjousse / sqlalchemy_conftest.py
Created February 20, 2018 14:35 — forked from kissgyorgy/sqlalchemy_conftest.py
Python: py.test fixture for SQLAlchemy test in a transaction, create tables only once!
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from myapp.models import BaseModel
import pytest
@pytest.fixture(scope='session')
def engine():
return create_engine('postgresql://localhost/test_database)
@ofrzeta
ofrzeta / preseed.cfg
Last active May 10, 2019 14:14
Minmal preseed.cfg for Debian on KVM, German keyboard/timezone, auto LVM partitioning, serial console
d-i debian-installer/locale string en_US
d-i keymap select de
d-i keyboard-configuration/xkb-keymap select de
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string de
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string debianhost
d-i netcfg/get_domain string mydomain
d-i netcfg/wireless_wep string
@pgaskin
pgaskin / jessie-base.preseed
Last active March 23, 2024 15:39
A preseed file for a minimal Debian Jessie installation
# How to run
# In the folder with these files
# sudo python -m SimpleHTTPServer 80
#
# Update the ip at the bottom of this file to the output of
# hostname -I
# This is your ip
#
# Start debian cd
# Press esc on menu
@johanndt
johanndt / upgrade-postgres-9.3-to-9.5.md
Last active July 15, 2022 12:35 — forked from dideler/upgrade-postgres-9.3-to-9.4.md
Upgrading PostgreSQL from 9.3 to 9.5 on Ubuntu

TL;DR

Install Postgres 9.5, and then:

sudo pg_dropcluster 9.5 main --stop
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
@mmasaki
mmasaki / iperf.service
Last active August 14, 2023 19:42
systemd service unit for iperf
# /etc/systemd/system/iperf.service
[Unit]
Description=iperf server
After=syslog.target network.target auditd.service
[Service]
ExecStart=/usr/bin/iperf -s
[Install]
WantedBy=multi-user.target
@kissgyorgy
kissgyorgy / sqlalchemy_conftest.py
Last active June 26, 2024 20:01
Python: py.test fixture for SQLAlchemy test in a transaction, create tables only once!
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from myapp.models import BaseModel
import pytest
@pytest.fixture(scope="session")
def engine():
return create_engine("postgresql://localhost/test_database")