Skip to content

Instantly share code, notes, and snippets.

View gunantosteven's full-sized avatar
👊
Work from home

Steven Gunanto gunantosteven

👊
Work from home
View GitHub Profile
@gunantosteven
gunantosteven / gist:16978d720ecc5668689c39a85f1df782
Created November 14, 2021 01:38
Combining snapshot firestore flutter
import 'package:async/async.dart';
final Stream<QuerySnapshot> stream0 = collectionReference
.snapshots();
final Stream<QuerySnapshot> stream1 = collectionReference
.snapshots();
return StreamZip([stream0, stream1]).asBroadcastStream();
@gunantosteven
gunantosteven / ErrorWidgetPage
Created May 12, 2021 14:31
ErrorWidgetPage
void main() {
ErrorWidget.builder = (FlutterErrorDetails details) {
return ErrorWidgetPage(details);
};
runApp(MyApp());
}
class ErrorWidgetPage extends StatelessWidget {
ErrorWidgetPage(this.details);
@gunantosteven
gunantosteven / gist:36c96295b2799f866a0a0e241ed492fb
Created March 21, 2021 10:10
Firebase Cloud Backup Function
const functions = require("firebase-functions");
const firestore = require("@google-cloud/firestore");
const client = new firestore.v1.FirestoreAdminClient();
// Replace BUCKET_NAME
const bucket = "gs://firestore_backups_ivadmin_app";
exports.scheduledFirestoreExport = functions.pubsub
.schedule("every 24 hours")
.onRun((context) => {
// Line 73
func viewDidDisappearFromContainer() {
if let visibleIP = visibleIP {
if let listSocialCell = tableView.cellForRow(at: visibleIP) as? ListSocialTableViewCell,
listSocialCell.photo.isVideo {
listSocialCell.stopPlayback()
}
// after cell
if let listSocialCell = tableView.cellForRow(at: IndexPath(row: visibleIP.row + 1, section: visibleIP.section)) as? ListSocialTableViewCell,
listSocialCell.photo.isVideo {
@gunantosteven
gunantosteven / Filename
Created May 14, 2020 15:16
Create Button Auth Facebook FBLoginButton Full Width
class SettingsSignInTableViewCell: UITableViewCell {
@IBOutlet private var viewFBLoginButton: UIView! {
didSet {
// Add tap gesture
let tapViewFBLoginButton = UITapGestureRecognizer(
target: self, action: #selector(SettingsSignInTableViewCell.tapViewFBLoginButton(_:)))
tapViewFBLoginButton.numberOfTapsRequired = 1
viewFBLoginButton.isUserInteractionEnabled = true
viewFBLoginButton.addGestureRecognizer(tapViewFBLoginButton)
}
@gunantosteven
gunantosteven / File
Last active May 9, 2020 16:00
Implement SkeletonView in iOS Swift 5
import SkeletonView
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCategoryTableViewCell",
for: indexPath) as? HomeCategoryTableViewCell
return cell
}
extension ViewController: SkeletonTableViewDataSource {
func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
@gunantosteven
gunantosteven / File
Created April 30, 2020 15:44
Create UICollectionView Like Instagram When Exploring Photos
import UIKit
class SavedCollectionViewLayout: UICollectionViewLayout {
private let columnsCount = 18 // 18 type columns
private let numberOfColumns = CGFloat(3.0)
private let minimumLineSpacing: CGFloat = 2
private let minimumInteritemSpacing: CGFloat = 2
private var cache: [UICollectionViewLayoutAttributes] = []
private var contentHeight: CGFloat = 0
private var contentWidth: CGFloat {
@gunantosteven
gunantosteven / File
Created April 22, 2020 12:37
Make Difference between Double Tap and Single Tap in UIView
let tapImagePhoto = UITapGestureRecognizer(target: self, action: #selector(YourClass.tapImagePhoto))
tapImagePhoto.numberOfTapsRequired = 2
videoPlayerSuperView.addGestureRecognizer(tapImagePhoto)
let tapPlayPause = UITapGestureRecognizer(target: self, action: #selector(YourClass.tapPlayPause))
tapPlayPause.numberOfTapsRequired = 1
videoPlayerSuperView.addGestureRecognizer(tapPlayPause)
tapPlayPause.require(toFail: tapImagePhoto2) // important code
@gunantosteven
gunantosteven / File
Last active April 14, 2020 13:31
Be Careful with "UI API called on a background thread"
self.view.makeToastActivity(.center)
DispatchQueue.global(qos: .background).async {
if let url = URL(string: self.photo.url),
let urlData = NSData(contentsOf: url)
{
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath="\(documentsPath)/tempFile.mp4"
urlData.write(toFile: filePath, atomically: true)
PHPhotoLibrary.shared().performChanges({
let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: filePath))
@gunantosteven
gunantosteven / File
Created April 8, 2020 03:14
How to cache image for temporary use iOS Swift 5
import UIKit
class ImageCache {
static func getImage(urlString: String) -> UIImage? {
if let dict = UserDefaults.standard.object(forKey: "ImageCache") as? [String:String] {
if let path = dict[urlString] {
if let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
let img = UIImage(data: data)
return img
}