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
| //! Leveraging tuples to make a statically typed, concatenative EDSL in Rust. | |
| //! | |
| //! I'm not sure how practical it really is – Rust's syntax can make it a little | |
| //! hard to read, but it's fun to play around with it. The neat thing is how | |
| //! little copying occurs. Everything is moved in and out by-value in a pipeline. | |
| //! | |
| //! Thanks goes to [Tekmo on reddit](http://www.reddit.com/r/programming/ | |
| //! comments/1zzom4/using_functionlength_to_implement_a_stack_language/cfyibsr) | |
| //! for the idea. | |
| //! |
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
| module AsyncAwait | |
| class Task < NSOperation | |
| def self.new(&block) | |
| alloc.initWithBlock(block) | |
| end | |
| def initWithBlock(block) | |
| init.tap 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
| /// Phantom type for step 1. | |
| pub enum Step1 {} | |
| /// Phantom type for step 2. | |
| pub enum Step2 {} | |
| /// Contains data we set step by step. | |
| pub struct Data<'a> { | |
| /// 'a' is set in the first step. | |
| a: Option<int>, |
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
| # Copyright (c) 2013 Joe Noon (https://github.com/joenoon) | |
| # | |
| # 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 | |
| # furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in |
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
| fn main() { | |
| do RoutedServer::serve |config, router| { | |
| config.listen("127.0.0.1", 1337); | |
| router.get("/hello", |_,res| res.write("hello world")); | |
| router.get("/posts/:id", |req,res| { | |
| res.write(format!("post {}", req.params["id"])) | |
| }); | |
| } |
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
| // Asynchronously loads UIImages from the given URLs, but throttles the loading | |
| // to keep memory and CPU usage sane. | |
| - (RACSignal *)loadImagesAtURLs:(NSArray *)imageURLs { | |
| // Map each URL to a signal of work. The result is a signal of work signals. | |
| return [[imageURLs.rac_signal | |
| map:^(NSURL *imageURL) { | |
| return [[[[NSURLConnection | |
| // Load the URL asynchronously. | |
| rac_sendAsynchronousRequest:[NSURLRequest requestWithURL:imageURL]] | |
| reduceEach:^(NSURLResponse *response, NSData *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
| # This one! | |
| def viewNamed(view_name, ofClass: class_reference) | |
| var_name = view_name[0].downcase + view_name[1, view_name.length - 1].gsub(/\s/, '') | |
| instance_variable_get("@#{var_name}") or instance_variable_set("@#{var_name}", class_reference.new).tap do |view| | |
| view.accessibilityLabel = view_name | |
| yield view if block_given? | |
| end | |
| end |
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
| totalCombinedViewHeight = 100 | |
| Motion::Layout.new do |layout| | |
| layout.view view | |
| layout.subviews "state" => @state, "action" => @action | |
| layout.metrics "margin" => 20, "height" => 40, "halfHeight" => ((view.bounds.size.height - totalCombinedViewHeight) / 2), "halfWidth" => ((view.bounds.size.width - 100) / 2) | |
| layout.vertical "|-(<=halfHeight)-[state]-margin-[action]-(>=halfWidth)-|" | |
| layout.horizontal "|-margin-[state]-margin-|" | |
| layout.horizontal "|-margin-[action]-margin-|" | |
| end |
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
| + (NSDictionary *)downloadableFonts | |
| { | |
| CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)@{(id)kCTFontDownloadableAttribute : (id)kCFBooleanTrue}); | |
| CFArrayRef matchedDescs = CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL); | |
| NSArray *array = (__bridge NSArray *)matchedDescs; | |
| NSMutableDictionary *families = [NSMutableDictionary dictionary]; | |
| for (UIFontDescriptor *fontDescriptor in array) { | |
| NSString *familyName = fontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute]; |

