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
// Mark: - Factorial! | |
// Iterative | |
func factorialIterative(of number: Int) -> Int { | |
var factorial: Int = 1 | |
for i in 2...number { | |
factorial *= i | |
} |
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
// Mark: - Prime fun | |
// isPrime function | |
func isPrime(n: Int) -> Bool { | |
guard n > 1 else { return false } | |
for i in stride(from: n-1, to: 1, by: -1) { | |
if n % i == 0 { | |
return false | |
} |
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
import UIKit | |
import Foundation | |
extension Array { | |
func get(index: Int) -> Element? { | |
if 0 <= index && index < count { | |
return self[index] | |
} else { | |
return nil |
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
/* QUESTION: | |
In an unsorted array of negative and positive integers, write a function, hasSumOf3Ints(array, n), that returns true if you find three numbers in the array that add up to a passed number, "n". | |
(ie. array of [3,10,2,-3,100,4,0,-103], and n=14, 10, 4, and 0 is found and thus it would return true) | |
*/ | |
// Error enum created at the end to properly throw errors including a function message() to directly display the error in the catch | |
enum Errors: ErrorType { | |
case EmptyArray |
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
**** Medium Story **** | |
https://medium.com/ios-os-x-development/logan-wright-i-just-started-dabbling-with-swift-s-error-handling-myself-5e7b3dffdf06#.zbor79r8l | |
public enum Errors: ErrorType { | |
case NoInternetConnection | |
case QueryResponseError | |
case ErrorQueryingForData | |
case QueryDataEmpty | |
public func message() -> 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
<?php | |
if (file_exists($_GET['file'])) { | |
chmod($_GET['file'], 0755); | |
if (unlink($_GET['file'])) { | |
echo "true"; | |
} else { | |
echo "false"; | |
} |
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
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback= |
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 | |
foreach($_POST as $data) { | |
//$data = $_POST['data']; | |
$file = 'snapshot-'.md5(uniqid()) . '.png'; | |
$result=(array)(json_decode($data,true)); | |
$chart['plot']=$result["charts"][0]["panes"][0]["content"]; |
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
let script: JSValue = jsContext.objectForKeyedSubscript("getImageURL") | |
[jsContext callWithArguments:@["FirstParam",^(NSString* callbackValue) { | |
NSLog(@"Got a value: %@",callbackValue) | |
}] | |
basically I have a javascript function that looks like this: | |
function getImageURL(object, callback) { | |
object.executeActionById("takeScreenshot"); | |
object.onScreenshotReady(function(imageName) { |