Skip to content

Instantly share code, notes, and snippets.

@tonisuter
tonisuter / gist:155f057edb3d2b4baecf
Last active August 29, 2015 14:11
Pipe & Stages with varying task types
#include <iostream>
#include <type_traits>
template<typename IN, typename OUT = IN>
struct node {
using in_type = IN;
using out_type = OUT;
};
template<class A, class...>
@tonisuter
tonisuter / Liquefier.md
Last active August 29, 2015 14:13
FastFlow & Liquefier

FastFlow

Pipeline

  • Type: ff_pipe
  • Header: <ff/ffpipeline.hpp>

A pipeline is a stream parallel skeleton. It has multiple stages and a task type which defines the type of the elements (tasks) that are passed from stage to stage. Each stage runs on a separate thread and works on one task at a time.

The following example shows how a pipeline with 3 stages and task type int can be created. The pipe is started

@tonisuter
tonisuter / SolutionLoggerExample.swift
Last active August 9, 2017 08:30
SolutionLogger Example
import Foundation
struct LogEntry: Codable {
let task: String
let solution: String
}
class ViewController: UIViewController {
// ...other code...
let x = newHeading.x
let y = newHeading.y
let z = newHeading.z
let magnitude = sqrt(x*x + y*y + z*z)
let maxMagnitude = 4000.0
let magnitudeRatio = magnitude / maxMagnitude
strengthIndicator.progress = Float(magnitudeRatio)
import UIKit
import CoreMotion
class ViewController: UIViewController {
let motionManager = CMMotionManager()
var currentAngle:Double!
override func viewDidLoad() {
super.viewDidLoad()
@IBAction func captureImageWithQRCode(_ sender: UIButton) {
let solutionLogger = SolutionLogger(viewController: self)
solutionLogger.scanQRCodeAndCaptureImage { (qrCode: String, image: UIImage) in
// use qrCode and image
}
}
let fetchRequest: NSFetchRequest<MemoryPair> = MemoryPair.fetchRequest()
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
do {
let pairs: [MemoryPair] = try coreDataStack.context.fetch(fetchRequest)
// display the memory pairs
} catch {
print(error)
}
let memoryPair = MemoryPair(context: coreDataStack.context)
memoryPair.creationDate = Date()
memoryPair.image1 = image1
memoryPair.text1 = code1
memoryPair.image2 = image2
memoryPair.text2 = code2
coreDataStack.saveContext()
coreDataStack.context.delete(memoryPair)
coreDataStack.saveContext()