Skip to content

Instantly share code, notes, and snippets.

View alexdremov's full-sized avatar
🥑
study

Aleksandr Dremov alexdremov

🥑
study
View GitHub Profile
@alexdremov
alexdremov / SnapCarousel.swift
Last active August 11, 2021 11:18
Swift remastered minimal snap carousel View
//
// SnapCarousel.swift
// Spontanea
//
// Created by  Alex Dremov on 10.08.2021.
//
import Foundation
import SwiftUI
class Foo {
let bonkProvider: () -> DBConnection
lazy var bonk: DBConnection = bonkProvider()
init(_ expression: @escaping @autoclosure () -> DBConnection) {
self.bonkProvider = expression
}
func send() {
// Here bonkProvider() is called
// only for the first call of send()
bonk.sendMessage()
@alexdremov
alexdremov / node_definition.cpp
Created April 22, 2022 11:42
Treap Alex Dremov implementation
template<typename T>
struct Node {
T key;
size_t prior;
Node* left = nullptr, *right = nullptr;
Node(T key, size_t prior) :
key(std::move(key)),
prior(prior) {
}
Node* find(Node* node, const T& key) {
if (node == nullptr)
return nullptr;
if (node->key == key)
return node;
return find(key >= node->key ? node->right : node->left, key);
}
Sequence 1 Sequence 2 Result
1 1
4 4
2 2
3 3
import enum Accelerate.vDSP
struct AnimatableVector: VectorArithmetic {
var values: [Float]
static var zero = AnimatableVector(values: [0.0])
static func + (lhs: AnimatableVector, rhs: AnimatableVector) -> AnimatableVector {
let count = min(lhs.values.count, rhs.values.count)
return AnimatableVector(
class MyThread: Thread {
override func main() { // Thread's starting point
print("Hi from thread")
}
}
let thread = MyThread()
thread.start()
let data = [
(text: "Nice", subtext: "Onborading sequence of screens"),
(text: "OK", subtext: "But how to do it with SwiftUI?"),
(text: "So that", subtext: "it is nice and shiny"),
]
let typeCommon: PathPresenter.PathType =
.animated(
transition: .asymmetric(
insertion: .move(edge: .trailing),
ColumnsLayout(columnsNumber: 2) {
VStack {
Text("That's one view")
Image(systemName: "tortoise.fill")
}
.padding()
.border(.red)
Text("That's the second view ")
.padding()
.border(.red)
@alexdremov
alexdremov / Project.swift
Last active October 7, 2022 12:38
Tuist example project snippets
import ProjectDescription
import ProjectDescriptionHelpers
let project = Project(
name: Feature.Foo.rawValue,
targets: [
.feature(
implementation: .Foo,
dependencies: [
.feature(interface: .Biz),