Skip to content

Instantly share code, notes, and snippets.

# %%
"""
Standalone example using obstore to list and download parquet files from the Unravel data bucket.
Path structure:
bucket/metric_type/timestamp_type/interval/exchange=exchange/symbol=symbol/year=year/month=month.parquet
Requirements: obstore, polars
"""
let pan = UIPanGestureRecognizer()
let pinch = UIPinchGestureRecognizer()
let panStarted = pan.rx_event.filter { $0.state == .Began }
let panEnded = pan.rx_event.filter { $0.state == .Ended }
let pinchStarted = pinch.rx_event.filter { $0.state == .Began }
let pinchEnded = pinch.rx_event.filter { $0.state == .Ended }
// condition: when both pan and pinch ended
var panPresent = false
var pinchPresent = false
var gestureTimer: NSTimer?
var secondsLeft = 3
func handlePan(panGesture: UIPanGestureRecognizer) {
if panGesture.state == .Began && self.panPresent == false {
self.panPresent = true
self.checkIfBothGesturesPresent()
} else if panGesture.state == .Ended {
let pan = UIPanGestureRecognizer()
let pinch = UIPinchGestureRecognizer()
// Here, we want to create a signal that emits an event when the
// gesture has started.
// We can call .rx_event on UIPangestureRecognizer, and
// transform it's output into a signal, which then
// We can use filter to discard all other events!
@almostintuitive
almostintuitive / gist:0534e7e8329a7f9b3ca0
Created November 28, 2015 20:12
Imperative vs. FRP swift performance
func test1Imperative() {
class Counter {
var count: Int = 0 {
didSet {
realCount = count+1
}
}
var realCount: Int = 0
}
@almostintuitive
almostintuitive / NSHashTable+SequenceType.swift
Created September 19, 2015 18:33
Use NSHashTable with for .. in .. style enumeration with Swift2 (safely)
extension NSHashTable: SequenceType {
public func generate() -> AnyGenerator<AnyObject> {
var array = self.allObjects
var nextIndex = array.count-1
return anyGenerator {
if (nextIndex < 0) {
return nil
@almostintuitive
almostintuitive / SwipeToPeepCell-5.m
Created August 30, 2014 13:23
SwipeToPeepCell-5.m
- (void)changeBackgroundColorBasedOnProgress:(float)progress {
self.interactiveBackground.alpha = progress;
}
- (void)didMoveToSuperview {
self.interactiveBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.bounds.size.height)];
self.interactiveBackground.backgroundColor = [UIColor flatGrayColor];
self.interactiveBackground.alpha = 0;
[self insertSubview:self.interactiveBackground atIndex:0];
@almostintuitive
almostintuitive / ViewController-5.m
Created August 30, 2014 13:23
ViewController-5.m
- (void)adjustViewBasedOnSwipeProgress:(float)progress {
self.tableView.spring.alpha = progress;
self.tableView.spring.center = CGPointMake(self.view.center.x*progress, self.view.center.y);
self.postWebView.spring.center = CGPointMake(self.view.center.x+(self.view.bounds.size.width*progress), self.view.center.y);
}
@almostintuitive
almostintuitive / SwipeToPeepCell-4.m
Created August 30, 2014 13:22
SwipeToPeepCell-4.m
if (velocity.x > 0) {
return NO;
}
@almostintuitive
almostintuitive / ViewController-4.m
Created August 30, 2014 13:21
ViewController-4.m
- (void)swipeableCell:(SwipeToPeepCell *)cell didSwipeWithHorizontalPosition:(CGFloat)horizontalPosition progress:(float)progress {
self.tableView.scrollEnabled = NO;
[self adjustViewBasedOnSwipeProgress:(1-progress)];
}