Skip to content

Instantly share code, notes, and snippets.

@trszdev
trszdev / RegexGroup.swift
Last active June 14, 2023 15:55
Allows convenient navigation between capture groups for NSRegularExpression
import Foundation
public final class RegexGroup: CustomDebugStringConvertible {
public internal(set) var subgroups = [RegexGroup]()
public internal(set) var value = Substring()
func contains(range: Range<String.Index>) -> Bool {
return range.lowerBound >= value.startIndex && range.upperBound <= value.endIndex
}
@trszdev
trszdev / AnyObservableObject.swift
Last active April 15, 2022 20:15
ViewModel behind protocol (2 approaches)
import SwiftUI
import Combine
// Protocol 'NonConstrainedViewModel' can only be used as a generic constraint
// because it has Self or associated type requirements
protocol NonConstrainedViewModel: ObservableObject {
var state: Int { get set }
var statePublished: Published<Int> { get }
var statePublisher: Published<Int>.Publisher { get }
func increase()
@trszdev
trszdev / Package.swift
Last active February 19, 2022 14:52
Package.swift boilerplate
// swift-tools-version:5.5
import PackageDescription
var package = Package(
name: "App",
defaultLocalization: "en",
platforms: [.iOS(.v14)]
)
// MARK: - Dependencies
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>kgg</title>
<style>
body {
display: flex;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Penrose P3</title>
<style>
body {
padding: 0;
@trszdev
trszdev / cube_rotate.html
Created June 22, 2019 21:15
HTML/CSS - 3D Cube rotate animation (https://jsfiddle.net/Lb3q9cr7/)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>3D Cube rotate animation</title>
<style>
.global {
background: yellow;
@trszdev
trszdev / center.html
Last active June 22, 2019 18:33
CSS - Center inline-block element both vertically and horizontally (https://jsfiddle.net/r9hn4a0L/)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Centering text</title>
<style>
.outer {
width: 300px;
@trszdev
trszdev / payment.html
Last active June 22, 2019 18:33
HTML/CSS/JS - payment page with input masking and native form validation (https://jsfiddle.net/pu57Lns8/1/)
<!--
Minimal example of payment page with input masking and native form validation
https://jsfiddle.net/pu57Lns8/1/
One of the caveats in this example maybe using "minlength" attribute while changing input value programmatically:
this won't check real validity.
From html5 spec (minlength attribute): If an element has a minimum allowed value length, its dirty value flag is true,
VALUE WAS LAST CHANGED BY A USER EDIT (AS OPPOSED TO A CHANGE MADE BY A SCRIPT),
@trszdev
trszdev / competitive.py
Created April 27, 2019 21:36
python competitive programming template for pytest
from sys import *
def main(cin, cout):
a, b = map(int, cin.readline().split())
cout.write(str(a + b))
def get_main_output(input_str):
from io import StringIO
@trszdev
trszdev / logmorpher.py
Last active April 27, 2019 20:39
1C .lgd log changer
"""
> python logmorpher.py 1Cv8.lgd 14
Для запуска необходим python3.6+
Скрипт для изменения .lgd логов 1С:
* смещает даты на указанное количество дней и случайное количество секунд
* заменяет все компьютеры и пользователей на текущих
* изменяет идентикаторы сессий и транзакций на случайные
Перед отправкой изменненой базы преподавателю рекомендуется стереть временные файлы 1C (пустые папки и файлы),