Skip to content

Instantly share code, notes, and snippets.

Avatar

Sagar Kothari sag333ar

View GitHub Profile
View custom_circle_avatar.dart
import 'package:flutter/material.dart';
class CustomCircleAvatar extends StatelessWidget {
const CustomCircleAvatar(
{Key? key, required this.height, required this.width, required this.url})
: super(key: key);
final double height;
final double width;
final String url;
@sag333ar
sag333ar / form_factor.dart
Created Jan 25, 2022
Flutter - Dart - Get the type of the device based on device width.
View form_factor.dart
import 'package:flutter/material.dart';
enum ScreenType {
desktop,
tablet,
handset,
watch,
}
class FormFactor {
@sag333ar
sag333ar / flutter_seconds_to_duration.dart
Created Jan 25, 2022
Flutter - Seconds to Duration
View flutter_seconds_to_duration.dart
// 4515 seconds to
// (60 * 60 * 1) + (15 * 60) + (15)
// 01:15:15
class Utilities {
static String formatTime(int seconds) {
return '${(Duration(seconds: seconds))}'
.split('.')[0]
.padLeft(8, '0');
}
}
@sag333ar
sag333ar / DeleteSlackUploads.py
Created Sep 19, 2016
Delete slack uploads older than 30 days.
View DeleteSlackUploads.py
import requests
import json
import calendar
from datetime import datetime, timedelta
_token = "your token here"
_domain = "your domain here"
if __name__ == '__main__':
while 1:
@sag333ar
sag333ar / script_1x2x3x.sh
Last active Feb 4, 2020
Generate 1x 2x 3x images from supplied 3x assets. Following shell-script can be used for iOS Asset catalogue.
View script_1x2x3x.sh
for f in *.png
do
# Process to get File Name & 2x, 3x file names
xNAME=`echo "$f" | cut -d'.' -f1`
cp "$f" "$xNAME@3x.png"
cp "$f" "$xNAME@2x.png"
# Set proper resolution to original file
sips -s dpiHeight 72.0 -s dpiWidth 72.0 "$f"
@sag333ar
sag333ar / transparentNavBar.m
Created Oct 19, 2015
Transparent Navigation Bar
View transparentNavBar.m
- (void)applyTransparencyToNavigationControllersBar:(UINavigationController *)nvCtr {
nvCtr.navigationBar.translucent = YES;
nvCtr.navigationBar.shadowImage = [UIImage new];
nvCtr.view.backgroundColor = [UIColor clearColor];
[nvCtr.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
nvCtr.navigationBar.backgroundColor = [UIColor clearColor];
}
@sag333ar
sag333ar / ParseJSONData.swift
Last active Oct 10, 2015
Load Data from file & parse JSON in Swift 2
View ParseJSONData.swift
// Swift 2
// try will throw an error if there any &
// catch will directly catch with 'error'
let str:String? = NSBundle.mainBundle().pathForResource("IndiaPost", ofType: "json")
let data:NSData? = NSData(contentsOfFile: str!)
do {
let jsonData:AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)
@sag333ar
sag333ar / GenerateAppIcons.sh
Last active Oct 8, 2016
Generate all Icons in single shot by providing 1024x1024.png as an input.
View GenerateAppIcons.sh
cp 1024x1024.png AppIcon-20.png
sips -Z 20 AppIcon-20.png
cp 1024x1024.png AppIcon-20@2x.png
sips -Z 40 AppIcon-20@2x.png
cp 1024x1024.png AppIcon-20@3x.png
sips -Z 60 AppIcon-20@3x.png
cp 1024x1024.png AppIcon-29.png
@sag333ar
sag333ar / Exercise3.swift
Last active Aug 29, 2015
Exercise3 : Declaring / modifying / displaying an array. Declaring / modifying / displaying key-valued array. Creating empty array & key-valued empty array.
View Exercise3.swift
//: Playground - noun: a place where people can play
// The Swift Programming Language
// Basics of Array & key-valued array
import UIKit
var str = "Hello, playground"
// creating / declaring an array
var shoppingList = ["catfish", "water", "tulips", "blue paint"]
@sag333ar
sag333ar / Exercise2.swift
Created Aug 19, 2015
Exercise2 : String operation - Inserting values of variables in a string using \()
View Exercise2.swift
//: Playground - noun: a place where people can play
// The Swift Programming Language
// iBook Page 6 (13" screen display with full screen)
// Basic string operations
import UIKit
// declare two variables
let apples = 3
let oranges = 5