Skip to content

Instantly share code, notes, and snippets.

View nRewik's full-sized avatar

Nutchaphon Rewik nRewik

View GitHub Profile
@nRewik
nRewik / NSDate+Utility.swift
Last active August 29, 2015 14:27
Create all dates in specific month and year as in `gregorian` calendar
import UIKit
extension NSDate{
/**
Create all dates in specific month and year as in `gregorian` calendar
**Usage Example**
`NSDate.datesInMonthCalendar(month: 8, year: 2015)`
@nRewik
nRewik / PromiseTaskExample.swift
Created September 10, 2015 13:28
an example of how to create an async promise task
func getUserData(#token: String) -> Promise<User>{
return Promise<User>{ fulfill, reject in
let task = NSURLSession.sharedSession().dataTaskWithURL(self.getCurrentUserURL){ data , res , err in
if let err = err{
return reject(err)
}
let user = User(data: data)
return fulfill(user)
}
task.resume()
@nRewik
nRewik / Rule.swift
Created October 20, 2015 14:06
A rule-based string validator
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
public typealias Validator = String -> Bool
public typealias ValidatorTransformer = Validator -> Validator
public typealias ValidatorCombiner = ( Validator , Validator ) -> Validator
public enum Rule{
@nRewik
nRewik / chainingRequestCallback.swift
Created September 10, 2015 13:37
an example of request chaining using NSURLSession Callback
// 1. login post request
NSURLSession.sharedSession().dataTaskWithRequest(loginRequest){ data , res , err in
// let token = data...
// we have token.
let getCurrentUserURL = NSURL(string: getUserDataURL + "?token=\(token)")!
// 2. get current user data
NSURLSession.sharedSession().dataTaskWithURL(getCurrentUserURL){ data , res , err in
// we have user data, and we get currentUserID

Keybase proof

I hereby claim:

  • I am nrewik on github.
  • I am nrewik (https://keybase.io/nrewik) on keybase.
  • I have a public key ASA5UgYMoNUfaxy7wRAk2xm85HAyTz_7wYbTiX52ZZyv9go

To claim this, I am signing this object:

@nRewik
nRewik / TransformTransitioning.swift
Last active October 2, 2018 14:26
view controller transition from origin view to another view controller.
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
extension UIView{
var snapshot: UIImage{
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0);
import UIKit
let text = "Saw yet kindness too replying whatever marianne. Old sentiments resolution admiration unaffected its mrs literature. (https://www.google.com/), Situation admitting promotion at or to perceived be. Mr acuteness we as estimable enjoyment up. An held late as felt know."
let font = UIFont.preferredFont(forTextStyle: .body)
let highlightFont = UIFont.preferredFont(forTextStyle: .headline)
let attributedText = NSMutableAttributedString(string: text, attributes: [
.font : font
])
@nRewik
nRewik / UIImage+Orientation.swift
Created August 21, 2015 09:00
UIImage fix orientation ( rotate pixel rather than relying on exif )
//
// UIImage+Orientation.swift
// DrCloudPatient
//
// Created by DW78 on 8/21/15.
// Copyright (c) 2015 DW78. All rights reserved.
//
import UIKit
{
"todo": [
{
"id": "0cd7190c-c99b-4716-a6ab-e36432aca084",
"title": "non labore quam",
"description": "Est enim dolor. Vitae cumque doloremque voluptas. Ex autem voluptas neque facilis deserunt eius fugit possimus molestias.",
"userId": "94375b4e-b500-4264-883f-81e920fccc58",
"createdAt": "2019-10-16T10:30:11.563Z"
},
{
{
"todo": [
{
"id": "ffcedd58-bf77-4e90-a153-32e6723b16c4",
"title": "deleniti sapiente ut",
"description": "Ut odit sequi iste. Quaerat veritatis officia. Quas doloribus velit dolorem laborum totam.",
"userId": "d29a3b73-732d-4218-b9e2-9dc3b1c5c59b",
"createdAt": "2020-06-30T07:08:06.932Z"
},
{