Skip to content

Instantly share code, notes, and snippets.

View YusufAbdelaziz's full-sized avatar
🎯
Focusing

Joe YusufAbdelaziz

🎯
Focusing
View GitHub Profile
@YusufAbdelaziz
YusufAbdelaziz / color_degree_manipulator.dart
Last active November 8, 2022 10:41
Lightens and darkens a material Color. Taken from a solution from StackOverflow.
import 'package:flutter/material.dart';
extension ColorDegree on Color {
Color darken([int percent = 10]) {
assert(1 <= percent && percent <= 100);
var f = 1 - percent / 100;
return Color.fromARGB(
this.alpha, (this.red * f).round(), (this.green * f).round(), (this.blue * f).round());
}
@YusufAbdelaziz
YusufAbdelaziz / text_size.dart
Created July 18, 2021 22:51
A method to know the width of a text before rendering it.
/// Finds the width of a text before rendering it.
Size findTextSize(
{required String text,
TextStyle style = textStyle,
required BuildContext context,
TextDirection textDirection = TextDirection.rtl}) {
final Size size = (TextPainter(
text: TextSpan(text: text, style: style),
maxLines: 5,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
@YusufAbdelaziz
YusufAbdelaziz / Brackets.java
Created July 8, 2021 02:58
Solving brackets sequence problem
package datastructures.main;
import java.util.Stack;
public class Brackets {
public static void main(String[] args) {
boolean isValid = false;
String inputString = "[()]()()()";
Stack<Character> myStack = new Stack<>();
boolean valid = true;
@YusufAbdelaziz
YusufAbdelaziz / linked-list.js
Created March 31, 2021 21:00
A linked list created in JavaScript.
//
// This is only a SKELETON file for the 'Linked List' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
/// Supposing that the list has at least one item.
class Node {
constructor(value, previous, next) {
this.value = value;
this.previous = previous;
@YusufAbdelaziz
YusufAbdelaziz / Dijkstra.java
Created October 29, 2020 20:02
Implementing Dijkstra from Grokking Algorithms
import java.util.*;
public class Dijkstra {
public static String findLowestNode(HashMap<String, Integer> costs, ArrayList<String> processedNodes) {
String lowestNode = null;
Integer lowestNodeVal = Integer.MAX_VALUE;
for (String node : costs.keySet()) {
if (lowestNodeVal > costs.get(node) && !processedNodes.contains(node)) {
@YusufAbdelaziz
YusufAbdelaziz / QuickSort.java
Created October 7, 2020 14:40
QuickSort in Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class QuickSort {
public static List<Integer> quickSort(List<Integer> array) {
if (array.size() < 2) {
return array;
} else {
import java.io.*;
import java.util.*;
public class problemSolving {
private static int getMajorityElement(int[] a) {
//Java's sort is a dual pivot quick sort which is basically O(nlog n)
Arrays.sort(a);
//We here set a counter to count the duplicated elements
@YusufAbdelaziz
YusufAbdelaziz / BinarySearch.java
Created March 28, 2020 21:50
Divide and conquer --> question 1
import java.io.*;
import java.util.*;
public class problemSolving {
static int binarySearch(int[] a, int x, int left, int right) {
if (left > right) {
return -1;
}
int middle = left + ((right - left) / 2);
@YusufAbdelaziz
YusufAbdelaziz / RandomizedQuickSort2.java
Created March 28, 2020 21:06
A faster quick sort with some recursive calls eliminated.
import java.util.Arrays;
import java.util.Random;
public class problemSolving {
static void RandomizedQuickSort(int[] array, int l, int r) {
//We first check if the left-most element index is greater than right-most element index
//This is considered as a base case to exit from infinite recursive calls
while (l < r) {
@YusufAbdelaziz
YusufAbdelaziz / RandomizedQuickSort.java
Created March 28, 2020 18:22
Quick sort with random pivot in java
import java.util.Arrays;
import java.util.Random;
public class problemSolving {
static void RandomizedQuickSort(int[] array, int l, int r) {
//We first check if the left-most element index is greater than right-most element index
//This is considered as a base case to exit from infinite recursive calls
if (l >= r) {