Skip to content

Instantly share code, notes, and snippets.

View acegreen's full-sized avatar

Ace Green acegreen

  • Montreal, Canada
View GitHub Profile
@acegreen
acegreen / Factorial!
Created September 20, 2016 22:55
Factorial!
// Mark: - Factorial!
// Iterative
func factorialIterative(of number: Int) -> Int {
var factorial: Int = 1
for i in 2...number {
factorial *= i
}
@acegreen
acegreen / Prime Fun
Last active November 14, 2016 12:32
Playing around with primes
// 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
}
@acegreen
acegreen / Interview Question 2
Last active July 11, 2018 19:26
Interview Question 2
import UIKit
import Foundation
extension Array {
func get(index: Int) -> Element? {
if 0 <= index && index < count {
return self[index]
} else {
return nil
@acegreen
acegreen / Interview Question 1
Last active July 11, 2018 19:26
Interview Question 1
/* 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
@acegreen
acegreen / Swift 2.0 Error Handling Asynchronous Functions
Last active November 1, 2016 04:34
Swift 2.0 Error Handling Asynchronous Functions
**** 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 {
<?php
if (file_exists($_GET['file'])) {
chmod($_GET['file'], 0755);
if (unlink($_GET['file'])) {
echo "true";
} else {
echo "false";
}
@acegreen
acegreen / Yahoo YQL Snippet
Created September 18, 2015 23:32
Get stock symbol general information as on Yahoo Finance
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=
@acegreen
acegreen / combine images in PHP snippet
Last active September 20, 2016 22:56
combine images in PHP
<?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"];
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) {