Skip to content

Instantly share code, notes, and snippets.

@ninjitaru
ninjitaru / coredata.swift
Created September 10, 2021 07:58
NSAsynchronousFetchRequest test
let asyncRequest = NSAsynchronousFetchRequest(fetchRequest: request) { fetchResult in
// this may or may not right in the same thread as the context thread
// except when the context is main thread, this will always run in main thread
// TODO: can i access NSManagedObject safely if this is not the same thread?
print("ttt: blk thread: \(Thread.current)")
Thread.sleep(forTimeInterval: 100)
guard let dataResult = fetchResult.finalResult else {
return
}
@ninjitaru
ninjitaru / gist:9124fc157363a80b68e7c4c231477d31
Created December 24, 2019 09:35
Get reservation table history
async function printReservation() {
const companyId = '-Kl2_DOjdmBh4Rlj58C1';
const branchId = '-Kl2_DOjdmBh4Rlj58C2';
const db = getCachedAdminDB(companyId);
const tableData = (await db.ref(`branchTables/${companyId}/${branchId}`).once('value')).val();
const tableMap = {};
for (const [sectionId, section] of Object.entries(tableData)) {
for (const [tableId, table] of Object.entries(section.tables)) {
{
reservations/-Kl2_DOjdmBh4Rlj58C1/-Kl2_DOjdmBh4Rlj58C2/-LuuTCKCHkZS-_MRRLLH/autoTableIds: [
0: "-Kl7-4NnyHWpkLXNXzVj"
]
reservations/-Kl2_DOjdmBh4Rlj58C1/-Kl2_DOjdmBh4Rlj58C2/-Luuw9YunML-YZ7Jy6Al/autoTableIds: [
0: "-Kl3S7kPpTA9V_570Q7e"
1: "-Kl3S8vGcRe0f4WnEe-Z"
2: "-Kl3SAkzCGky85zAR41B"
3: "-Kl7-7CYtKKHM4-HIUT9"
]
{
reservations/-Kl2_DOjdmBh4Rlj58C1/-Kl2_DOjdmBh4Rlj58C2/-LuuTCKCHkZS-_MRRLLH/autoTableIds: [
0: "-Kl7-4NnyHWpkLXNXzVj"
]
reservations/-Kl2_DOjdmBh4Rlj58C1/-Kl2_DOjdmBh4Rlj58C2/-Luuw9YunML-YZ7Jy6Al/autoTableIds: [
0: "-Kl3S7kPpTA9V_570Q7e"
1: "-Kl3S8vGcRe0f4WnEe-Z"
2: "-Kl3SAkzCGky85zAR41B"
3: "-Kl7-7CYtKKHM4-HIUT9"
]
const { redis, getSubscriber, subscribeWithSubscriber, publish } = require('applib/redis');
const _ = require('lodash');
// 1 ~ 80ms
// 10 ~ 80ms
// 100 ~ 80ms
// 1000 ~ 90ms
// 10000 ~ 200ms
// spread across 10 client
@ninjitaru
ninjitaru / gist:b82557a6ccad653bc2a0
Last active August 29, 2015 14:11
iOS 8+ open app setting
if(&UIApplicationOpenSettingsURLString) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
@ninjitaru
ninjitaru / gist:88879b4e3cca35ba2e08
Created November 9, 2014 09:04
gen localized string on xcode
genstrings -o zh-Hant.lproj *.m
// only need 112 bit for 14 ascii character
LDPC_Parity_Irregular H;
H.generate(224,
"0 0.27684 0.28342 0 0 0 0 0 0.43974",
"0 0 0 0 0 0.01568 0.85244 0.13188",
"rand", // random unstructured matrix
"500 8"); // optimize girth
LDPC_Generator_Systematic G(&H);
LDPC_Code C(&H, &G);
C.set_exit_conditions(2500);
@ninjitaru
ninjitaru / gist:761d76ac3219a969d054
Last active August 29, 2015 14:01
build facebook aar
cd facebook-sdk/facebook
open build.gradle modify buildToolsVersion
run gradle from compatable version
gradle build
facebook.aar is in build/libs/
@ninjitaru
ninjitaru / gist:8629482
Last active January 4, 2016 13:39
git add deleted files
git rm $(git ls-files --deleted)
git ls-files --deleted --exclude-standard -z | while read -r -d '' file; do
git rm "$file"
done