Skip to content

Instantly share code, notes, and snippets.

View ZSendokame's full-sized avatar
:shipit:
Programming

ZSendokame ZSendokame

:shipit:
Programming
  • 192.168.51.1
  • 00:16 (UTC -03:00)
View GitHub Profile
@ZSendokame
ZSendokame / relindex.py
Created June 22, 2024 00:50
Make dictionaries by list segments.
def relindex_value(iterable: list, column: list) -> list[dict]:
result = []
aux = {}
for index, item in enumerate(iterable):
aux[column[index % len(column)]] = item
if (index % len(column)) == (len(column) - 1):
result.append(aux)
@ZSendokame
ZSendokame / space.ps1
Created April 9, 2024 20:56
Get how many gigabytes there is in a directory.
function space(){
param($Directory)
$total = 0
foreach($file in Get-ChildItem $Directory){
$total += $file.length
}
return $total / 1Gb
}
@ZSendokame
ZSendokame / logs.json
Last active March 4, 2024 20:44
Team Fortress 2 game logs. logs.json contain data from multiple games. 5 Cheaters detected
{
"MrYiang": {
"tf_projectile_arrow": {
"kills": 2,
"crits": 2
},
"spy_cicle": {
"kills": 2,
"crits": 2
},
@ZSendokame
ZSendokame / flatten.py
Last active March 2, 2024 11:57
flattening of dictionaries.
def flatten(structure: dict, head = [], flattened = {}) -> list:
for key, value in structure.items():
if isinstance(value, dict):
head.append(key)
flatten(value, [*head, key], flattened)
else:
flattened['__'.join(head)] = value
return flattened
@ZSendokame
ZSendokame / parse.py
Last active February 16, 2024 00:06
Parsing and unparsing of Query Strings. Saving first ones instead of last ones.
def parse_qs(qs: str) -> dict:
kvs = qs.split('&')
parsed = {}
for kv in kvs:
key, value = kv.split('=')
if key not in parsed:
parsed[key] = value
@ZSendokame
ZSendokame / combinations.py
Created February 10, 2024 01:21
Return all the combinations of a set of characters. ['A', 'B', 'C'], 2 -> AA, AB, AC, BA, BB, BC, CA, CB, CC
def combinations(letters: list, length: int = 4, string = '', result = []) -> list[str]:
if length == len(string):
result.append(string)
return
for letter in letters:
combinations(letters, length, string + letter, result)
return result
@ZSendokame
ZSendokame / text_prediction.py
Last active January 9, 2024 03:00
Text prediction using your own datasets. Works by searching matches and then cutting out unnecesary segments. Still working on it
def algorithm(dataset: list, input: str, output_length: int = None) -> str:
matches = filter(lambda quote: input in quote, dataset)
processed = map(lambda quote: quote[quote.index(input):], matches)
return [segment[0:output_length] for segment in processed]
@ZSendokame
ZSendokame / composites.py
Last active January 9, 2024 05:27
Return composition of a number n, checking divisibility by all numbers up to a ceiling.
def compound(n, ceiling: int = 10, powers: list = []):
for i in range(2, ceiling):
if n % i == 0:
powers.append(i)
return compound(n // i, ceiling, powers)
powers.append(n)
return powers
@ZSendokame
ZSendokame / wrap.py
Last active November 18, 2023 16:50
Wrap an array in n-Sized groups, wrap([1, 2, 3, 4, 1, 2, 3, 4], 4) -> [[1, 2, 3, 4], [1, 2, 3, 4]]
def wrap(array, size) -> list:
result = []
aux_array = []
for i in array:
aux_array.append(i)
if len(aux_array) == size:
result.append(aux_array)
@ZSendokame
ZSendokame / Eulers.py
Last active November 3, 2023 18:09
Euler number approximation. Instead of using math.factorial, used that little trick. Discovered while thinking how to make it faster and more precise, didn't found a way to make it more precise
def euler() -> Decimal:
e = Decimal(0)
f = 1
for n in range(2, 100_000):
f *= n
e += Decimal((1 / f))
return e + 2