Skip to content

Instantly share code, notes, and snippets.

View elbeicktalat's full-sized avatar

Talat El Beick elbeicktalat

View GitHub Profile

How to create a Singleton Obejct using Dart

First of all why to create a Singleton object? The answer to this question is very simple, If you have a class or object that you use twice and you want to repeat using the same instance of it, you guest use a Singleton.

There are several ways to create a Singleton object each one of them shine for specific using.

I will show you how to create a Singleton and Which/Why approach to use.

@elbeicktalat
elbeicktalat / barcode.vba
Created December 11, 2023 20:42
Insert BarCode (image) into Excel Sheet
Sub InsertBarCode()
' Delete all inserted pictures, this will help us to delete BarCodes before creating new one.
ActiveSheet.Pictures.Delete
' Your data, can be whatever such as color, style number etc.
Data = Cells(2, 1)
FilePath = "https://barcode.tec-it.com/barcode.ashx?data=" & Data
@elbeicktalat
elbeicktalat / Worksheet_Change.vba
Last active December 11, 2023 20:44
Excel cell change event listener
' 1) Open the developer mode
' 2) On the left bar, under `Microsoft Excel Objects` tab open your sheet you want to observe changes
' 3) Paste the code you find below
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' run you code when they are changed.
Set KeyCells = Range("A1:A3")
@elbeicktalat
elbeicktalat / CookiesManager.java
Created August 23, 2023 16:33
Selenium java cookies manager. Contains save delete and load methods.
package com.elbeicktalat;
import lombok.RequiredArgsConstructor;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.json.Json;
import java.io.File;
@elbeicktalat
elbeicktalat / Image_color_picker.dart
Last active May 18, 2022 12:53
Extract color palette from an image in Flutter.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:palette_generator/palette_generator.dart';
void main() => runApp(const MyApp());
// need to change
const String _imagePath = 'assets/images/profiles/onboarding_1.jpg';
const String _appName = 'Color Picker';
@elbeicktalat
elbeicktalat / main.dart
Created November 21, 2021 12:42
Dart null-safety singleton pattern with parameters.
void main() {
Person personA = Person();
Person personB = Person();
print(personA);
print(personB);
print(identical(personA, personB)); // if this return `true`, that mains this class is singleton.
}
@elbeicktalat
elbeicktalat / colors.dart
Last active November 21, 2021 12:44
How to call print( ); with colorful text to console in dart.
class Colors {
static String black(String text) {
return '\x1B[30m$text\x1B[0m';
}
static String red(String text) {
return '\x1B[31m$text\x1B[0m';
}
static String green(String text) {