Skip to content

Instantly share code, notes, and snippets.

View giorgiberia's full-sized avatar
🎯
Focusing

Giorgi Beria giorgiberia

🎯
Focusing
View GitHub Profile
@giorgiberia
giorgiberia / matchCaseExamplex.py
Created August 16, 2021 07:47
python 3.10 match case examples
http_code = "418"
match http_code:
case "200":
print("OK")
do_something_good()
case "404":
print("Not Found")
do_something_bad()
case "418":
print("I'm a teapot")
import socket
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 9000
location = ("127.0.0.1", port)
result_of_check = a_socket.connect_ex(location)
print(str(port)+" open" if result_of_check == 0 else str(port)+" not open")
a_socket.close()
@giorgiberia
giorgiberia / datetimExamples.py
Last active October 16, 2020 11:53
datetime python useful
import datetime as dt
# 2020-10-14 12:00:00
first_date = dt.datetime.strptime(first_date, '%Y-%m-%d %H:%M:%S')
# 2020-10-16 12:05:05
second_date = dt.datetime.strptime(second_date, '%Y-%m-%d %H:%M:%S')
diff = second_date - first_date
hours = diff.days * 24 + diff.seconds // 3600
var cover = document.createElement("div");
let css = `
position: fixed;
pointer-events: none;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: white;
mix-blend-mode: difference;
# it's very easy to remove white spaces from strings
# it can be done using many methods but here we will disscuss some efficient one
# 1. Using replace()
s = " h a c k you r co de " # this function doesn't modify original string
new_s = s.replace(" ","") # here new_s holds new string with no blank spaces at all.
print(new_s)
# the output will be "hackyourcode"
# 2. Using join() and split()
@giorgiberia
giorgiberia / tasksSubs.py
Last active May 29, 2020 15:20
parent child task sub tasks flat array to nested by children
def buildTree(tasks, parentId=0):
branch = []
for task in tasks:
if task['parent_id'] == parentId:
children = buildTree(tasks, task['id'])
if children:
# print(list(children.keys()))
task['children'] = children
else:
@giorgiberia
giorgiberia / gist:d1e772007170cc2a45d3f3f17c08a0a3
Last active August 21, 2019 11:44 — forked from evildmp/gist:3094281
Set up Django, nginx and uwsgi

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using: