Skip to content

Instantly share code, notes, and snippets.

package com.minhwang.myapplication;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
@minhwang
minhwang / PickRandomNumbersFromArray.swift
Last active November 22, 2016 09:32
How to pick numbers randomly from array
//: Playground - noun: a place where people can play
import UIKit
func pickNumbersRandomly(from numbers: [UInt], theNumberOf: UInt) -> [UInt] {
var numbers = numbers
var numbersPickedRandomly = [UInt]()
for _ in 1...theNumberOf {
let indexPickedRandomly = Int(arc4random_uniform(UInt32(numbers.count)))
@minhwang
minhwang / requestGET.swift
Created November 8, 2016 10:20
How to write code to request GET data
func requestGET(stringURL url:String) -> URLSessionDataTask? {
var task: URLSessionDataTask? = nil
guard let url: URL = URL(string: url) else {
print("URL is invalid..!!")
return task
}
let urlSession = URLSession(configuration: URLSessionConfiguration.default)
@minhwang
minhwang / requestGETUsingString.swift
Last active November 8, 2016 10:18
How to write code to request GET data using String object.
func requestGETUsingString(stringURL url:String) {
guard let url: URL = URL(string: url) else {
print("URL is invalid..!!")
return
}
guard let result = try? String(contentsOf: url) else {
print("Error occurred while getting data..!!")
return
}