Skip to content

Instantly share code, notes, and snippets.

View potat-dev's full-sized avatar
🥔
Котик крутится, лабы мутятся

Denis Churilov potat-dev

🥔
Котик крутится, лабы мутятся
View GitHub Profile
@potat-dev
potat-dev / smart_rename.py
Created February 10, 2022 21:07
Функция "Умного переименования" файлов
def smart_rename(file):
# renames a file by adding a numeric index to it
# increments the index if the directory already has files with the index
regex = r'(.+)_\((\d+)\)\.(.+)' # filename_(0).ext
make_filename = lambda p: p[0] + f"_({p[1]})." + p[2]
filename, path = os.path.basename(file), os.path.dirname(file)
match = match_regex(regex, filename)
parts = list(match.groups())[::2] if match else filename.split('.')
parts.insert(1, int(match.group(2)) if match else 0)
new_path = os.path.join(path, make_filename(parts))
@potat-dev
potat-dev / is_prime.cpp
Created February 13, 2022 02:20
Primality test in C++
int is_prime(int n) {
if (n < 3) return (n == 2);
if (~n & 1) return 0;
for (int i = 3; i*i <= n; i += 2)
if (n % i == 0) return 0;
return 1;
}
@potat-dev
potat-dev / main.c
Created May 28, 2022 10:11 — forked from Mashpoe/main.c
ASCII Tesseract Rotation C Program
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <windows.h>
// width and height of screen
#define ww 100
#define wh 50
void clr(CHAR_INFO* d)
# вычисляет хэш нескольких файлов
from hashlib import md5
def files_hash(files):
temp = md5()
for file in tqdm(files, desc="calculating files hash"):
with open(file, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
temp.update(chunk)
return temp.hexdigest()
@potat-dev
potat-dev / index.html
Created July 15, 2022 12:01
Masonry - stagger option, vanilla JS
<h1>Masonry - stagger option, vanilla JS</h1>
<p>Resize window or click to toggle item size</p>
<div class="grid">
<div class="grid-item"></div>
<div class="grid-item grid-item--width2 grid-item--height2"></div>
<div class="grid-item grid-item--height3"></div>
<div class="grid-item grid-item--height2"></div>
<div class="grid-item grid-item--width3"></div>
@potat-dev
potat-dev / CustomModal.js
Created July 27, 2022 19:41
Modal that closes when clicked outside, goes bottom on mobile screen and goes middle on desktop
<!-- The button to open modal -->
<label for="my-modal" class="btn modal-button">open modal</label>
<input type="checkbox" id="my-modal" class="modal-toggle" />
<label for="my-modal" class="modal modal-bottom sm:modal-middle">
<label class="modal-box">
<h3 class="font-bold text-lg">Congratulations random Internet user!</h3>
<p class="py-4">You've been selected for a chance to get one year of subscription to use Wikipedia for free!</p>
<div class="modal-action">
<label for="my-modal" class="btn">Yay!</label>
def commentify(text, start, end, width=32, fill="="):
content = f' {text} '.center(width - len(start) - len(end) - 2, fill)
return f'{start} {content} {end}'
while True:
text = input('Enter text: ')
if not text:
break
print(commentify(text.upper(), '//', '//', width=42))
@potat-dev
potat-dev / hello-emoji.cpp
Created September 4, 2022 22:11 — forked from abusse/hello-emoji.cpp
Some C++ Emoji fun found on the internet. Compiles (currently) only with clang (sorry GCC) and C++11.
#include <iostream>
#include <vector>
#include <cstdlib>
namespace 🔵 = std;
using 🔢 = int;
using 💯 = unsigned;
using 💀 = void;
using 🕖 = time_t;
using 👌 = bool;
@potat-dev
potat-dev / launch.json
Created September 28, 2022 23:36
VS Code MinGW g++ debug tasks
{
"version": "0.2.0",
"configurations": [
{
"name": "build file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/compile/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
@potat-dev
potat-dev / table.cpp
Last active November 4, 2022 01:56
Template function to pretty print table in C++
// template function to print table
template <typename T>
void ptable(vector<vector<T>> table, int axis_offset = 0, int split = 10,
int tab_size = 8, int index_width = 3, bool round_val = false) {
int rows = table.size();
int splitted_parts = rows / split + (rows % split != 0);
for (int table_n = 0; table_n < splitted_parts; table_n++) {
int columns = min(split, (int)rows - table_n * split);
cout << setw(index_width + 3) << " | ";
for (int i = 0; i < columns; i++) {