Skip to content

Instantly share code, notes, and snippets.

View mazlum's full-sized avatar

Mazlum Ağar mazlum

View GitHub Profile
@mazlum
mazlum / gcd.py
Created March 18, 2019 11:36
greatest common divisor
def gcd(x, y):
while y != 0:
(x, y) = (y, x % y)
return x
@mazlum
mazlum / making_queries_models.py
Last active June 3, 2019 14:28
Django making queries
from django.db import models
class Exam(models.Model):
studen_name = models.CharField(max_lenght=50)
point = models.PositiveIntegerField(default=0)
from django.db.models import Case, IntegerField, Sum, Value, When
from django.db.models.functions import Coalesce
q = Exam.objects.aggregate(
success=Coalesce(
Sum(
Case(
When(score__gte=85, then=Value(1)),
default=Value(0),
output_field=IntegerField(),
from django.db.models import Count, Q
q2 = Exam.objects.aggregate(
success=Count("pk", filter=Q(score__gte=85)),
)
print(q)
# {"success": 5}
@mazlum
mazlum / asyncomponent.vue
Last active April 3, 2020 16:01
Vue async component
<template>
<transition name="fade" mode="out-in">
<component
ref="asyncComponent"
:is="asyncComponent"
v-bind.sync="$attrs"
@reload="getComponent"
v-on="$listeners"
/>
</transition>
@mazlum
mazlum / async-example.vue
Last active April 3, 2020 16:06
async example
<template>
<div id="app">
<button @click="load">Load Component right here.</button>
<async-component
v-if="loadComponent"
:component="Example"
example="Example Props"
@listen="listen"/>
</div>
</template>
@mazlum
mazlum / pydantic_like_rest_framework.py
Last active May 6, 2021 14:55
pydantic_like_rest_framework.py
from typing import Optional, Any, Dict, TYPE_CHECKING
from pydantic import BaseModel, validator, validate_model, PrivateAttr
from pydantic.error_wrappers import ValidationError
object_setattr = object.__setattr__
class Foobar(BaseModel):
_errors = PrivateAttr()