Skip to content

Instantly share code, notes, and snippets.

@bysensa
bysensa / stable_scroll_position_list.dart
Created November 15, 2024 11:21
Simple implementation of list where scroll position not changed when adding elements at top
import 'package:flutter/material.dart';
/// Flutter code sample for [CustomScrollView].
void main() => runApp(const CustomScrollViewExampleApp());
class CustomScrollViewExampleApp extends StatelessWidget {
const CustomScrollViewExampleApp({super.key});
@override
@bysensa
bysensa / 0.flutter.helpers.md
Last active January 28, 2025 18:12
Flutter/Dart helpers

Intro

Gist with code to build flutter apps easily

@bysensa
bysensa / async-test.dart
Last active October 11, 2022 21:15
Solution to deal with async instances
import 'package:flutter_test/flutter_test.dart';
import 'package:async/async.dart';
class TestValue {}
void main() {
test('should call factory only once', () async {
var callCount = 0;
final asyncClass = Async(() async {
callCount += 1;
@bysensa
bysensa / iOSProjectFolderStructure.swift
Created February 4, 2022 20:09 — forked from sergigracia/iOSProjectFolderStructure.swift
How to organize an Xcode project? This is a folder structure proposal for an iOS project.
App
Coordinators // Views management
UI // Grouped by features/viewHierarchy
General // Custom textfield, picker
FeatureA
A.swift
AView.swift
AController.swift
AppExtensions // Specific code for extensions
Watch
@bysensa
bysensa / get_title_and_url.applescript
Created December 22, 2021 23:49 — forked from vitorgalvao/Get Title and URL.applescript
AppleScript and JavaScript for Automation to get frontmost tab’s url and title of various browsers.
-- AppleScript --
-- This example is meant as a simple starting point to show how to get the information in the simplest available way.
-- Keep in mind that when asking for a `return` after another, only the first one will be output.
-- This method is as good as its JXA counterpart.
-- Chromium variants include "Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge".
-- Specific editions are valid, including "Google Chrome Canary", "Microsoft Edge Dev".
-- "Google Chrome" Example:
tell application "Google Chrome" to return title of active tab of front window
@bysensa
bysensa / MEH.md
Created April 27, 2021 09:42 — forked from jehugaleahsa/MEH.md
Minimal Exception Handling

Minimal Exception Handling

Introduction

With so many other aspects of daily development completely unattainable by your average developer, exception handling is often ignore in lieu of bigger fish to fry. On the surface, exception handling appears sufficiently complicated enough that most developers have simply resolved to ignore it on a day-to-day basis or altogether. Only during the last weeks of development do they tack on a top-level try/catch block to avoid complete system failure or to log that "some" error occurred. Rather than a simple error dialog appearing to users, they are greeted with the "yellow screen of death". Even when the developer does manage to display an error dialog, the message is often vague or cryptic, e.g., "An error occurred".

We can do better than this. I believe the issue is that not a lot of focus has been given to providing simple, bare-minimum exception handling. For the majority of applications, exception handling only needs to satisfy the following requirements:

@bysensa
bysensa / DecodeQRCodeFromUIImage.swift
Created April 19, 2021 21:40
Extract QR Code data as CIQRCodeFeature from UIImage
extension UIImage {
func qrCodes() -> [CIQRCodeFeature] {
guard let image = CIImage(image: self) else {
return []
}
let detector = CIDetector(
ofType: CIDetectorTypeQRCode,
context: nil,
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
@bysensa
bysensa / overridable_operators.dart
Created February 22, 2021 21:56
Dart overridable operators
extension on Object {
Object operator | (Object some) {}
Object operator & (Object some) {}
Object operator + (Object some) {}
Object operator - (Object some) {}
Object operator * (Object some) {}
Object operator / (Object some) {}
Object operator ^ (Object some) {}
Object operator >> (Object some) {}
Object operator << (Object some) {}
@bysensa
bysensa / as_a.dart
Created February 21, 2021 13:26
Mapping utils for easily type casting and complex objects build
import 'dart:async';
import 'package:quiver/core.dart';
import 'package:stack_trace/stack_trace.dart';
typedef AsValueProvider = Object Function();
Optional<T> asA<T>(AsValueProvider provider) {
final handledExceptions = <CaughtException>[];
final providedValue = Chain.capture(
@bysensa
bysensa / flutter_color_swatches.dart
Created January 23, 2021 10:19
Color Swatches for Flutter
import 'package:flutter/rendering.dart';
//+─────────────────────────────────────────────────────────────────────────
//+ Blue Grey
//+─────────────────────────────────────────────────────────────────────────
const blueGrey0 = Color.fromRGBO(240, 244, 248, 1);
const blueGrey1 = Color.fromRGBO(217, 226, 236, 1);
const blueGrey2 = Color.fromRGBO(188, 204, 220, 1);
const blueGrey3 = Color.fromRGBO(159, 179, 200, 1);
const blueGrey4 = Color.fromRGBO(130, 154, 177, 1);