Skip to content

Instantly share code, notes, and snippets.

View kaanberke's full-sized avatar
🐍
Focusing

Kaan Berke UGURLAR kaanberke

🐍
Focusing
View GitHub Profile
@kaanberke
kaanberke / postgres-cheatsheet.md
Created March 3, 2021 16:32 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@kaanberke
kaanberke / ilceler.json
Created April 6, 2020 07:50
Türkiye il ilçe
[
{
"bolge": "AKDENİZ",
"id": 1,
"il": "ADANA",
"ilce": "ALADAĞ",
"plaka": 1
},
{
"bolge": "AKDENİZ",
@kaanberke
kaanberke / client.py
Created April 5, 2020 00:06
ChatApplicationSystemSocket
import socket
import select
import errno
import sys
HEADER_LENGTH = 10
IP = '127.0.0.1'
PORT = 3000
@kaanberke
kaanberke / useful_packages.md
Last active October 17, 2023 07:42
Useful Python Packages
@kaanberke
kaanberke / seizer.py
Created February 24, 2020 14:19
A class named Seizer which helps us to create pickle-like files.
import shelve
class Seizer:
def __init__(self, filename, writeback=False):
self.filename = filename
self.writeback = writeback
self.last_get = None
self.last_add = None
self.open()
@kaanberke
kaanberke / utils.py
Last active February 18, 2020 11:53
Timer
from time import time
class Timer(object):
def __init__(self, logger=None):
self.start = None
self.end = None
self.logger = logger
def __enter__(self):
import requests
import re
import os
from concurrent.futures import ProcessPoolExecutor
import atexit
URL = "https://www.chessgames.com/perl/nph-chesspgn?text=1&gid="
def send_request(url=None, number=None):
@kaanberke
kaanberke / processpoolexecutor.py
Last active February 11, 2020 09:28
Process Pool Executor
from concurrent.futures import ProcessPoolExecutor, as_completed
from time import sleep
from random import randint
def take_sometime(number):
sleep(randint(1, 5))
return f'Return of {number}'
executor = ProcessPoolExecutor(max_workers=5)
futures = []
@kaanberke
kaanberke / threadpoolexecutor.py
Last active February 8, 2020 21:23
Thread Pool Executor
from concurrent.futures import ThreadPoolExecutor
from time import sleep
def overself(n):
print(f'In overself function for {n}')
sleep(2)
return n ** n
def main(values):
with ThreadPoolExecutor(max_workers = 5) as executor: