ZN Code Saves
20 subscribers
2 photos
2 links
Code snippets and programming notes.

For testing bots and scripts, please join: @botspamdebug

More from ZN: @z_network
Download Telegram
Forwarded from I Run Code
Language:
python


Code:
# Unicode Secure Password Generator v1.0
import secrets
import unicodedata

def is_printable_unicode(char):
"""Check if a character is printable and not a whitespace character."""
category = unicodedata.category(char)
# Categories starting with 'C' are control characters, 'Z' are separators including spaces, 'M' are marks
if category.startswith(('C', 'Z', 'M')):
return False
return True

def generate_printable_unicode_list(length=16):
printable_unicode_chars = []

while len(printable_unicode_chars) < length:
# Generate a random Unicode code point
random_code_point = secrets.randbelow(0x110000) # Unicode range: 0 to 0x10FFFF

try:
char = chr(random_code_point)
if is_printable_unicode(char):
printable_unicode_chars.append(char)
except ValueError:
# If the code point is not a valid Unicode character, skip it
continue

return printable_unicode_chars

# Generate the list of printable Unicode characters
printable_unicode_chars = generate_printable_unicode_list()

# Print the resulting list of Unicode characters
print("".join(printable_unicode_chars))


Output:
ไฃขโฒ†๐ฌบ๏ฅฎ๐คป™๐คฐš็น๐žบ๐ฆผฉ๐คฆŸ้œๅกง๐ชตด๐ฎ บ๐ซ™Ÿ๐Ÿ˜Ž
your password can't be cracked if it doesn't contain anything that is expected in a password ๐Ÿ˜๐Ÿคจ
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘1
import math

# Constants
NANOSECONDS_IN_A_SECOND = 1_000_000_000
SECONDS_IN_A_YEAR = 60 * 60 * 24 * 365
NANOSECONDS_IN_A_YEAR = NANOSECONDS_IN_A_SECOND * SECONDS_IN_A_YEAR
MAX_YEARS = 30

# Initial value of nanoseconds
nanoseconds = 1

while True:
# Calculate the corresponding years for the current nanoseconds
years = nanoseconds / NANOSECONDS_IN_A_YEAR

# Check if the next doubling would exceed 30 years
if 2 * nanoseconds / NANOSECONDS_IN_A_YEAR >= MAX_YEARS:
break

# Double the nanoseconds
nanoseconds *= 2

# Print the results in scientific notation for nanoseconds and years with one decimal place
print(f"Nanoseconds milestone: {nanoseconds:.2e} ns")
print(f"Corresponding age in years: {years:.1f} years")

Output:
Nanoseconds milestone: 5.76e+17 ns
Corresponding age in years: 18.3 years
from datetime import datetime, timedelta

# Constants
NANOSECONDS_IN_A_SECOND = 1_000_000_000
SECONDS_IN_A_YEAR = 60 * 60 * 24 * 365
NANOSECONDS_IN_A_YEAR = NANOSECONDS_IN_A_SECOND * SECONDS_IN_A_YEAR

# Function to convert nanoseconds to a timedelta
def nanoseconds_to_timedelta(nanoseconds):
seconds = nanoseconds // NANOSECONDS_IN_A_SECOND
remaining_nanoseconds = nanoseconds % NANOSECONDS_IN_A_SECOND
return timedelta(seconds=seconds, microseconds=remaining_nanoseconds / 1000)

# Input birth datetime
birth_datetime_str = input("Enter your birth datetime (YYYY-MM-DD HH:MM:SS): ")
birth_datetime = datetime.strptime(birth_datetime_str, "%Y-%m-%d %H:%M:%S")

# Current datetime
current_datetime = datetime.now()

# Initial value of nanoseconds and milestones
nanoseconds = 1
previous_milestone = birth_datetime
next_milestone = birth_datetime

# Loop to find the next milestone after the current datetime
while True:
# Calculate the next potential milestone datetime
next_milestone = birth_datetime + nanoseconds_to_timedelta(nanoseconds)

# Check if the next milestone surpasses the current datetime
if next_milestone > current_datetime:
break

# Update the previous milestone and double the nanoseconds
previous_milestone = next_milestone
nanoseconds *= 2

# Output the results
print(f"Previous milestone: {previous_milestone} (nanoseconds: {nanoseconds//2:.2e} ns)")
print(f"\nNext milestone: {next_milestone} (nanoseconds: {nanoseconds:.2e} ns)")
Input:
1990-01-01 00:00:00

Output:
Previous milestone: 2008-04-07 23:59:12.303423 (nanoseconds: 5.76e+17 ns)

Next milestone: 2026-07-14 23:58:24.606847 (nanoseconds: 1.15e+18 ns)
Forwarded from davide
O(1) solution
import math as m
YOUR_AGE = 30
YEAR_NS = 1e9 * 60 * 60 * 24 * 365
MS_NS = 2 ** m.floor(m.log2(YOUR_AGE * YEAR_NS))
print(f"Your previous nanoseconds milestone was at {MS_NS / YEAR_NS:.2f} years, next one is at {MS_NS * 2 / YEAR_NS:.2f}")
๐Ÿ‘1
Forwarded from I Run Code
Language:
python


Code:
import datetime
import pytz
from collections import OrderedDict
from dateutil.relativedelta import relativedelta
import math as m
import time

class MilestoneCalculator:
def __init__(self, birthdate_str, timezone_str):
self.timezone = pytz.timezone(timezone_str)
self.birthdate_utc = pytz.utc.localize(datetime.datetime.strptime(birthdate_str, "%Y-%m-%d %H:%M:%S"))
self.birthdate_local = self.birthdate_utc.astimezone(self.timezone)

def convert_and_calculate_milestones(self, nanoseconds):
ns_per_microsecond = 1_000
ns_per_second = 1e9

seconds, remaining_ns = divmod(nanoseconds, ns_per_second)
timedelta_value = datetime.timedelta(seconds=seconds, microseconds=remaining_ns // ns_per_microsecond)

current_date = self.birthdate_local + timedelta_value
result = OrderedDict()

years = 0
while current_date >= self.birthdate_local + relativedelta(years=years + 1):
years += 1
result['y'] = years

months = 0
while current_date >= self.birthdate_local + relativedelta(years=years, months=months + 1):
months += 1
result['m'] = months

days = 0
while current_date >= self.birthdate_local + relativedelta(years=years, months=months, days=days + 1):
days += 1
result['d'] = days

delta = current_date - (self.birthdate_local + relativedelta(years=years, months=months, days=days))
hours, remainder = divmod(delta.seconds, 3600)
minutes, seconds = divmod(remainder, 60)

result.update({'H': hours, 'M': minutes, 'S': seconds, 'ms': delta.microseconds // 1_000,
'us': delta.microseconds % 1_000, 'ns': remaining_ns % 1_000})

return result, timedelta_value


def print_age_and_milestones(self):
current_time_local = datetime.datetime.now(pytz.utc).astimezone(self.timezone)
current_ns = time.time_ns()
age_ns = current_ns - int(self.birthdate_utc.timestamp() * 1e9)

age_details, _ = self.convert_and_calculate_milestones(age_ns)
age_str = ' '.join(f"{value}{key}" for key, value in age_details.items())

MS_NS = 2 ** (age_ns.bit_length() - 1)
previous_ns = MS_NS
next_ns = MS_NS * 2

prev_details, prev_timedelta = self.convert_and_calculate_milestones(previous_ns)
prev_date = self.birthdate_local + prev_timedelta
prev_date_str = prev_date.strftime("%Y-%m-%d %H:%M:%S.%f %Z")

next_details, next_timedelta = self.convert_and_calculate_milestones(next_ns)
next_date = self.birthdate_local + next_timedelta
next_date_str = next_date.strftime("%Y-%m-%d %H:%M:%S.%f %Z")

print(f"Current age in \"{self.timezone.zone}\":\n{age_str}\n\n"
f"Previous milestone: {prev_date_str} (nanosecond age: {previous_ns:.2e} ns)\n\n"
f"Next milestone: {next_date_str} (nanosecond age: {next_ns:.2e} ns)")

birthdate_str = "1990-01-01 00:00:00"
for timezone_str in ["Asia/Nicosia", "America/New_York"]:
calculator = MilestoneCalculator(birthdate_str, timezone_str)
calculator.print_age_and_milestones()
print("\n")


Output:
Current age in "Asia/Nicosia":
34y 7m 0d 10H 55M 39S 137ms 929us 344.0ns

Previous milestone: 2008-04-08 01:59:12.303423 EET (nanosecond age: 5.76e+17 ns)

Next milestone: 2026-07-15 01:58:24.606846 EET (nanosecond age: 1.15e+18 ns)


Current age in "America/New_York":
34y 7m 0d 10H 55M 39S 140ms 795us 520.0ns

Previous milestone: 2008-04-07 18:59:12.303423 EST (nanosecond age: 5.76e+17 ns)

Next milestone: 2026-07-14 18:58:24.606846 EST (nanosecond age: 1.15e+18 ns)
Forwarded from ("โ€Œ;(": GNU/std::sakty via @isakti_bot
Language:
python


Code:
print(chr(sum(range(ord(min(str(not())))))))


Output:
เถž
๐Ÿ‘€4โค2
Forwarded from Zac via @iruncode_bot
Language:
python


Code:
import unicodedata as ud
e="๐Ÿ’๐Ÿฝโ€โ™€๏ธ"
print(*[f"{x} ({x.encode('unicode-escape').decode('utf8')}): {y}" for y,x in zip(map(ud.name, [*e]), [*e])],sep="\n")


Output:
๐Ÿ’ (\U0001f481): INFORMATION DESK PERSON
๐Ÿฝ (\U0001f3fd): EMOJI MODIFIER FITZPATRICK TYPE-4
โ€ (\u200d): ZERO WIDTH JOINER
โ™€ (\u2640): FEMALE SIGN
๏ธ (\ufe0f): VARIATION SELECTOR-16
Forwarded from I Run Code
Language:
python


Code:
import datetime

current_time_str = "01:15"
start_cycle = 3
end_cycle = 6
sleep_latency = 20
cycle_length = 90

current_time = datetime.datetime.strptime(current_time_str, "%H:%M")
start_time = current_time + datetime.timedelta(minutes=sleep_latency)

for N in range(start_cycle, end_cycle + 1):
alarm_time = start_time + datetime.timedelta(minutes=N * cycle_length)
alarm_time_str = alarm_time.strftime("%H:%M")
print(f"Cycle#: {N}, Alarm Set: {alarm_time_str}")


Output:
Cycle#: 3, Alarm Set: 06:05
Cycle#: 4, Alarm Set: 07:35
Cycle#: 5, Alarm Set: 09:05
Cycle#: 6, Alarm Set: 10:35
It worked :D
Forwarded from Zac via @iruncode_bot
Language:
python


Code:
votes = [1, 1, 4]
weight = 100/max(sum(votes),1)
percs = [f"{x*weight:.2f}%" for x in votes]
print(percs)


Output:
['16.67%', '16.67%', '66.67%']
Forwarded from Zac via @iruncode_bot
Language:
python


Code:
def p(prec):
votes = [1, 1, 4]
weight = 100/max(sum(votes),1)
percs = [f"{x*weight:.{prec}f}%" for x in votes]
print(percs)
print(sum([float(x[:-1]) for x in percs]))
p(3);p(2);p(1);p(0)


Output:
['16.667%', '16.667%', '66.667%']
100.001
['16.67%', '16.67%', '66.67%']
100.01
['16.7%', '16.7%', '66.7%']
100.1
['17%', '17%', '67%']
101.0
Zac
Language: py3 Source: from datetime import datetime,timedelta import math p,m="โ–“","โ–‘" n=datetime.now() st,en=datetime(n.year,1,1), datetime(n.year+1,1,1)-timedelta(days=1) tot,el=en-st,n-st pe=(el/tot)*100 elp=int(math.ceil(pe)*0.17) print(p*elp,m*(17-elp)โ€ฆ
Language:
python

Code:
from datetime import*;D=datetime;n=D.now();print(n);a=D(y:=n.year,1,1);x=(n-a)/(D(y+1,1,1)-a);i=-int(-17*x);print('โ–“'*i+'โ–‘'*(17-i),'%d%%'%(x*100))

Output:
2026-08-23 06:10:57.111380
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 64%