Skip to content

Instantly share code, notes, and snippets.

// E.g. usage
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 39, 56)];
[shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
[shareButton setImage:[PaintCodeStyleKit imageOfShareWithTextWithTintColor:[UIColor whiteColor]] forState:UIControlStateNormal];
+ (UIImage*)imageOfShareWithTextWithTintColor: (UIColor*)tintColor;
{
@jscalo
jscalo / gist:f31f70ce58bedc17c521
Created February 25, 2015 21:57
Basic drawing with Python's turtle module
import turtle
import random
# input: takes a side and a length as integers
# processing: draws a figure based on the inputs
# output: nothing, dones't return any value
def polygon(sides, length):
for x in range(sides):
//
// John Scalo
// CloudKitExtras.swift
//
import CloudKit
var ckLogging = true
let ckBatchLimit = 400
let usleepInterval: UInt32 = 500000
private func updateLines(samples: [Float], yMidline: CGFloat) {
let maxSampleMagnitude = max(dataProvider.summarySampleMax, -(dataProvider.summarySampleMin), Float.leastNonzeroMagnitude)
let yScalingFactor = bounds.height / 2 / CGFloat(maxSampleMagnitude)
var xPos: CGFloat = 0
let cnt = samples.count
var idx = 0
let visibleDur = dataProvider.duration / Double(viewPort.zoom)
let startTime = (Double(viewPort.startingXUnit) / Double(viewPort.xAxisUnits)) * dataProvider.duration
private var firstSampleToPlotIdx: Int {
get {
let idx = Int(-viewPort.xTrans * UIScreen.main.scale)
return (0..<dataProvider.summarySampleCnt).clamp(idx)
}
}
private func viewPortZoomed() {
dataProvider?.summarySamples = nil
updateScrollViewSize()
CATransaction.begin()
CATransaction.setDisableActions(true)
update()
CATransaction.commit()
}
private func updateScrollViewSize() {
scrollView.contentSize =
CGSize(width: bounds.width * viewPort.zoom,
height: bounds.height)
}
override func layoutSubviews() {
super.layoutSubviews()
let scale = bounds.width / lastBounds.width
scrollView.recenterForScale(scale)
lastBounds = bounds
updateScrollViewSize()
update()
}
@objc func pinchGesture(_ gc: UIPinchGestureRecognizer) {
switch gc.state {
case .changed:
pauseUpdates = true
scrollView.recenterForScale(gc.scale)
pauseUpdates = false
let newScale = viewPort.zoom * gc.scale
viewPort.zoom = max(newScale, 1.0)
gc.scale = 1.0
case .ended, .cancelled, .failed:
func update() {
guard viewPort != nil else { return }
guard dataProvider != nil else { return }
prepare()
updateMidline()
updatePlot()
}