Skip to content

Instantly share code, notes, and snippets.

@Jubiko31
Jubiko31 / db.rs
Created July 24, 2023 13:04
🦀 Rust (Rocket) microservice to clean up postgres database within specified interval. Connection to Django app with RabbitMQ
use tokio_postgres::{NoTls, Error};
pub async fn pg_delete_old_records() -> Result<(), Error> {
let (client, connection) = tokio_postgres::connect("postgres://postgres:postgres@localhost:5432/test_db", NoTls).await?;
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
}
});
@Jubiko31
Jubiko31 / arpspoof_detect.py
Created April 4, 2023 12:13
ARP Spoofing Detector
#!/usr/bin/env python
import scapy.all as scapy
from argparse import ArgumentParser
def get_args():
parser = ArgumentParser()
parser.add_argument("-i", "--interface", dest="interface", help="Target interface to monitor")
args = parser.parse_args()
return args
@Jubiko31
Jubiko31 / report.query.ts
Created February 3, 2023 22:38
Advance SQL query to generating report from cars & rents tables
export const report_query = (year: number, month: number) => {
const query = `SELECT id, COALESCE(usage_in_percents, '0%') as usage, name, license_plate, '${year}-${month}' as month FROM
(SELECT car_id, TO_CHAR(SUM(diff) / (SELECT extract(days FROM date_trunc('month', date('${year}-${month}-01')) + interval '1 month - 1 day')) * 100, 'fm00D00%') as Usage_In_Percents FROM
(SELECT
car_id, startdate,lastdate,
DATE_PART('day', (date_trunc('month', startdate::date) + interval '1 month' - interval '1 day')::date::timestamp - startdate::timestamp)
AS diff
FROM rents
WHERE (EXTRACT(MONTH FROM startdate) = ${month}
AND EXTRACT(YEAR FROM startdate) = ${year})