Skip to content

Instantly share code, notes, and snippets.

View anoop4real's full-sized avatar

anoop4real anoop4real

View GitHub Profile
@anoop4real
anoop4real / simplewebviewflutter.dart
Last active October 11, 2023 18:27
WebviewSample
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
class SimpleWebview extends StatefulWidget {
@override
_SimpleWebviewState createState() => _SimpleWebviewState();
}
@anoop4real
anoop4real / result.dart
Created November 30, 2020 21:55
Dart Result type
enum ResultStatus { success, error }
class Result<T, E> {
final E error;
final T value;
final ResultStatus status;
const Result.success(this.value)
: status = ResultStatus.success,
error = null;
@anoop4real
anoop4real / featureflags.dart
Created November 7, 2020 12:48
Dart: Featureflags
enum Environment {
dev,
qa,
prod,
}
enum FeatureType {
feature1,
feature2,
}
enum Environment {
case dev
case qa
case prod
}
enum FeatureType {
case feature1
case feature2
@anoop4real
anoop4real / CapsuleSegmentedControl.playground
Last active September 15, 2022 06:52
CapsuleSegmentedControl
import UIKit
import PlaygroundSupport
// Ref: https://stackoverflow.com/questions/58315497/selectedtintcolor-of-segment-control-is-not-rounded-corner-on-ios-13
class CapsuleSegmentedControl: UISegmentedControl {
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = self.bounds.size.height / 2.0
layer.borderColor = UIColor.gray.cgColor
layer.borderWidth = 1.0
layer.masksToBounds = true
@anoop4real
anoop4real / stackview.playground
Created August 4, 2020 10:06
A sample code to show custom width/ height proportion in stackview
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
self.view = view
setUpView()
//setUpViewVertical()
@anoop4real
anoop4real / Snippet.md
Last active March 18, 2023 05:18
No Storyboard scene delegate snippet

Snippet for my video No Storyboards

SWIFT

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let windowScene = (scene as? UIWindowScene) else { return }
@anoop4real
anoop4real / LeadingEllipsis.swift
Created April 6, 2020 15:13
A Swift string extension for adding leading ellipsis
extension String {
func stringByTruncatingLeadingForWidth(width: CGFloat, withFont font: UIFont) -> String{
var modifiedString = self
var mutableWidth = width
let ellipsis = "..."
if (self.widthOfString(usingFont: font) > width) {
let ellipsisWidth = ellipsis.widthOfString(usingFont: font)
@anoop4real
anoop4real / JMESquery.md
Created March 16, 2020 18:15
JMESquery

Sample query

[? area > 1000 && contains('["Asia","Europe"]',region)] | sort_by(@, &capital) | [*].{alpha2Code: alpha2Code, area: area, callingCodes: callingCodes[0], capital: capital, flag: flag, name: name, nativeName: nativeName, numericCode: numericCode, regionValue:region}

@anoop4real
anoop4real / ColorGen.playground
Last active January 18, 2020 16:29
A small utility to generate color hash from string for Swift and also generate UIColor
import UIKit
func generateColorFor(text: String) -> UIColor{
var hash = 0
let colorConstant = 131
let maxSafeValue = Int.max / colorConstant
for char in text.unicodeScalars{
if hash > maxSafeValue {
hash = hash / colorConstant
}