Skip to content

Instantly share code, notes, and snippets.

View Bahaaib's full-sized avatar
🎯
Focusing

Bahaa Abdelal Bahaaib

🎯
Focusing
View GitHub Profile
private static int equalizeArray(int[] arr) {
int[] index = new int[101];
int[] intrinsicIndex = new int[101];
int max = 0;
for (int i = 0; i < arr.length; i++) {
index[arr[i]]++;
}
//Select only Non-Zero integers
@Bahaaib
Bahaaib / Doctor.java
Created July 5, 2019 17:31
Doctor Date Problem
static String getStatusOfDoctorOpenedOrClosed(int[] doctorDays, int[] fromHour, int[] toHour) {
String opened = "Opened: Closes at 8 PM";
String closed = "Closed: Opens at Mon 4 PM";
int doctorWeekLength = doctorDays.length;
//Get Exact day of the week
Date date = new Date();
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int dayOfWeek = localDate.getDayOfWeek().getValue() + 1;
@Bahaaib
Bahaaib / git.sh
Last active May 29, 2019 01:36
Important git commands
##Fetch changes from remote repository to local machine
#Reference a remote repository locally under name 'upstream'
- git remote add upstream <link>
#De-reference a remote repository locally under name 'upstream'
- git remote rm upstream
#Fetch the new changes from upstream
- git fetch upstream
@Bahaaib
Bahaaib / RPS.cpp
Last active March 27, 2019 15:28
Cpp code to solve the Rock Paper Scissor problem
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char mPlayer = 'x';
int change = 0;
int position;
int pairPosition;
int round_num;
@Bahaaib
Bahaaib / RPS.java
Last active March 21, 2019 10:23
Java code to solve the Rock Paper Scissor problem
public class Solution {
private static int change;
private static int mIndex;
private static int mSubIndex;
private static int round;
private static boolean isMyTurn;
private static StringBuilder current, winner;
private static char player1 = 'x';
private static char player2 = 'x';
@Bahaaib
Bahaaib / pushNotification.js
Created January 29, 2019 13:20
Firebase Node js function that pushes notifications upon listening to database change
//import firebase functions modules
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// Listens for new messages added to messages/:pushId
exports.notificationSender = functions.database.ref('/messages/{pushId}').onWrite((change,context) => {
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
deque<int> addDeques(deque<int>& num1, deque<int>& num2);
int main()
{
#include <iostream>
#include <iomanip>
using namespace std;
int gcd(int a, int b);
long double lcm (long a, long b);
int main()
{
@Bahaaib
Bahaaib / RemoveNode.java
Created January 13, 2019 11:54
Remove node from Firebase DB
DatabaseReference testRef = mRef.child("test");
testRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot db : dataSnapshot.getChildren()){
db.child("isAvailable").getRef().setValue(null);
}
}
@Bahaaib
Bahaaib / addNewNode.java
Last active January 13, 2019 11:54
Add new key-value pair child in Firebase DB
DatabaseReference testRef = mRef.child("test");
ref.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
currentData.child("my new child").setValue(1);
return Transaction.success(currentData);
}
@Override
public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {