Skip to content

Instantly share code, notes, and snippets.

View kidap's full-sized avatar

Karlo Pagtakhan kidap

  • Toronto, Canada
View GitHub Profile
@kidap
kidap / test_data.md
Last active October 7, 2019 16:23
Creating test data

Type we want to test

struct Player {
    var name: String
    var age: String
    var address: String
    var wins: Int
    var losses: Int

    var hasWinningRecord: Bool {
#
# uncrustify config file for objective-c and objective-c++
#
indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs
output_tab_size = 4 # new tab size
indent_columns = output_tab_size
indent_label = 2 # pos: absolute col, neg: relative column
indent_align_assign = FALSE
const jwt = require('express-jwt');
const getTokenFromHeaders = (req) => {
const { headers: {authorization} } = req;
if (authorization && authorization.split(' ')[0] === 'Token') {
return authorization.split(' ')[1];
}
return null
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const session = require('express-session');
const cors = require('cors');
const mongoose = require('mongoose');
const errorHandler = require('errorHandler');
//Configure mongoose's promise to global promise
mongoose.promise = global.Promise;
class ManagedObjectContextObserver {
// MARK: - Private properties
private let context: NSManagedObjectContext
private let notificationCenter: NotificationCenter
private let notification: NSNotification.Name
private let trackTypes: [NSManagedObject.Type]
private let queue: DispatchQueue
private var observers: [NSObjectProtocol] = []
@kidap
kidap / gist:51d78bf345764380fe85406736839843
Last active August 17, 2018 15:57
XCode Playground - strong vs weak
import Foundation
class Restaurant {
var table: Table!
deinit{ print("Restaurant deinitialized") }
}
class Table {
weak var restaurant: Restaurant! //OPTION 1
@kidap
kidap / gist:26247bb7aaf0a41c104e160bd56e05c5
Created August 14, 2018 13:00
Cleanup Protocols/Objects that display or calculate totals
// MARK: Refundable
protocol Refundable {
var canBeRefunded: Bool { get }
var isRefunded: Bool { get }
var isARefund: Bool { get }
}
extension Bill: Refundable {
var canBeRefunded: Bool {
return isClosed && !isRefunded && !isARefund
`
fileprivate func createOperation(for job: Job) {
let jobUUID = job.objectID
guard let printer = job.printer else { return }
guard let operationQueue = operationQueue(of: printer) else { return }
let operation = BlockOperation.init {
let operationContext = FalconRecord.container.newBackgroundContext()
var operationJobDidChange = false
Recommendations
1. In FormOrderTableViewCell, move logic that changes color and font to awakeFromNib()
2. In OrderPickerView
2.1 Use the reset method of NSManagedObjectContext when OrderPickerView is not displayed
2.2 Change data structure of bills from [Date: [Bill]] to either [[(headerText, rows)]] or split it into 2 - headerTexts [String] and bills[[Bill]]
2.3 Instead of passing the Bill managed object to the UITableViewCell, map the values to an intermediary struct and pass that instead
2.4 Use UITableView directly and take out falcon
2.4.1 Option 1:
1. Start 2 fetches: <Fetch#1> to fetch initial objects to display(maybe the bills in the last 7 days), <Fetch#2> Fetch all bills (in the background)
2. Display <Fetch#1> right away.
@kidap
kidap / gist:a5f1536bde0ae69d98a5e24cd803211e
Created August 18, 2017 20:55
Error uploading BillItemMetaData
mutation($ubimd_upsertBillItemMetaData: [CreateBillItemMetaData], $idempotentCreateBills_idempotentCreateBills: [CreateBill]) {
bulk(upsertBillItemMetaData: $ubimd_upsertBillItemMetaData, idempotentCreateBills: $idempotentCreateBills_idempotentCreateBills) {
upsertBillItemMetaData {
_ref
}
idempotentCreateBills {
id
_ref
}
didSucceed