Skip to content

Instantly share code, notes, and snippets.

View DineshKachhot's full-sized avatar
🎯
Focusing

Dinesh Kachhot DineshKachhot

🎯
Focusing
View GitHub Profile
@DineshKachhot
DineshKachhot / NSTimeInterval+AudioDurationFormat.swift
Created August 29, 2019 06:49
Audio/Video Duration formate in Swift 4.2
import Foundation
extension TimeInterval {
struct DateComponents {
static let formatterPositional: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour,.minute,.second]
formatter.unitsStyle = .positional
formatter.zeroFormattingBehavior = .pad
return formatter
@gireesh092
gireesh092 / database_helper.dart
Created April 6, 2019 12:23
Flutter : Database helper boiler code
import 'package:sqflite/sqflite.dart';
import 'dart:async';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:notebuddy/models/note.dart';
class DatabaseHelper {
static Database _database;
static DatabaseHelper _databaseHelper; //SINGLETON DBHELPER
@DineshKachhot
DineshKachhot / time_ago_since_now.dart
Created March 1, 2019 06:08
Flutter Time ago calculator
static String timeAgoSinceDate(String dateString, {bool numericDates = true}) {
DateTime date = DateTime.parse(dateString);
final date2 = DateTime.now();
final difference = date2.difference(date);
if ((difference.inDays / 365).floor() >= 2) {
return '${(difference.inDays / 365).floor()} years ago';
} else if ((difference.inDays / 365).floor() >= 1) {
return (numericDates) ? '1 year ago' : 'Last year';
} else if ((difference.inDays / 30).floor() >= 2) {
@ffeu
ffeu / main.dart
Created August 3, 2018 00:18
Flutter Main Example with StreamBuilder
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
@DineshKachhot
DineshKachhot / Array+FilterUniqueByKey.swift
Created July 12, 2018 05:14
Array extension to return the unique list of objects based on a given key.
extension Array {
func unique<T:Hashable>(by: ((Element) -> (T))) -> [Element] {
var set = Set<T>() //Keep unique list in a Set for fast retrieval
var orderedArray = [Element]() //Keeping the unique list of elements but ordered
for value in self {
if !set.contains(by(value)) {
set.insert(by(value))
orderedArray.append(value)
}
}
/*
Problem:
['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
// YOUR ALGORITHM
@branflake2267
branflake2267 / main.dart
Created April 16, 2018 01:18
Flutter - Using the Refresh Indicator
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
@branflake2267
branflake2267 / main.dart
Last active May 7, 2021 03:36
Flutter - Navigation Drawer Left or Right
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
@hfossli
hfossli / SHA256-Bridging-Header.h
Last active April 9, 2024 01:05
AES 256 in swift 4 with CommonCrypto
#import <CommonCrypto/CommonCrypto.h>
@Deub27
Deub27 / UIStackView+removeAll.swift
Created November 25, 2017 14:00
Remove all arranged subviews from UIStackView at once
import UIKit
extension UIStackView {
func removeAllArrangedSubviews() {
let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in
self.removeArrangedSubview(subview)
return allSubviews + [subview]
}