Skip to content

Instantly share code, notes, and snippets.

View ozkansen's full-sized avatar
:octocat:

Özkan ŞEN ozkansen

:octocat:
View GitHub Profile
@ozkansen
ozkansen / custom_json_pgx.go
Created May 25, 2024 17:26
Go Postgresql Client: pgx custom json marshaller & unmarshaller
package example
import (
pgx "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
)
func postgresCustomJSONUpgrade(conn *pgxpool.Pool) {
conn.Config().AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
package main
import (
"fmt"
"sync"
"sync/atomic"
)
type ObjectPool[T any] struct {
pool sync.Pool
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
import datetime
from dataclasses import dataclass
@dataclass
class ArduinoStatus:
sicaklik : float
battery : float
isik_sens : int
isik_role : int
kasa_kapak : int
@ozkansen
ozkansen / bind_socket.py
Created July 6, 2021 21:53 — forked from tuxfight3r/bind_socket.py
python tcp socket client / server examples
#!/usr/bin/python
import socket #for sockets
import sys #for exit
try:
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
// Fill inside of the optimizeFunction function
function doExpensiveTask(input) {
const result = 2 * input
console.log("Doing expensive task...:", result);
return result;
}
function optimizeFunction(func) {
/*
* Only write code in this function.
* This function returns an optimized version of the func
import random
import string
class RandomPassword:
def __init__(self, length=8, string=True, number=True, special=False) -> None:
self.length = length
self.string = string
self.number = number
self.special = special
def connect_channel(self, channel, delay=1/4):
listen = self.r.pubsub()
listen.subscribe(channel)
self.r.publish(channel, "a::1")
def start_process():
while True:
message = listen.get_message()
time.sleep(delay)
@ozkansen
ozkansen / sensor_read.py
Last active September 21, 2020 11:36
Ardunio analog pin is not attached sensor read value problem
#!/usr/bin/env python3
# Using python package : https://pypi.org/project/pyFirmata/
from pyfirmata import Arduino, util
board = Arduino("/dev/ttyACM0")
it = util.Iterator(board)
it.start()
from subprocess import Popen, PIPE, TimeoutExpired
from typing import Tuple
def execute_command(
command: str, sudo: bool = False, shell: bool = False
) -> Tuple[str, str, int]:
"""
Subprocess Execute Command