Skip to content

Instantly share code, notes, and snippets.

View valeriyvan's full-sized avatar
🇺🇦
in Armed Forces of Ukraine since 3 of March 2022

Valeriy Van valeriyvan

🇺🇦
in Armed Forces of Ukraine since 3 of March 2022
  • B̵e̵r̵l̵i̵n̵/̵O̵d̵e̵s̵a̵ somewhere in Ukraine
View GitHub Profile
@valeriyvan
valeriyvan / install-swift.sh
Last active October 17, 2023 09:56 — forked from vzsg/install-swift.sh
Bash script to install Swift 5.9 on Ubuntu 22.04
#!/bin/bash
if [ -f "/opt/swift/bin/swift" ]; then
echo ====== Swift is already installed at /opt/swift, exiting!
exit 1
fi
for i in "$@"
do
case $i in
import Foundation
import CommonCrypto
extension Data {
enum Algorithm {
case md5
case sha1
case sha224
case sha256
case sha384
import Foundation
// One drawback of using callbacks vs delegation in Swift - if method is used
// instead of closure for callback, retain cycle is created.
// And this retain cycle can't be broken with usual weak/unowned capture.
// In case of delegate everyone knows that delegate property should be weak,
// and linter enforces this.
// Callbacks are nice. But you can't enforce only closures to be used for callbacks.
@valeriyvan
valeriyvan / change.swift
Last active September 5, 2020 14:41
Solution for change-making problem (a.k.a. vending machine change problem)
import Foundation
// Change making problem https://en.wikipedia.org/wiki/Change-making_problem.
// Solution for change-making problem (a.k.a. vending machine change problem).
// Greedy algorythm going from bigger denominations.
// Fails for changeGreedy(60, from: [50:10, 20:10])
// More tests on bottom.
@valeriyvan
valeriyvan / SPM:Article:Generate.sh
Last active March 4, 2019 13:26 — forked from dive/SPM:Article:Generate.sh
SPM:Article:Generate
swift package generate-xcodeproj --xcconfig-overrides ./Sources/ios.xcconfig
@valeriyvan
valeriyvan / FizzBuzz.swift
Last active November 13, 2018 18:11
FizzBuzz in Swift
#!/usr/bin/swift
import Foundation
// Write a program that prints the numbers from 1 to 100.
// But for multiples of three print ‘Fizz’ instead of the number and for the multiples of five print ‘Buzz’.
// For numbers which are multiples of both three and five print ‘FizzBuzz’.
for i in 1...100 {
switch i {
@valeriyvan
valeriyvan / xcode-icon-tag.sh
Created March 19, 2018 23:59 — forked from valeriomazzeo/xcode-icon-tag.sh
Xcode Icon Version Overlay
# xcode-icon-tag.sh
# The MIT License (MIT)
#
# Copyright (c) <2015> <Valerio Mazzeo>
# Permission is hereby granted, free of charge, to any person obtaining a copy
#
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@valeriyvan
valeriyvan / pickleViewer.py
Created February 13, 2017 13:10 — forked from mcitron/pickleViewer.py
Viewer for arbitrary pickle files
#!/usr/bin/python
import pickle
from collections import defaultdict
from collections import OrderedDict
import sys
def checkDict(inputData):
return (type(inputData) == dict or type(inputData) == defaultdict\
or type(inputData) == OrderedDict)
@valeriyvan
valeriyvan / MinMaxCoordinates.swift
Last active December 13, 2021 11:30
Lookup for min/max latitude/longitude with one pass on array with the only reduce call
// Having array of coordinates you would like show on map you have calculate center and span for map.
// For that you need min/max latitude/longitude of coordinates.
let coordinates = [(CLLocationCoordinate2D(latitude:-40.0, longitude:38.2)),
(CLLocationCoordinate2D(latitude:44.2, longitude:17.833)),
(CLLocationCoordinate2D(latitude:5.22, longitude:154.2)),
(CLLocationCoordinate2D(latitude:33.2, longitude:9.2)),
(CLLocationCoordinate2D(latitude:4.2, longitude:3.2))]
// Lookup is done with one pass on array with only reduce
@valeriyvan
valeriyvan / DMSToDecimal
Last active August 19, 2019 12:35
Geographic coordinate conversion from NSString in DMS format into decimal in CLLocationDegrees (aka double).http://en.wikipedia.org/wiki/Geographic_coordinate_conversion43° 36' 15.894" N => 43.60442
// http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
// 43° 36' 15.894" N => 43.60442
#import "DMSToDecimal.h"
BOOL DMSToDecimal(NSString* dms, CLLocationDegrees *decimal) {
CLLocationDegrees degres=0, minutes=0, seconds=0;
NSScanner *scanner = [NSScanner scannerWithString:dms];
scanner.charactersToBeSkipped = [NSCharacterSet whitespaceAndNewlineCharacterSet];
if (![scanner scanDouble:&degres]) {