This file contains hidden or 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
<?php | |
class Adventurer { | |
public $class; | |
public $name; | |
public $inventory = []; | |
public $handler; | |
function __construct($name, $class, $handler=null) { |
This file contains hidden or 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
<?php | |
class Animal { | |
public $species; | |
public $numLegs; | |
public $name; | |
function __construct($species, $legs, $name) { |
This file contains hidden or 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
// Swift 3 | |
class MyController: UIViewController { | |
var timer : Timer? | |
var startDate: Date? | |
@IBOutlet weak var timerLabel: UILabel! | |
func startTimer() { | |
print("startTimer()") | |
let timeInterval = TimeInterval(1.0/10.0) | |
startDate = Date() |
This file contains hidden or 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
// Dates compared in Swift 3 | |
let date1 = Date() | |
var date2 = Date() | |
let interval = TimeInterval(exactly: 11.0) | |
date2.addTimeInterval(interval!) | |
date1.compare(date2) == .orderedDescending // true if date1 is before date2 | |
date1.compare(date2) == .orderedAscending // true if date1 is after date2 | |
date1.compare(date2) == .orderedSame // true if date1 is equal to date2 |
This file contains hidden or 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
File path = context.getFilesDir(); | |
// OR For external SD : | |
File path = context.getExternalFilesDir(null); | |
// create your file : | |
File file = new File(path, "FILENAME.txt"); | |
// Get Strings from text view : | |
TextView t = (TextView)findViewById(R.id.mainText); |
This file contains hidden or 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
// Preg.match("[a-z]+", "alpha, beta, core") | |
// let newString = Preg.replace("([a-z]+)", "__$1__,", "alpha, beta, core") | |
class Preg { | |
/** | |
* regular expression matching. | |
* | |
*/ | |
class func match(pattern: String, subject: String) -> [String] { | |
var mm = [String]() |
This file contains hidden or 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
protocol ArgType {} | |
extension String: ArgType {} | |
extension Dictionary where Key: ArgType, Value: ArgType { | |
func toHttpArgString() -> String { | |
var r = String() | |
for (n, v) in self { | |
if !r.isEmpty { r += "&" } | |
r += "\(n)=\(v)" |
This file contains hidden or 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 String { | |
// Modifies string in place | |
mutating func removeCharsInCharacterSet(charSet: NSCharacterSet) { | |
if let range = self.rangeOfCharacterFromSet(charSet, options: .LiteralSearch, range: nil) { | |
self.replaceRange(range, with: "") | |
} | |
} | |
// Creates a new string without modifying existing string | |
func stringByRemovingCharactersInCharacterSet(charSet: NSCharacterSet) -> String { | |
var newStr = self |
This file contains hidden or 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
struct Vector | |
{ | |
var x: Double = 0 | |
var y: Double = 0 | |
init(x: Double, y: Double) | |
{ | |
self.x = x | |
self.y = y | |
} |
This file contains hidden or 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 { | |
public func addTopBorderWithColor(color: UIColor, width: CGFloat) { | |
let border = CALayer() | |
border.backgroundColor = color.CGColor | |
border.frame = CGRectMake(0, 0, self.frame.size.width, width) | |
self.layer.addSublayer(border) | |
} | |
public func addRightBorderWithColor(color: UIColor, width: CGFloat) { | |
let border = CALayer() |