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
Cediddi / canim_turkiyem.py
Created Feb 21, 2019
Python için güncel Türkiye il ilçe deposu
View canim_turkiyem.py
#!/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 Sep 12, 2019
Simple helper that enables Postgresql 10's declarative partitioning features.
View pg10_partition_compiler_sqla.py
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 Nov 26, 2017
A very simple read n lines implementation, available in all natural, classic and generator flavors.
View readnlines.py
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:
View simple_http_debug_server.py
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
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.
View nested_itemgetter.py
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 Mar 11, 2017
django_extensions' shell_plus for Pycharm's django console
View shell_plus_for_pycharm.py
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 Sep 26, 2016
Factory for creating namedtuples with keyword arguments.
View namedtuple_with_defaults.py
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 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)
View weather_widget.py
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 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):
rlist.append(l2t(i))
else:
rlist.append(i)
return tuple(rlist)
@Cediddi
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
dbname=$1
dbuser=$2
psql -c "alter database \"$dbname\" owner to \"$dbuser\"" $dbname;
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $dbname`;
do
psql -c "alter table \"$tbl\" owner to \"$dbuser\"" $dbname;
You can’t perform that action at this time.