Skip to content

Instantly share code, notes, and snippets.

Umut Karcı Cediddi

Block or report user

Report or block Cediddi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Cediddi /
Created Feb 21, 2019
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 /
Last active Sep 12, 2019
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 /
Created Nov 26, 2017
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:
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(('', 5555))
while True:
current_connection, address = connection.accept()
Cediddi /
Created May 31, 2017
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
Cediddi /
Created Mar 11, 2017
django_extensions' shell_plus for Pycharm's django console
from import import_objects
from import no_style
globals().update(import_objects({"dont_load":[], "quiet_load":False},no_style()))
Cediddi /
Created Sep 26, 2016
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 /
Created Sep 11, 2016
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 / list2tuple
Created Sep 9, 2016
This function takes a list and recursively changes all lists to tuples
View list2tuple
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):
return tuple(rlist)
Cediddi / pg_change_ownership
Created Jul 28, 2016
I needed a way to bulk alter ownerships to another user. This worked for me very well. Usage: ./pg_change_ownership dbname username
View pg_change_ownership
#!/usr/bin/env bash
psql -c "alter database \"$dbname\" owner to \"$dbuser\"" $dbname;
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $dbname`;
psql -c "alter table \"$tbl\" owner to \"$dbuser\"" $dbname;
You can’t perform that action at this time.