Skip to content

Instantly share code, notes, and snippets.

@zorky
zorky / mutable-immutable.py
Created December 17, 2024 17:08
list / tuple / namedtuple : mutable immutable
from collections import namedtuple
BOLD = "\033[1m"
RESET = "\033[0m"
# Liste : mutable
print(f"\n{BOLD}1-{RESET} changement valeur élément d'une {BOLD}liste{RESET} possible : {BOLD}mutable{RESET}")
fruits = ["pomme", "banane", "cerise", "orange"]
fruits.append("orange") # Liste modifiable
print(f"liste : {fruits} - set(liste) : {set(fruits)}\n")
@zorky
zorky / debounce-dictinct-filter.ts
Last active March 8, 2024 13:11
search input TS Rxjs Angular : debounceTime distinctUntilChanged
fromEvent(this.filter.nativeElement, 'keyup').pipe(
debounceTime(400),
distinctUntilChanged(),
filter(() => this.filter.nativeElement.value.length >= this.minFilter || this.filter.nativeElement.value.length === 0))
@zorky
zorky / _docker-migrate-aufs.md
Created March 3, 2023 14:57 — forked from marcelrv/_docker-migrate-aufs.md
Docker migrate to overlay2 from aufs script

Docker migrate to overlay2 from aufs script

Crazy that this is pretty much forced change without proper transition script

note. Based on https://www.sylvaincoudeville.fr/2019/12/docker-migrer-le-stockage-aufs-vers-overlay2/ NOT WORKING!!!! IF FOLLOWING THE ABOVE.. SOMEHOW THE CONTAINERS DO NOT RE-APPEAR!

The only way I found that is somewhat automated is the the docker-compose way..

Which is still not 100% and require manual fixing of stupid errors of the docker-compose tool (mainly things that ere not interpreted right, like dates & userIds that need to manually surrounded by quotes etc)

@zorky
zorky / psql_useful_stat_queries.sql
Created March 19, 2021 08:50 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@zorky
zorky / reduce.ts
Last active August 24, 2019 10:48
Reduce d'une liste de dates, renvoie une chaîne de concaténation des dates: date1, date2, ..., dateN
/**
Exemple de reduce d'une liste de dates (dates_obj : [{date: 'date'}, ...]
*/
reduce(row): string {
dates = row.dates_obj.reduce<string>((previousValue, currentValue, currentIndex) => {
let currentDate = `${dp.transform(currentValue.date, 'dd/MM/yyyy')}`;
const { hh, mm } = { hh: dp.transform(currentValue.date, 'HH'), mm : dp.transform(currentValue.date, 'mm')};
if (hh !== '00') {
currentDate = `${currentDate} à ${hh}h${mm}`;
}
@zorky
zorky / fieldoperator_filter.py
Last active January 4, 2019 10:20
Generic filter with operators (gt, lt, eq, ne) on model's field
import django_filters
import datetime
from django.db.models import Q
class FilterOperatorBase(django_filters.FilterSet):
"""
base filter for field_operator
field_operator is formatted as : field||type||operator||value