Skip to content

Instantly share code, notes, and snippets.

View werediver's full-sized avatar
💭
🦀

Raman Fedaseyeu werediver

💭
🦀
View GitHub Profile
@werediver
werediver / BasicServiceLocator.swift
Last active January 14, 2019 06:13
Basic Service Locator pattern implementation in Swift 2.
protocol ServiceLocator {
func getService<T>() -> T?
}
final class BasicServiceLocator: ServiceLocator {
// Service registry
private lazy var reg: Dictionary<String, Any> = [:]
private func typeName(some: Any) -> String {
/// Cast the argument to the infered function return type.
func autocast<T>(some: Any) -> T? {
return some as? T
}
protocol Foo {
static func foo() -> Self
}
class Vehicle: Foo {
@werediver
werediver / LazyServiceLocator.swift
Last active March 18, 2020 10:32
Service Locator pattern implementation in Swift 2 with lazy (on demand) service initialization.
protocol ServiceLocator {
func getService<T>() -> T?
}
final class LazyServiceLocator: ServiceLocator {
/// Registry record
enum RegistryRec {
case Instance(Any)
@werediver
werediver / ViewTransition.swift
Last active July 8, 2020 10:19
View Transition mechanism for MVVM pattern (Swift, iOS)
import UIKit
// MARK: - Specification
protocol ViewType {
associatedtype ViewModel: ViewModelType
var viewModel: ViewModel { get }
@werediver
werediver / resample_rlen.vex
Created October 10, 2020 15:22
Houdini VEX code to resample a (two point) curve into segments of random length (with restrictions)
// Resample into segments of random length
// Run over primitives
float seed = chf("seed");
float seg_len_min = chi("seg_len_min");
float seg_len_max = chi("seg_len_max");
float seg_padding = chf("padding");
if (seg_len_min <= 0 || seg_len_max < seg_len_min || seg_padding < 0) {
error("Make sure 0 < seg_len_min <= seg_len_max and 0 <= seg_padding");
@werediver
werediver / CircularQueue.h
Created August 22, 2014 11:45
Simple implementation of circular queue in Objective-C (for ARC-enabled environment).
//
// CircularQueue.h
//
// Created on 9/21/13.
//
#import <Foundation/Foundation.h>
@interface CircularQueue : NSObject <NSFastEnumeration>
@werediver
werediver / WiFiSsid.swift
Created July 14, 2016 12:47
Get the connected Wi-Fi network SSID on iOS (in Swift).
import Foundation
import SystemConfiguration.CaptiveNetwork
func getWiFiSsid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break
@werediver
werediver / default.yaml
Last active February 18, 2022 13:33
Lima/Podman configuration allowing connections to ports 80, 443 through non-loopback interfaces
# Based on https://github.com/lima-vm/lima/blob/943c90b13e38be32777b8f25be17c2491bb1421f/examples/podman.yaml
#
# Allows connections to ports 80, 443 through non-loopback interfaces.
# Example to use Podman instead of containerd & nerdctl
# $ limactl start ./podman.yaml
# $ limactl shell podman podman run -it -v $HOME:$HOME --rm docker.io/library/alpine
# To run `podman` on the host (assumes podman-remote is installed):
# $ export CONTAINER_HOST=$(limactl list podman --format 'unix://{{.Dir}}/sock/podman.sock')
void main() async {
await variant1();
variant2();
print("xxx");
}
Future<void> variant1() async {
final result = await y();
// async gap
print("y: $result");
@werediver
werediver / main.dart
Last active November 1, 2022 14:00
Container types and the `map()` function in Dart
void main() {
print(f(true).map((value) => value + 1));
print(f(false).map((value) => value + 1));
print([1, 2, 3].map((value) => "x ${value + 1}"));
print([].map((value) => value + 1));
}
// Methods like
// map, flatMap / expand, filter / where, firstWhere, reduce, fold