Skip to content

Instantly share code, notes, and snippets.

View AlShahawi's full-sized avatar

Ahmed Shahawi AlShahawi

View GitHub Profile
@AlShahawi
AlShahawi / First-non-repeating character.ts
Created September 22, 2025 13:53
First non-repeating character
const stringOne = "abccbad"; ===> Expected Output: "d";
const stringTwo = "abccba"; ===> Expected Output: null;
const stringThree = "xcsix"; ===> Expected Output: "c";
@AlShahawi
AlShahawi / SOLID-violations.ts
Last active September 22, 2025 13:50
SOLID-violations
// School Management System is a software application designed to manage students, teachers, and academic activities within a school.
// It streamlines operations such as enrollment, grading, and communication between staff and students.
// 1-
class School {
private students: string[] = [];
private teachers: string[] = [];
addStudent(name: string): void {
this.students.push(name);
setTimeout(function () {
console.log("A");
}, 1000);
setTimeout(function () {
console.log("B");
}, 0);
console.log("C");
@AlShahawi
AlShahawi / flatten-array-challenge.js
Last active June 27, 2024 11:56
Flatten Array Challenge
const arr = [[2, 3, [4]], 10, [5], [9, 7]];
// flatten logic.
console.log(arr); // [2, 3, 4, 10, 5, 9, 7]
@AlShahawi
AlShahawi / gist:5c79d900df21f4d569ada7e3b68d31bc
Created February 19, 2017 22:44 — forked from adrienne/gist:3180103
Haversine formula (PHP/MySQL)
/**
* Generates the string for the Haversine function. We assume that the `zipcode`, `latitude`,
* and `longitude` columns are named accordingly. We are also not doing much error-checking
* here; this is a simple text cruncher to make things prettier.
* We may also be integrating some extra SQL in, passed in via the $extra parameter
*
* @param string $table The table to search in
* @param float $lat The latitude part of the reference coordinates
* @param float $lng The longitude part of the reference coordinates
* @param int $radius The radius to search within
/*
* Codingame Power of thor Level Solution.
*
*
*/
var inputs = readline().split(' ');
var lightX = parseInt(inputs[0]); // the X position of the light of power
var lightY = parseInt(inputs[1]); // the Y position of the light of power
var x = parseInt(inputs[2]); // Thor's starting X position
var y = parseInt(inputs[3]); // Thor's starting Y position
@AlShahawi
AlShahawi / Adder.cs
Created February 7, 2016 06:01
UnitTesting Example.
using System;
namespace Adder
{
public class Adder
{
public int Add(int x, int y)
{
return x + y;
}
<?php
function factorial($number) {
if($number <= 1) return 1;
return $number*factorial($number-1);
}
function Person(name) {
this.name = name;
}
Person.prototype.greet = function (otherName) {
return "Hi, " + otherName + " my name is: " + this.name;
}
var ahmed = new Person("Ahmed");
alert(ahmed.greet("Mohamed")); // outputs "Hi!, Mohammed my name is Ahmed"