Skip to content

Instantly share code, notes, and snippets.

View gist:3eb22042afa691b3213032541a350716
<activity android:name="com.yocto.wenote.widget.SortLauncherFragmentActivity"
android:label="PRINT"
android:noHistory="true"
android:taskAffinity="com.yocto.wenote.launcher"
android:theme="@style/Theme.Transparent"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.item/vnd.socialnmobile.colornote.note.title"/>
View gist:bd3f4bf43116027f74f60a2b0bc81ae0
if (shareIntent.resolveActivity(context.getPackageManager()) != null) {
List<Intent> targetedShareIntents = new ArrayList<>();
Intent x = new Intent(Intent.ACTION_SEND);
x.setClassName("com.yocto.wenote",
"com.yocto.wenote.widget.SortLauncherFragmentActivity");
x.setType("vnd.android.cursor.item/vnd.socialnmobile.colornote.note.title");
targetedShareIntents.add(x);
final Intent chooserIntent = Intent.createChooser(shareIntent, context.getString(R.string.share_note));
View gist:4313ed81967226a31db6d12e0e431d49
SELECT id, "order" FROM plain_note WHERE archived = :archived AND trashed = :trashed ORDER BY "order" ASC
to
private func getUpdateOrdersBasedOnX(context: NSManagedObjectContext, sortDescriptors: [NSSortDescriptor], archived: Bool, trashed: Bool) -> [UpdateOrder] {
let predicate = NSPredicate(format: "archived == %i AND trashed == %i", (archived ? 1 : 0), (trashed ? 1 : 0))
// https://stackoverflow.com/a/64964284/72437
let objectIDExpression = NSExpressionDescription()
objectIDExpression.name = "objectID"
@yccheok
yccheok / gist:1a78fa08a88cfebc4a10d2288d334032
Last active Aug 27, 2021
startOfDay computation is required when during Day light saving, Cuba starts its day @ 1:00am
View gist:1a78fa08a88cfebc4a10d2288d334032
let cubaTimeZone = TimeZone(identifier: "America/Havana")!
var cubaCalendar = Calendar(identifier: .gregorian)
cubaCalendar.timeZone = cubaTimeZone
let t: TimeInterval = 1615698000
let date0 = Date(timeIntervalSince1970: t-1)
let date1 = Date(timeIntervalSince1970: t)
let date2 = Date(timeIntervalSince1970: t+1)
let date3 = Date(timeIntervalSince1970: t+2)
@yccheok
yccheok / gist:b660cc09b404ae3bab3eb4a586c33cc8
Created Aug 22, 2021
zoomable and swipeable image viewer
View gist:b660cc09b404ae3bab3eb4a586c33cc8
//
// MyPaveViewController.swift
// zzz
//
// Created by Yan Cheng Cheok on 22/08/2021.
//
import UIKit
class MyPageViewController: UIPageViewController {
View gist:35c31a29e7f9eebdccfdc7cdfe9fe724
else if type == NSFetchedResultsChangeType.move {
// A hackish way to ensure PIN icon is updated.
if let newIndexPath = newIndexPath, let indexPath = indexPath {
if let plainNote = nsPlainNoteProvider.getNSPlainNote(newIndexPath), let noteCell = collectionView.cellForItem(at: indexPath) as? NoteCell {
noteCell.update(
plainNote,
selected: false,
animate: false
)
View gist:9a9357d2e0bb152a85ba8ce34b32c0b0
func updateOrders(_ updates : [(objectID: NSManagedObjectID, order: Int64)]) {
if updates.isEmpty {
return
}
let coreDataStack = CoreDataStack.INSTANCE
let backgroundContext = coreDataStack.backgroundContext
backgroundContext.perform {
var objectIDs: [NSManagedObjectID] = []
View gist:c29a3c6fa059fde36305d1d53bbcc5ff
//
// ONE nsPlainNote has MANY attachments
// ONE attachment has ONE nsPlainNote
//
nsPlainNote.removeFromAttachments(attachment)
//
// This line is required. If not, we will have an attachment without nsPlainNote.
//
@yccheok
yccheok / gist:95c0457e4187ca8c7e962b5899890212
Created Jul 9, 2021
find out the location of SQLite file in iOS
View gist:95c0457e4187ca8c7e962b5899890212
func getCoreDataDBPath() {
let path = FileManager
.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)
.last?
.absoluteString
.replacingOccurrences(of: "file://", with: "")
.removingPercentEncoding
print("Core Data DB Path :: \(path ?? "Not found")")
View gist:568e325bb6f4bacda5dc91ae30e87f7e
class NoFadeFlowLayout: UICollectionViewFlowLayout {
override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)
attrs?.alpha = 1.0
return attrs
}
override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath)