Skip to content

Instantly share code, notes, and snippets.

View Cediddi's full-sized avatar
🐍
from yilan_terbiyecisi import current_user

Umut Karcı Cediddi

🐍
from yilan_terbiyecisi import current_user
  • Tacto.ai
  • München
  • 17:52 (UTC +02:00)
View GitHub Profile
@Cediddi
Cediddi / allons_y.py
Created January 20, 2021 01:38
A simple script that can run as a daemon to check and notify you about your public transport arriving in next hour.
import json
import pathlib
import sys
import time
import datetime
from copy import deepcopy
from typing import List, Dict, Any
from urllib.parse import urljoin
import appdirs
@Cediddi
Cediddi / canim_turkiyem.py
Created February 21, 2019 09:17
Python için güncel Türkiye il ilçe deposu
#!/usr/bin/env python3
"""
Bu script İçişleri Bakanlığının yayınladığı il/ilçe listesini okuyup size bir sözlük olarak geri verir, aslında başka şeyler de yapabilir, ben yapmadım üşendim, siz isterseniz yapın.
"""
__author__ = "Umut Karcı"
__license__ = "MIT"
from tablib import Dataset
@Cediddi
Cediddi / pg10_partition_compiler_sqla.py
Last active September 12, 2019 16:44
Simple helper that enables Postgresql 10's declarative partitioning features.
import textwrap
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.ddl import CreateTable
@compiles(CreateTable, "postgresql")
def pg10_partition_compiler(element, compiler, **kw):
"""
Simple helper that enables Postgresql 10's declarative partitioning features.
partition_by : str = Plain sql string that defines partition rules for the parent table.
@Cediddi
Cediddi / readnlines.py
Created November 26, 2017 14:09
A very simple read n lines implementation, available in all natural, classic and generator flavors.
def readnlines(filehandler, n=4):
line_groups = []
while True:
nlines = []
for i in range(n):
line = filehandler.readline()
if line:
nlines.append(line.strip())
else:
if nlines:
import socket
def listen():
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
connection.bind(('0.0.0.0', 5555))
connection.listen(10)
while True:
current_connection, address = connection.accept()
@Cediddi
Cediddi / nested_itemgetter.py
Created May 31, 2017 12:05
We all love operator.itemgetter, wouldn't it be cool if you can just do itemgetter("a.b", "a.c"). This works great on nested dictionaries, not so great with sequences.
class nested_itemgetter:
def __init__(self, item, *items):
if not items:
def func(obj):
steps = item.split(".")
for step in steps:
obj = obj[step]
return obj
self._call = func
else:
@Cediddi
Cediddi / shell_plus_for_pycharm.py
Created March 11, 2017 12:27
django_extensions' shell_plus for Pycharm's django console
from django_extensions.management.shells import import_objects
from django.core.management.color import no_style
globals().update(import_objects({"dont_load":[], "quiet_load":False},no_style()))
@Cediddi
Cediddi / namedtuple_with_defaults.py
Created September 26, 2016 10:28
Factory for creating namedtuples with keyword arguments.
def namedtuple_with_defaults(typename, args=None, kwargs=None, verbose=False, rename=False):
"""
Factory for creating namedtuples with keyword arguments.
:type typename: str
:type args: tuple
:type kwargs: tuple
:type verbose: bool
:type rename: bool
:rtype: namedtuple
"""
@Cediddi
Cediddi / weather_widget.py
Created September 11, 2016 14:03
A RGB weather widget written in Micropython for ESP8266. Requires urequests from micropython-lib and wemos from mplibs. Also known as Future Gadget 13-2 (Wireless WorldWideWeb Weather Widget)
from wemos import *
from machine import Pin, PWM
import machine
import time
import urequests
import urandom
red = PWM(Pin(D8), freq=512, duty=0)
green = PWM(Pin(D7), freq=512, duty=0)
blue = PWM(Pin(D6), freq=512, duty=0)
@Cediddi
Cediddi / list2tuple
Created September 9, 2016 11:59
This function takes a list and recursively changes all lists to tuples
def list2tuple(l):
"""This function takes a list and recursively changes all lists to tuples"""
rlist = []
for i in l:
if type(i) in (list, tuple, set):
rlist.append(l2t(i))
else:
rlist.append(i)
return tuple(rlist)