Skip to content

Instantly share code, notes, and snippets.

View rj76's full-sized avatar

Richard Jansen rj76

  • The Hague, The Netherlands
View GitHub Profile
@rj76
rj76 / apprenticeship.md
Created June 3, 2023 09:43
Apprenticeship My24Service.com

Apprenticeship My24Service.com

It would concern a apprenticeship at My24Service.com (regretfully, the website is only in Dutch at the moment). We have a SaaS application for the maintenance and installation sector, that is now expanding to more types of clients.

One of the wishes we have, that might be an interesting project to do, is to be able to map a warehouse (loading docks, other equipment, etc.) into a 3D model using photogrammetry. As a first step we could make photo's by hand, but having a drone do that would be far more praktical.

From the top of my head, the following would have to be created:

@rj76
rj76 / crud_diesel.rs
Last active December 3, 2022 20:54
CRUD
pub trait CrudModel: Table + IntoUpdateTarget {
type FormObj;
fn get<T>(self, conn: &mut TenantConnection, id: i32) -> QueryResult<T>
where
Self: FindDsl<i32>,
<Self as FindDsl<i32>>::Output:
Table + AsQuery + for<'a> LoadQuery<'a, TenantConnection, T>,
{
self.find(id).get_result::<T>(conn)
@rj76
rj76 / TestDatabase.rs
Created October 1, 2022 18:40
Set up a test database once and get connections for tests that run in a diesel test_transaction
use std::error::Error;
use diesel::{sql_query, Connection, RunQueryDsl, insert_into};
use diesel::{PgConnection};
use diesel::pg::Pg;
use diesel::r2d2::ConnectionManager;
use diesel_migrations::{EmbeddedMigrations, MigrationHarness};
use r2d2::CustomizeConnection;
use reqwest::Url;
use lazy_static::lazy_static;
use log::{info};
@rj76
rj76 / create_subselect.rs
Created August 20, 2022 18:16
Function to create a subselect so it can be used in Diesel's select()
use diesel::prelude::*;
use diesel::backend::Backend;
use diesel::expression::{Expression, AsExpression, Selectable, ValidGrouping};
use diesel::query_builder::{AstPass, Query, QueryFragment};
use diesel::{QueryResult};
use diesel::pg::Pg;
use diesel::sql_types::{SingleValue};
use crate::schema::{order_order, order_status};
pub struct Subquery<T> {
@rj76
rj76 / pagination.rs
Created July 9, 2022 10:56
Diesel pagination
use diesel::prelude::*;
use diesel::pg::Pg;
use diesel::query_builder::*;
use diesel::query_dsl::methods::LoadQuery;
use diesel::sql_types::{BigInt};
const DEFAULT_PAGE_SIZE: i64 = 20;
#[derive(QueryId)]
pub struct Paginated<T> {
@rj76
rj76 / exception.py
Created February 24, 2022 11:26
Exception
class SalaryNotInRangeError(Exception):
"""Exception raised for errors in the input salary.
Attributes:
salary -- input salary which caused the error
message -- explanation of the error
"""
def __init__(self, salary, message="Salary is not in (5000, 15000) range"):
self.salary = salary
@rj76
rj76 / managers.py
Last active November 20, 2021 16:04
Some django manager methods for the Order model
class OrderManager(Manager):
def add_available_count(self, qs):
available_count = qs.annotate(
available_count=Count('user_order_availability', filter=Q(user_order_availability__is_accepted=False))
).filter(user_order_availability__order_id=OuterRef('id'))
qs = qs.annotate(
available_count=Subquery(available_count.values('available_count'), output_field=IntegerField()),
)
@rj76
rj76 / threaded-entry-redis-PoC.py
Created November 8, 2021 20:25
Threaded vote entry using redis PoC
from threading import Thread, get_ident
import random
import redis
from time import sleep
from pathlib import Path
redisServer = redis.Redis(host='localhost', port=6379, db=5, decode_responses=True)
@rj76
rj76 / bsn_check.dart
Created October 2, 2021 09:50
BSN checker
bool isNumeric(String? s) {
if(s == null) {
return false;
}
return double.tryParse(s) != null;
}
bool isValidBsn(String bsn) {
/*
Validator based on a variation of the Dutch check-digit validation used for checking IBAN.
@rj76
rj76 / fixtures.py
Created September 15, 2021 09:47
pytest tenant fixtures
import pytest
from django.core.management import call_command
from django_tenants.utils import get_public_schema_name
from apps.core import test_mixins as mixins
from apps.core.nmbrs import NmbrsEmployee, NmbrsCompany
from apps.member import models as member_models
from apps.member.tests import factories as member_factories