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
defmodule MyApp.Scheduler do | |
@moduledoc """ | |
Schedules a Mix task to be run at a given interval in milliseconds. | |
## Options | |
- `:task`: The name of the Mix task to run. | |
- `:args`: A list of arguments to pass to the Mix task's `run/1` function. | |
- `:interval`: The time interval in millisconds to rerun the task. |
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
defmodule MyApp.Scheduler do | |
@moduledoc """ | |
Schedules a Mix task to be run at a given interval in milliseconds. | |
## Options | |
- `:task`: The name of the Mix task to run. | |
- `:args`: A list of arguments to pass to the Mix task's `run/1` function. | |
- `:interval`: The time interval in millisconds to rerun the task. |
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
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
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
#user nobody; | |
#Defines which Linux system user will own and run the Nginx server | |
worker_processes 1; | |
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores. | |
#error_log logs/error.log; #error_log logs/error.log notice; | |
#Specifies the file where server logs. |
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
extension NSObject { | |
func addObserver <RawType: RawRepresentable where RawType.RawValue == String>(observer: NSObject, forKeyPath keyPath: RawType, options: NSKeyValueObservingOptions, context: UnsafeMutablePointer<Void>) { | |
addObserver(observer, forKeyPath: keyPath.rawValue, options: options, context: context) | |
} | |
func removeObserver <RawType: RawRepresentable where RawType.RawValue == String>(observer: NSObject, forKeyPath keyPath: RawType) { | |
removeObserver(self, forKeyPath: keyPath.rawValue) | |
} | |
func removeObserver <RawType: RawRepresentable where RawType.RawValue == String>(observer: NSObject, forKeyPath keyPath: RawType, context: UnsafeMutablePointer<Void>) { |
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
// Extensions of Int and String for converting to and from Roman and Arabic digits and | |
// checking to see if a given Roman numeral String is valid. Only designed to work in | |
// the range [0, 3999]. Output given from outside of this range will not be correct. | |
// | |
// Created by Michael MacCallum | |
// CC0 License | |
public extension Int { | |
public func toRoman() throws -> String { | |
guard 0..<4000 ~= self else { |
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
struct FizzBuzzGenerator: SequenceType { | |
private let bounds: Range<Int> | |
func generate() -> AnyGenerator<String> { | |
var current = bounds.startIndex | |
return anyGenerator { | |
guard current < self.bounds.endIndex else { | |
return nil | |
} |
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
func recursiveFlatmap<T, U: AnyObject>(list: [U]) -> [T] { | |
var results = [T]() | |
results.reserveCapacity(list.count) | |
for element in list { | |
if let subList = element as? [U] { | |
results += recursiveFlatmap(subList) | |
} else if let element = element as? T { | |
results.append(element) | |
} |
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
extension NSObject { | |
class func isStrictSubclassOfClass(aClass: AnyClass) -> Bool { | |
return isSubclassOfClass(aClass) && self !== aClass.self | |
} | |
class func isStrictSuperclassOfClass(aClass: AnyClass) -> Bool { | |
return isSuperclassOfClass(aClass) && self !== aClass.self | |
} | |
class func isSuperclassOfClass(aClass: AnyClass) -> Bool { |
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
// Simple factorial generator. Doesn't handle numbers that overflow Int or the 0! = 1 case. | |
// Swift 2 | |
let num = (1...17).reduce(1, combine: *) // 355687428096000 | |
// Swift 1.x | |
let num = reduce(1...17, 1, *) // 355687428096000 | |
NewerOlder