Skip to content

Instantly share code, notes, and snippets.

module.exports = function(context, req) {
context.log('push data:', req.body);
var str = req.body;
var results = str.split("&");
var slackText = getParam(results, "text").replace(/\+/g, " ").replace(/mytodo/g, "");
var userName = getParam(results, "user_name").replace(/\+/g, " ");
context.log(getParam(results, "token"));
context.log(getParam(results, "channel_name"));
@codePrincess
codePrincess / .swift
Created August 2, 2017 15:17
empty doodling class
import Foundation
import UIKit
public class DoodleCanvas : UIImageView {
}
@codePrincess
codePrincess / .swift
Last active August 10, 2018 18:26
Basic doodling with Apple Pencil
import Foundation
import UIKit
public class DoodleCanvas : UIImageView {
let pi = CGFloat(Double.pi)
let forceSensitivity: CGFloat = 4.0
var pencilTexture = UIColor(patternImage: UIImage(named: "PencilTexture")!)
let defaultLineWidth : CGFloat = 6
@codePrincess
codePrincess / .swift
Created August 2, 2017 15:39
Smooth doodling with coalesced touches
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
let context = UIGraphicsGetCurrentContext()
image?.draw(in: bounds)
var touches = [UITouch]()
@codePrincess
codePrincess / .swift
Last active August 3, 2017 14:37
timer for tracking the users doodling coordinates
public func setup () {
resetDoodleRect()
lastTouchTimestamp = 0
if #available(iOS 10.0, *) {
trackTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: {
timer in
let now = Date().timeIntervalSince1970
@codePrincess
codePrincess / .swift
Created August 3, 2017 14:37
draw rectangle over current drawing area
func drawDoodlingRect(context: CGContext?) {
let inset = 5
markerColor.setStroke()
context!.setLineWidth(1.0)
context!.setLineCap(.round)
UIColor.clear.setFill()
ocrImageRect = CGRect(x: minX - inset, y: minY - inset, width: (maxX-minX) + inset*2, height: (maxY-minY) + 2*inset)
context!.addRect(ocrImageRect!)
@codePrincess
codePrincess / .swift
Created August 3, 2017 14:38
get ready for the next doodling area
func resetDoodleRect() {
minX = Int(self.frame.width)
minY = Int(self.frame.height)
maxX = 0
maxY = 0
lastTouchTimestamp = 0
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
@codePrincess
codePrincess / .swift
Created August 3, 2017 14:53
get text on image for handwriting
func fetchOCRText () {
let manager = CognitiveServices()
let ocrImage = image!.crop(rect: ocrImageRect!)
manager.retrieveTextOnImage(ocrImage) {
operationURL, error in
if #available(iOS 10.0, *) {
@codePrincess
codePrincess / .swift
Created August 3, 2017 15:00
call the handwriten recognition for an image
public func retrieveTextOnImage(_ image: UIImage, completion: @escaping (String?, NSError?) -> ()) {
assert(CognitiveServicesComputerVisionAPIKey.characters.count > 0,
"Please set the value of the API key variable (CognitiveServicesVisualFeaturesAPIKey) before attempting to use the application.")
var urlString = CognitiveServicesConfiguration.HandwrittenOcrURL
urlString += "?\(CognitiveServicesHTTPParameters.Handwriting)=true"
let url = URL(string: urlString)
print("calling the following URL: \(String(describing: url))")
@codePrincess
codePrincess / .swift
Created August 7, 2017 11:32
playground structure for basic doodeling
//at the very top of the class
import Foundation
import UIKit
import PlaygroundSupport
public class MyDoodleCanvas {
...
}
//after the class implementation