Skip to content

Instantly share code, notes, and snippets.

function () {
if (!this.$sizingHeader) return;
this.$element.prepend(this.$sizingHeader);
var $sizingCells = this.$sizingHeader.find('th');
var columnCount = $sizingCells.length;
var tableWidth = $sizingCells.parent().width(); // Used to calculate the width percent
function matchSizingCellWidth(i, el) {
@jjacobson93
jjacobson93 / if_let_test1.swift
Last active March 14, 2017 20:57
Swift If-let Statement
func giveMeAStringMaybe(_ maybe: Bool) -> String? {
return maybe ? "Yes!" : nil
}
let str: String? = giveMeAStringMaybe(true)
if let unwrappedStr = str {
print(unwrappedStr is String) // prints: true
print(unwrappedStr) // prints: "Yes!"
} else {
print(str) // prints: nil
@jjacobson93
jjacobson93 / guard_let_test1.swift
Last active March 14, 2017 20:57
Swift Guard-let Statement
func giveMeAStringMaybe(_ maybe: Bool) -> String? {
return maybe ? "Yes!" : nil
}
let str: String? = giveMeAStringMaybe(true)
guard let unwrappedStr = str else {
print("str is nil")
// unwrappedStr is NOT accessible here
return
}
func giveMeAStringMaybe(_ maybe: Bool) -> String? {
return maybe ? "Yes!" : nil
}
let str1: String? = giveMeAStringMaybe(true)
let lowercaseStr1: String? = str1?.lowercased()
print(lowercaseStr2) // prints: "yes!"
let str2: String? = giveMeAStringMaybe(false)
let lowercaseStr2: String? = str2?.lowercased()
@jjacobson93
jjacobson93 / skaction_test1.swift
Created March 16, 2017 02:45
Creating an SKAction
let moveAction = SKAction.moveBy(x: 10, y: -15, duration: 0.8)
@jjacobson93
jjacobson93 / skaction_test2.swift
Created March 16, 2017 02:50
Running an SKAction
let moveAction = SKAction.moveBy(x: 10, y: -15, duration: 0.8)
let player = SKSpriteNode(imageNamed: "player.png")
player.run(moveAction)
@jjacobson93
jjacobson93 / skaction_test3.swift
Created March 16, 2017 02:59
Grouping SKActions
let moveAction = SKAction.moveBy(x: 10, y: -15, duration: 0.8)
let rotateAction = SKAction.rotate(byAngle: π, duration: 0.5)
let moveAndRotate = SKAction.group([moveAction, rotateAction])
let player = SKSpriteNode(imageNamed: "player.png")
player.run(moveAndRotate)
@jjacobson93
jjacobson93 / skaction_test4.swift
Created March 17, 2017 07:24
Repeat SKAction
let moveAction = SKAction.moveBy(x: 10, y: -15, duration: 0.8)
let player = SKSpriteNode(imageNamed: "player.png")
let moveFiveTimes = SKAction.repeat(moveAction, count: 5)
player.run(moveFiveTimes)
@jjacobson93
jjacobson93 / skaction_test5.swift
Created March 20, 2017 23:32
Run block SKAction
let coin = SKSpriteNode(imageNamed: "coin.png")
let animate = SKAction.rotate(byAngle: π/2, duration: 0.75)
let updateScore = SKAction.run {
scoreValue += 10
}
let sequence = SKAction.sequence([animate, updateScore])
coin.run(sequence)
@jjacobson93
jjacobson93 / skaction_test6.swift
Created March 20, 2017 23:51
Custom SKAction
let updateTimeLabel = SKAction.customAction(withDuration: 5) {
(node, elapsedTime) in
if let label = node as? SKLabelNode {
label.text = "\(elapsedTime)s"
}
}
let timeLabel = SKLabelNode(fontNamed: "Chalkduster")
timeLabel.text = "0s"
timeLabel.run(updateTimeLabel)