Skip to content

Instantly share code, notes, and snippets.

View kittisak-phetrungnapha's full-sized avatar
:octocat:

Kittisak Phetrungnapha kittisak-phetrungnapha

:octocat:
View GitHub Profile
// Two pointers: one input, opposite ends
public int fn(int[] arr) {
int left = 0;
int right = arr.length - 1;
int ans = 0;
while (left < right) {
// do some logic here with left and right
if (CONDITION) {
@kittisak-phetrungnapha
kittisak-phetrungnapha / APIManager.swift
Last active October 8, 2019 16:50
CustomDecodableResponseSerializer in Alamofire 5 for automatic mapping decodable object if the response is success or throw an error object if it is fail that dynamic with your api. The explanation is in the comment.
import Foundation
import Alamofire
protocol NetworkSession: class {
func request<T: Decodable>(router: Router, decoder: JSONDecoder, completion: @escaping (Result<T, Error>) -> Void)
}
final class APIManager: NetworkSession {
static let shared = APIManager()
const store = require('google-play-scraper');
store.reviews({
appId: 'com.facebook.katana',
page: 1,
sort: gplay.sort.RECENT
}).then(console.log, console.log);
import pandas as pd
import numpy as np
import json
import nltk
import string
import re
import tensorflow as tf
import pandas as pd
import numpy as np
import json
import spacy
import nltk
import string
import re
appIdCondition = df['appId'].notnull()
dateCondition = df['date'].str.len() == 17
df = df[np.logical_and(appIdCondition, dateCondition)][['appId', 'date', 'dataSource']]
print(df)
print(df.count())
# Result
appId date dataSource
6 #10_Perfectly Clear 26:07:13:08:31:49 PlayStore_Random
def model_cv(splits, X, y, pipeline, description, category):
print(description)
print()
kfold = StratifiedKFold(n_splits=splits, shuffle=True, random_state=42)
reports = []
accuracy = []
for train, test in kfold.split(X, y):
model_fit = pipeline.fit(X[train], y[train])
class NetworkTest: XCTestCase {
func testGetContacts() {
let expectation = self.expectation(description: "contacts")
var contacts: [Contact]?
Network.shared.request(router: Router.getContacts) { (result: Result<[Contact]>) in
switch result {
case .success(let contactList):
contacts = contactList
class Network {
static let shared = Network()
private let config: URLSessionConfiguration
private let session: URLSession
private init() {
config = URLSessionConfiguration.default
session = URLSession(configuration: config)
}
enum Router {
case getContacts
case getContact(id: Int)
case createContact(body: [String: Any])
case updateContact(id: Int, body: [String: Any])
private static let baseURLString = "YOUR_BASE_URL_STRING"
private enum HTTPMethod {
case get