(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// Takes a credit card string value and returns true on valid number | |
function valid_credit_card(value) { | |
// Accept only digits, dashes or spaces | |
if (/[^0-9-\s]+/.test(value)) return false; | |
// The Luhn Algorithm. It's so pretty. | |
let nCheck = 0, bEven = false; | |
value = value.replace(/\D/g, ""); | |
for (var n = value.length - 1; n >= 0; n--) { |
#!/bin/bash | |
# Shell script to be executed on a Mavericks Server runing Xcode Server using sudo | |
BOTRUN_DATA=/Library/Server/Xcode/Data/BotRuns | |
LATEST_RUN=`ls -tr $BOTRUN_DATA | grep BotRun- | tail -n1` | |
tail -f ${BOTRUN_DATA}/${LATEST_RUN}/output/build.log |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
Modern Cocoa development involves a lot of asynchronous programming using blocks and NSOperations. A lot of APIs are exposing blocks and they are more natural to write a lot of logic, so we'll only focus on block-based APIs.
Block-based APIs are hard to use when number of operations grows and dependencies between them become more complicated. In this paper I introduce asynchronous semantics and Promise type to Swift language (borrowing ideas from design of throw-try-catch and optionals). Functions can opt-in to become async, programmer can compose complex logic involving asynchronous operations while compiler produces necessary closures to implement that logic. This proposal does not propose new runtime model, nor "actors" or "coroutines".
// | |
// AppNotify.swift | |
// | |
// Created by Christopher Bess on 6/30/15. | |
// MIT License | |
// | |
import Foundation | |
/// Represents the app notification. |
extension Array where Element: Comparable { | |
func clamp(from lowerBound: Element, to upperBound: Element) -> Array { | |
return self.map { min(upperBound, max(lowerBound, $0)) } | |
} | |
} | |
let clamped = [0, 1, 2, 3, 4, 5, 6].clamp(from: 2, to: 4)) |