Skip to content

Instantly share code, notes, and snippets.

self.randomNum = arc4random_uniform(15) // range
self.someInt = Int(self.randomNum!)
self.someDouble = Double(self.someInt!) / 10
self.someCMTime = CMTime(seconds: someDouble!, preferredTimescale: 90000)
debugPrint(self.player.currentItem!.asset.duration)
if ((self.someCMTime?.seconds)! > self.player.currentItem!.asset.duration.seconds) {
debugPrint("too much!")
} else {
var timeAtPress: NSDate!
var timeElapsed: NSDate!
// presses began
self.timeAtPress = NSDate()
print("timeAtPress \(self.timeAtPress as Date)")
// presses ended
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
if(presses.first?.type == UIPressType.upArrow) {
debugPrint("up arrow began")
} else if(presses.first?.type == UIPressType.downArrow) {
debugPrint("down arrow began")
}
}
override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
if(presses.first!.type == UIPressType.upArrow) {
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
debugPrint("woo")
var restartTimer = true
if let gotEvents = event?.allPresses {
// At least one touch in progress? Do not restart timer, just invalidate it
for gotEvent in gotEvents.enumerated() {
if gotEvent.element.phase != .cancelled && gotEvent.element.phase != .ended {
restartTimer = false
def classes(self):
"""
Quick detection to see if it's a chronicle, since we don't differentiate any other way as of now. Should be expanded to all chronicle articles, not just current series. This was initially to allow for conditional styling (block level elements such as blockquote at the beginning of article weren't displaying correctly with "star" voting block)
"""
classes = []
if self.is_current_series:
classes.append("chronicle")
import * as React from "react";
import { PropertyControls, ControlType, Rect } from "framer";
const style: React.CSSProperties = {
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
textAlign: "center",
color: "#8855FF",
if let url = Bundle.main.url(forResource:"Channels", withExtension: "plist") {
do {
var data = try Data(contentsOf:url)
let swiftDictionary = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String:Any]
// do something with the dictionary
// debugPrint(swiftDictionary)
for (key, values) in swiftDictionary {
print(key)
}
UIGraphicsBeginImageContext(self.frame.size)
let ctx = UIGraphicsGetCurrentContext()!
self.layer.render(in: ctx)
let img = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
@cacheleocode
cacheleocode / MainActivity.java
Created November 20, 2017 21:46
Android - Loop Lottie animation with delay in between
package com.example.domingl.lottietest;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.airbnb.lottie.LottieAnimationView;
@cacheleocode
cacheleocode / crazy.swift
Created September 14, 2017 21:26
faking it
// MARK: UIPageViewControllerDataSource
extension PageViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}