This file contains hidden or 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
URLSession.shared.dataTaskPublisher(for: URL(string: BASE_URL + filename)!) | |
.flatMap { data, response in | |
let httpURLResponse = response as! HTTPURLResponse | |
switch httpURLResponse.statusCode { | |
case 404: | |
return Just("Unable to find file").eraseToAnyPublisher() | |
case (300..<399): | |
// this is a function that returns a publisher - it can make network requests, whatever | |
return processRedirect(data) |
This file contains hidden or 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 loadWebResource(_ path: String) -> AnyPublisher<Resource, Error> | |
func decodeImage(_ r1: Resource, _ r2: Resource) -> AnyPublisher<Image, Error> | |
func dewarpAndCleanupImage(_ i : Image) -> AnyPublisher<Image, Error> | |
func processImageData1() -> AnyPublisher<Image, Error> { | |
loadWebResource("dataprofile.txt").zip(loadWebResource("imagedata.txt")).flatMap { (dataResource, imageResource) in | |
decodeImage(dataResource, imageResource) | |
} | |
.flatMap { imageTmp in | |
dewarpAndCleanup(imageTmp) |
This file contains hidden or 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
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
self.window.backgroundColor = [UIColor whiteColor]; | |
[self.window makeKeyAndVisible]; | |
UITabBarController* tabController = [[UITabBarController alloc] init]; |
This file contains hidden or 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 actors.Futures | |
class DataflowFuture[A] private(f : => A) { | |
val future = Futures.future(f) | |
} | |
object DataflowFuture { | |
def apply[A](f : => A) = new DataflowFuture[A](f) | |
implicit def dataflowFutureToVal[A](df : DataflowFuture[A]) : A = df.future.apply() |
This file contains hidden or 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 actors.Futures.future | |
object PoorMansDataflow { | |
def main(args : Array[String]) { | |
// .... | |
val pastSales = future(db.getTotalSales) | |
val todaysSales = future(input.map(parseReport(_)).sumBy(_.totalSold)) |
This file contains hidden or 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
function rm () { | |
local path | |
for path in "$@"; do | |
# ignore any arguments | |
if [[ "$path" = -* ]]; then : | |
else | |
local dst=${path##*/} | |
# append the time if necessary | |
while [ -e ~/.Trash/"$dst" ]; do |
This file contains hidden or 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.createServer(function (request, response) { | |
var uri = url.parse(request.url).pathname; | |
if(uri=='/pong') { | |
response.writeHead(200, {'Content-Type': 'text/plain'}); | |
response.end('PONG'); | |
} else if ((match = uri.match(/^\/echo\/(.*)$/)) != null) { | |
response.writeHead(200, {'Content-Type': 'text/plain'}); | |
response.end(match[1]); |
This file contains hidden or 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 Data.Char (isSpace) | |
trim :: String -> String | |
trim = trimAndReverse . trimAndReverse | |
where trimAndReverse = reverse . dropWhile isSpace | |
reverseBreak :: (a -> Bool) -> [a] -> ([a], [a]) | |
reverseBreak f xs = (reverse before, reverse after) | |
where (after, before) = break f $ reverse xs |