Skip to content

Instantly share code, notes, and snippets.

View unix14's full-sized avatar
👋
Hi there

Eyal Yaakobi unix14

👋
Hi there
View GitHub Profile
@unix14
unix14 / BagTripsCalculator.java
Created November 29, 2023 17:45
Small bags per trips calculator algorithm
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
public class BagTripsCalculator {
// Default const values 1.01-3.0Kg
static final float MINIMUM_WEIGHT = 1.01f;
static final float MAXIMUM_WEIGHT = 3f;
@unix14
unix14 / date_extensions.dart
Created December 10, 2023 01:22
simpler date formatter - human readable date
import 'package:intl/intl.dart';
String getFormattedDate(_date) {
var inputFormat = DateFormat('yyyy-MM-dd HH:mm');
var inputDate = inputFormat.parse(_date);
var outputFormat = DateFormat('dd/MM/yyyy HH:mm');
// Calculate time difference
final timeDifference = DateTime.now().difference(inputDate);
@unix14
unix14 / file_cache.dart
Created January 2, 2024 21:48
FileCache lib
import 'dart:io';
import 'dart:convert';
class FileCache {
// The directory where the cache files are stored
final Directory cacheDir;
// The constructor that takes the cache directory as a parameter
FileCache(this.cacheDir);
@unix14
unix14 / smart_image_loader.dart
Created October 7, 2024 09:49
A Flutter widget that intelligently loads network images and SVGs with support for customization (width, height, fit, alignment) and error handling. Depends on flutter_svg lib
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:path/path.dart' as Path;
class SmartImageLoader extends StatefulWidget {
final String imageUrl;
// add others image params like width height fit , alignment, errorBuilder
final double? width;
final double? height;
@unix14
unix14 / firebase_storage_manager.dart
Last active October 9, 2024 12:10
This is a singleton class that handles file uploads and downloads for both web and mobile using Firebase Storage. Depends on firebase_storage lib
import 'dart:io';
import 'package:firebase_storage/firebase_storage.dart' as fbStorage;
import 'package:flutter/foundation.dart';
class FirebaseStorageManager {
static final FirebaseStorageManager _instance = FirebaseStorageManager._();
factory FirebaseStorageManager() {
return _instance;
@unix14
unix14 / maps_extension.dart
Created October 9, 2024 12:04
Provides utility functions and extensions for Map objects. It includes methods to print map details, get changes between two maps in string and map formats, and revert changes for a specific key in a map
extension MapsExtension on Map {
void printAll() {
this.forEach((key, value) {
print('Key: $key Value: $value');
});
}
String printAllKeys() {
@unix14
unix14 / smart_image_uploader.dart
Last active October 9, 2024 12:09
SmartImageUploader class in the Dart file provides a method to upload a file to Firebase. It first opens a file picker for the user to select a file. After a file is selected, it extracts the file extension and appends it to the provided path. Then, it uploads the file to Firebase Storage. If the upload is successful, it retrieves and returns th…
import 'dart:io';
import 'dart:typed_data';
import 'package:file_picker/file_picker.dart';
import 'firebase_storage_manager.dart';
class SmartImageUploader {
@unix14
unix14 / 404.html
Created October 28, 2024 17:03
Custom 404 error page with a bouncing ball animation, a message, and a button to redirect users back to the main site. Styled with internal CSS and includes a media query for responsiveness.
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
@unix14
unix14 / feature_generator.dart
Last active February 10, 2025 15:13
This Dart script generates a feature folder structure for a Flutter project. It creates the necessary folders and files based on the provided feature name and optional components (screens and widgets). If no components are specified, it generates the entire structure.
/// Feature Generator Script
///
/// This script generates a feature folder structure for a Flutter project.
/// It creates the necessary folders and files based on the provided feature name
/// and optional components (screens and widgets). If no components are specified,
/// it generates the entire structure.
///
/// Usage:
///
/// To generate the entire feature structure:
@unix14
unix14 / logger.dart
Created January 26, 2025 13:51
A simple colorized logger for Dart. dependent on ansi_styles library.
import 'package:ansi_styles/ansi_styles.dart';
//*** Enums ***//
/// This enum is used to define the log level
/// It has four values: debug, error, warning, info
enum LogLevel {
info,
debug,
warning,