Skip to content

Instantly share code, notes, and snippets.

View dejurin's full-sized avatar
💭
;-)

YURII D. dejurin

💭
;-)
  • Si-ɑR
  • București, România 🇷🇴
  • 09:36 (UTC +03:00)
View GitHub Profile
@dejurin
dejurin / settings.json
Created June 4, 2023 19:43 — forked from kevmor11/settings.json
VS Code Settings
// Controls the font size in pixels.
"editor.fontSize": 12,
// Controls auto save of dirty files. Accepted values: 'off', 'afterDelay', 'onFocusChange' (editor loses focus), 'onWindowChange' (window loses focus). If set to 'afterDelay', you can configure the delay in 'files.autoSaveDelay'.
"files.autoSave": "off",
// Controls the font family.
"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
@dejurin
dejurin / dict_list_to_dict_with_list_data_by_key.py
Last active February 21, 2023 16:45
How to dict list convert to dict with list data by key
from collections import defaultdict
data = [{
'base': 'a',
'data':1,
},{
'base': 'a',
'data':2,
},{
'base': 'a',
def json_default(o):
if isinstance(o, (date, datetime)):
return o.isoformat()
def slice_dict_keys(d: dict, start: str, end: str):
lk = list(d.keys())
lv = list(d.values())
try:
start_ll = lk.index(start)
end_ll = lk.index(end)
except ValueError:
return None
class DayQuarter:
def __init__(self, date_class: date, months = 3):
self.date_class = date_class
self.months = months
def quarter(self) -> int:
return (self.date_class.month - 1) // self.months + 1
def first(self):
return datetime(self.date_class.year, self.months * ((self.date_class.month - 1) // self.months) + 1, 1)
# Table mapping response codes to messages; entries have the
# form {code: (shortmessage, longmessage)}.
HTTP_response_codes = {
100: ('Continue', 'Request received, please continue'),
101: ('Switching Protocols',
'Switching to new protocol; obey Upgrade header'),
200: ('OK', 'Request fulfilled, document follows'),
201: ('Created', 'Document created, URL follows'),
202: ('Accepted',
@dejurin
dejurin / JSONDisk.py
Created February 12, 2023 17:31
DiskCache: JSONDisk driver
"""
with rapidjson or json lib
"""
import rapidjson, zlib
from diskcache import core, Disk
from datetime import date, datetime
from typing import Any
def json_default(o):
@dejurin
dejurin / float_is_int.py
Last active February 11, 2023 12:38
Python: float to int
"""
Get a number with type int from a float as like 1.0
"""
def float_is_int(value: float | str | int) -> float | int:
if isinstance(value, str):
try:
value = float(value)
except ValueError:
return value
@dejurin
dejurin / example.py
Created January 10, 2023 01:42
Remove items from nested dictionary where value is zero
"""
https://stackoverflow.com/a/59956828/3360295
"""
fdict = {
'apple': {'green': 5, 'red': 0},
'banana': {'light_yellow': 10, 'dark_yellow': 0},
'appraisal round': 1
}
@dejurin
dejurin / index.html
Created July 10, 2022 19:21
Using only CSS, show div on hover over another element
<!-- http://jsfiddle.net/cor6bay6/1/ -->
<style>
.showme {
display: none;
}
.showhim:hover .showme {
display: block;
}
</style>