This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
padWithZeros(n) { | |
return n > 9 ? `${n}` : `0${n}` // Adds a 0 if the value is less than 10 | |
} | |
// Pass in the time in ms | |
formatTime(time) { | |
const secs = Math.floor(time / 1000) // divide by 1000 to get secs | |
const mins = Math.floor(secs / 60) // divide secs by 60 for mins | |
const hrs = Math.floor(mins / 60) // divide mins by 60 for hrs | |
// Mod (%) 60 transforms values to 0 to 59 range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the current time in ms | |
let lastUpdateTime = Date.now() | |
setInterval(() => { | |
// get the current time in ms | |
const now = Date.now() | |
// calculate the delta time as difference between now and the last update | |
const deltaTime = now - lastUpdateTime | |
// Set the last update to now. | |
lastUpdateTime = now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
makeBars() { | |
// Get an array of timers tiemr.time is a utc | |
const timers = this.props.timers | |
// use reduce to get the max value to normalize times | |
const max = timers.reduce((acc, timer) => { | |
return Math.max(acc, timer.time) | |
}, 0) | |
// generate an array of bars | |
return this.props.timers.map((timer, index) => { | |
const h = timer.time / max * 100 // normalize the times to 0 to 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Local storage | |
// Create an object | |
var obj = {name:"Joe", age:33, shoesize:9.5, favoriteFoods:["Apples", "Bananas"]}; | |
// Convert object to JSON string | |
var objJSON = JSON.stringify(obj); | |
// save JSON string to local storage with the key obj. | |
localStorage.setItem("obj", objJSON); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List all of the letters of the alphabet lowercase | |
// get the starting code | |
var start = "a".charCodeAt(0); | |
var count = 26; // How many letters | |
var end = start + count; | |
for (var i = start; i < end; i++) { | |
var letter = String.fromCharCode(i) | |
console.log("Char:"+letter); | |
$("body").append("<div>"+letter+"</div>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func rotateRad(r: CGFloat) { | |
self.transform = CGAffineTransformMakeRotation(r) | |
} | |
func rotateDeg(r: CGFloat) { | |
self.transform = CGAffineTransformMakeRotation(r.degreesToRadians) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@IBDesignable | |
class CustomTextField: UITextField { | |
var padding: UIEdgeInsets { | |
get { | |
return UIEdgeInsets(top: 0, left: paddingValue, bottom: 0, right: paddingValue) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Draw a sine curve with a fill | |
let centerY = frame.height / 2 // find the vertical center | |
let steps = 200 // Divide the curve into steps | |
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance | |
// Make a path | |
let path = UIBezierPath() | |
path.moveToPoint(CGPoint(x: 0, y: centerY)) | |
// Loop and draw steps in straingt line segments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Draw a sine curve with a fill | |
let centerY = frame.height / 2 // find the vertical center | |
let steps = 200 // Divide the curve into steps | |
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance | |
// Make a path | |
let path = UIBezierPath() | |
// Start in the lower left corner | |
path.moveToPoint(CGPoint(x: 0, y: frame.height)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Draw a sine curve | |
let centerY = frame.height / 2 // find the vertical center | |
let steps = 200 // Divide the curve into steps | |
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance | |
// Make a path | |
let path = UIBezierPath() | |
// Move the starting point to the left center | |
path.moveToPoint(CGPoint(x: 0, y: centerY)) | |
// Loop and draw steps in straingt line segments |
NewerOlder