This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Register a custom SLQ function to convert a string to a slug | |
https://gist.github.com/abn/779166b0c766ce67351c588489831852 | |
This example is using Postgresql | |
""" | |
from django.db import migrations | |
SLUGIFY_FUNCTION = """ | |
CREATE OR REPLACE FUNCTION public.slugify( | |
v TEXT | |
) RETURNS TEXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_index(obj, itero): | |
try: | |
return search_index(obj[next(itero)], itero) | |
except StopIteration: | |
return obj | |
a = [{"name":"someone", "age":23}] | |
s = (0, 'name') | |
result = search_index(a, iter(s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Film(models.Model): | |
name = models.CharField(max_length=30) | |
def __str__(self): | |
return self.name | |
class Jury(models.Model): | |
name = models.CharField(max_length=30) | |
many_films = models.ManyToManyField(Film, through='Classement') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Agro: | |
def __init__(self, parent, prop1=None, prop2=None): | |
self.parent = parent | |
self._prop1 = prop1 | |
self._prop2 = prop2 | |
@property | |
def prop1(self): | |
try: | |
if self._prop1 is None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
class Modudule: | |
def __init__(self, param): | |
self.param = param | |
print("modudu: ", self.param.bouboul, self.param.nom, | |
self.param.metoclass()) | |
# via multiproc sur windows: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def lent(ind, string): | |
a = 1 | |
# for i in range(ind): #en fait vu que c'est single thread, le calcul se fait à la queulelle | |
# a **= 2 | |
await asyncio.sleep(ind) | |
print("funlent", string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Params: | |
def __init__(self): | |
self.attr1 = self.attr1 | |
@classmethod | |
def ret_attr1(cls): | |
return cls.attr1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MetaRace(type): | |
def __new__(mcs, name, bases, dct): | |
dct['genre'] = 'M' # ecrasé après | |
dct['espece'] = 'YAGARA' # pas ecrasé | |
return super().__new__(mcs, name, bases, dct) | |
class Parent: | |
nom = "daron" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# Classes créée dynamiquement | |
AutreNomYolo = type('Yolo', (), {'__str__': lambda: 'salut'}) | |
AutreNomYolo2 = type('Yolo', (), {'__str__': lambda: 'degage'}) | |
type('Yolo', (), {'__str__': lambda: 'salut'}) # garbage collector direct ? comment appeler la classe par son __name__ | |
# car je pourrais stocker l'objet dans une liste etc.. | |
list_obj = [None, None] | |
list_obj[1] = type('Yolo', (), {'__str__': lambda: 'salut'}) | |
print(AutreNomYolo.__str__()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ll = ['ya', 'bor'] | |
point_visrgul = ';'.join | |
print(point_visrgul(ll)) | |
class bidule: | |
pass | |
inst = bidule() |