Skip to content

Instantly share code, notes, and snippets.

View Thunderbird7's full-sized avatar
🏠
Working from home

Yuttana K. Thunderbird7

🏠
Working from home
View GitHub Profile
@Thunderbird7
Thunderbird7 / AbbreviateNumber.swift
Last active December 27, 2018 15:54
[Swift] Abbreviate number class, such as number of 1500 convert to 1.5k
func abbreviateNumber(num: NSNumber) -> String {
// less than 1000, no abbreviation
if num < 1000 {
return "\(num)"
}
// less than 1 million, abbreviate to thousands
if num < 1000000 {
var n = Double(num);
n = Double( floor(n/100)/10 )
@Thunderbird7
Thunderbird7 / TestURLConnection.m
Last active November 24, 2015 17:43
Test case example to test response of an asynchronous networking request with XCTestExpectation APIs
- (void)testAsynchronousURLConnection {
// Create request
NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/get"];
NSString *description = [NSString stringWithFormat:@"GET %@", URL];
XCTestExpectation *expectation = [self expectationWithDescription:description];
NSURLSession *session = [NSURLSession sharedSession];
@Thunderbird7
Thunderbird7 / jsondecode.swift
Last active December 29, 2015 11:44
Deserialize json string UTF8 encoding
//: Playground - noun: a place where people can play
import UIKit
let jsonString = "{\"username\" : \"thunderbird\", \"password\" : \"tb00110\"}"
func jsonDecodeString(json: String) -> Dictionary<String, AnyObject>? {
let json:NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
do {
return try NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions.MutableContainers) as? Dictionary<String, AnyObject>
// AWS SNS Config
// Credential
AWSStaticCredentialsProvider *credential = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:@"YOUR_AMAZON_ACCESSKEY"
secretKey:@"YOUR_AMAZON_SECERT"];
// Config region
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast1
credentialsProvider:credential];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
// ARN Endpoint
// For Amazon SNS
NSString *myARN = @"arn:aws:sns:ap-southeast-1:570761336625:app/APNS_SANDBOX/Airportthai";
AWSSNSCreatePlatformEndpointInput *platformEndpointRequest = [AWSSNSCreatePlatformEndpointInput new];
[platformEndpointRequest setCustomUserData:@"custom user data เช่นระบบ iOS version, Device Version อะไรก็ได้"];
[platformEndpointRequest setToken:[self deviceTokenAsString:deviceToken]]; //แปลง device token ให้เป็น string ก่อนนะ
[platformEndpointRequest setPlatformApplicationArn:myARN];
// This function creates the required URLRequestConvertible and NSData we need to use Alamofire.upload
func urlRequestComponentsWithParams(urlString:String, parameter: [String: AnyObject], imageData:[NSData], inputName: String) -> (URLRequestConvertible, NSData) {
// create url request to send
let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!)
mutableURLRequest.HTTPMethod = Alamofire.Method.PUT.rawValue
let boundaryConstant = "FileUploader-boundary-\(arc4random())-\(arc4random())";
let contentType = "multipart/form-data;boundary="+boundaryConstant
mutableURLRequest.setValue(contentType, forHTTPHeaderField: "Content-Type")
@Thunderbird7
Thunderbird7 / RegExHelper.Swift
Created March 8, 2016 03:45
Regular Expression helper in Swift 2 / match, replace with your pattern!
//
// Regex.swift
// Jitta
//
// Created by Yuttana Kungwon on 3/6/2559 BE.
// Copyright © 2559 Jitta Company. All rights reserved.
//
import Foundation

#การใช้ Git ฉบับรีบร้อน

##Git Git เป็น revision control แบบ distributed (หมายความว่าไม่มีศูนย์กลาง) และ แบบ non-linear history (หมายความว่ามีประวัติการเปลี่ยนแปลงแบบไม่ใช่เส้นตรง) ดังนั้นทำให้คอนเซปต์ของ Git นั้นต่างจาก revision control รุ่นก่อนหน้าหลายอย่าง

ต่อไปจะอธิบายย่อๆเรื่องคำสั่ง Git โดยอิงกับการทำงานใน GitHub เป็นสำคัญ (Git มีวิธีใช้พลิกแพลงมากมาย ไปศีกษาการใช้อื่นได้ด้วยการไป Google เอาเอง)

##clone

สมมุติว่ามี repository แห่งนีงใน GitHub เช่น https://github.com/norsez/projectA

/* split page by page with key */
{
// key for page 1
"page1": [ /* key for page 1 */
{ /* form type input */
"type": "textfield",
"payload": {
"label": "Name",
"placeholder": "your name"
}
import React, { Component } from 'react';
import { AppRegistry } from 'react-native';
import App from './App'
import ApolloClient, { createNetworkInterface } from 'apollo-client'
import { ApolloProvider } from 'react-apollo'
const networkInterface = createNetworkInterface({
uri: 'http://graphql-swapi.parseapp.com'
})