Skip to content

Instantly share code, notes, and snippets.

Avatar

Emrah Gündüz emrahgunduz

  • @Impressions-app
  • California
View GitHub Profile
@emrahgunduz
emrahgunduz / async_timer.py
Created Aug 18, 2021
Async timer with callback
View async_timer.py
import asyncio
from asyncio import Future
from collections import Callable
from typing import ClassVar
from typing import Optional
class Timer:
_task: Optional[ Future ] = None
_timeout: ClassVar[ float ]
@emrahgunduz
emrahgunduz / timed_class.py
Created Jul 8, 2021
A timed, self running, stoppable class for Python
View timed_class.py
from threading import Timer
from typing import ClassVar
from typing import Optional
class SelfRunner( object ):
_timeout: ClassVar[ float ] = 10.0
_timer: Optional[ Timer ] = None
_end_called: bool = False
@emrahgunduz
emrahgunduz / plot-multi.py
Created Apr 15, 2021
Plot multiple images (numpy array) with mathplotlib, defining only column size
View plot-multi.py
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams["figure.figsize"] = 12,12
def plot_images(images, columns=4):
total = len(images)
nrow = ceil(total / columns)
ncol = columns
fig = plt.figure(figsize=(ncol+1, nrow+1))
@emrahgunduz
emrahgunduz / took.py
Created Apr 13, 2021
Simple thread safe process timer
View took.py
from threading import Lock
import time
class Took:
def __init__ ( self ):
self.__lock = Lock()
with self.__lock:
self.__start = time.time()
self.__total = time.time()
@emrahgunduz
emrahgunduz / log.py
Created Apr 13, 2021
Simple auto flushing, thread safe logger for Elastic consumer (Singleton)
View log.py
from __future__ import annotations
from typing import Union
import os
import uuid
import json
from datetime import datetime
from threading import Lock
class Log( object ):
@emrahgunduz
emrahgunduz / counter.py
Last active Apr 14, 2021
Python thread safe counter
View counter.py
from threading import Lock
class Counter( object ):
def __init__ ( self ):
self.__value = 0
self.__lock = Lock()
def increment ( self, by_value: int = 1 ):
with self.__lock:
@emrahgunduz
emrahgunduz / health_check.py
Last active Mar 4, 2021
Python - Create a simple health check server (async)
View health_check.py
import asyncio
import json
import threading
from aiohttp import web
def healthcheck_response ( data, *, text=None, body=None, status=200, reason=None, headers=None, content_type="application/json", dumps=json.dumps ):
return web.json_response(
data,
text=text,
View CIImage_CVPixelBuffer.swift
import Foundation
import UIKit
extension CGImage {
public var cvPixelBuffer: CVPixelBuffer? {
let attrs = [
kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferMetalCompatibilityKey: kCFBooleanTrue
] as CFDictionary
@emrahgunduz
emrahgunduz / mail.rc
Last active Apr 5, 2019
Mailx and configuration for Cron email sending
View mail.rc
set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via D$
account forcron {
set smtp-use-starttls
set ssl-verify=ignore
set smtp-auth=login
set smtp=smtp://example.com:587
set from="Email Address <email@example.com>"
set smtp-auth-user=USERNAME
@emrahgunduz
emrahgunduz / imap-sync.sh
Created Feb 28, 2017
A bash script to clone multiple email-password combinations from one imap host to another. Requires imapsync installed/compiled and a csv file for email list. Uses port 993+ssl as default.
View imap-sync.sh
#!/bin/sh
# CSV file line example:
# some.name@domain.com,PASSWORD
if [ -z "$1" ]
then
echo "CSV file is not specified!"
exit 1
fi