This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import CommonCrypto | |
extension Data { | |
enum Algorithm { | |
case md5 | |
case sha1 | |
case sha224 | |
case sha256 | |
case sha384 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swift package generate-xcodeproj --xcconfig-overrides ./Sources/ios.xcconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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:°res]) { |