Skip to content

Instantly share code, notes, and snippets.

func genericDecode<T>(data: Data) -> T {
let pointer = UnsafeMutablePointer<T>.allocate(capacity: MemoryLayout<T.Type>.size)
data.copyBytes(to: pointer as! UnsafeMutablePointer<UInt8>, count: MemoryLayout<T.Type>.size)
return pointer.move()
}
func genericEncode<T>(value: T) -> Data {
var value = value
func directMetersFromCoordinate(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> Float {
let DEG_TO_RAD = 0.017453292519943295769236907684886
let EARTH_RADIUS_IN_METERS = 6372797.560856
let latutideArc = (from.latitude - to.latitude) * DEG_TO_RAD
let longitudeArc = (from.longitude - to.longitude) * DEG_TO_RAD
var latitudeH = sin(latutideArc * 0.5)
latitudeH *= latitudeH
defaults write com.apple.dt.xcodebuild PBXNumberOfParallelBuildSubtasks 4
defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4
class PopAnimator:: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 1.0
var originFrame = CGRect.zero
var presenting = true
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
MyView.superview?.constraints.forEach { constraint in
// print("-> \(constraint.description)\n")
if constraint.firstItem == MyView &&
constraint.firstAttribute == .centerX {
print("-> \(constraint.description)\n")
constraint.constant == myBool ? -100.0 : 0.0
return
}
if constraint.identifier == "my identifier set in Main Storyboard" {
constraint.isActive = false
@umwelt
umwelt / gist:2e81c12b08b2fe1fa8fdd44f90258ff5
Created July 2, 2017 14:11
Reproducible research week 1 quiz
Suppose I conduct a study and publish my findings. Which of the following is an example of a replication of my study?
- An investigator at another institution conducts a study addressing the same question, collects her own data, analyzes it separately from me, and publishes her own findings.
Which of the following is a requirement for a published data analysis to be reproducible?
- The full computer code for doing the data analysis is made publicly available.
Which of the following is an example of a reproducible study?
- The study's analytic data and computer code for the data analysis are publicly available. When the code is run on the analytic data, the findings are identical to the published results.
Which of the following is a reason that a study might NOT be fully replicated?
fileprivate class CustomButtonWithExtendedTouchArea : UIButton {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let relativeFrame = self.bounds
let hitTestEdgeInsets = UIEdgeInsetsMake(-10/masterRatio, -10/masterRatio, -10/masterRatio, -10/masterRatio)
let hitFrame = UIEdgeInsetsInsetRect(relativeFrame, hitTestEdgeInsets)
return hitFrame.contains(point)
}
}
import UIKit
private var pTouchAreaEdgeInsets: UIEdgeInsets = .zero
extension UIControl {
var touchAreaEdgeInsets: UIEdgeInsets {
get {
if let value = objc_getAssociatedObject(self, &pTouchAreaEdgeInsets) as? NSValue {
var edgeInsets: UIEdgeInsets = .zero
xcodebuild -workspace Grocerest.xcworkspace -scheme Grocerest clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep [1-9].[0-9]ms | sort -nr > culprits.txt
rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/*