Skip to content

Instantly share code, notes, and snippets.

View code2be's full-sized avatar
🎯
Focusing

Ahmed Hosny code2be

🎯
Focusing
  • Egypt
  • 03:28 (UTC +02:00)
View GitHub Profile
# Formula Calculator
formula = input("Enter the formula")
# 35 + 12
# 47
x = formula.find("+")
a = float(formula[:x])
b = float(formula[x+1:])
x = float(input("Enter first number"))
y = float(input("Enter second number"))
o = input("Enter operator") # + - / * %
if o == "+":
print(x + y)
elif o == "-":
print(x - y)
elif o == "*":
x = float(input("Enter first number"))
y = float(input("Enter second number"))
o = input("Enter operator") # + - / * %
if o == "+":
print(x + y)
elif o == "-":
print(x - y)
elif o == "*":
@code2be
code2be / integerToEnglishWords.js
Created March 3, 2020 13:51
integerToEnglishWords pretty code by psr@CodeSignal
// Simple JS code to convert a number into English Words.
// Copied from CodeSignal Solutions, Coded by psr < https://app.codesignal.com/profile/psr >
a = ` One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen`.split` `
b = ` Twen Thir For Fif Six Seven Eigh Nine`.split` `
w = ` Thousand Million Billion`.split` `
f = integerToEnglishWords = (
n,
k = 0,
@code2be
code2be / egypt_mobile.js
Created December 31, 2019 16:28
JS Regexp for mobile numbers in Egypt
var validate_egypt_mobile = (mobileStr) => {
return /^(010|012|011|015)[0-9]{8}$/.test(mobileStr);
}
@code2be
code2be / gist:cdd497c4998a9ab552ac4afa98d8cdbd
Last active October 25, 2016 12:04 — forked from prime31/gist:5675017
Simple PHP code to send FCM Push Notification
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
D/AsyncHttpClient: Headers were overwritten! (Accept | application/json) overwrites (Accept | application/json)
W/DefaultRequestDirector: Authentication error: Unable to respond to any of these challenges: {}
V/AsyncHttpResponseHandler: Progress 993 from 993 (100%)
W/remoting.RestAdapter: HTTP request (string) failed: org.apache.http.client.HttpResponseException: Unauthorized
W/System.err: org.apache.http.client.HttpResponseException: Unauthorized
W/System.err: at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:404)
W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:161)
W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:178)
W/System.err: at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:109)
W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
UserRepository userRepo = adapter.createRepository(UserRepository.class);
userRepo.loginUser(email, password, new UserRepository.LoginCallback() {
@Override
public void onSuccess(AccessToken token, Object currentUser) {
}
public void onError(Throwable t) {
@code2be
code2be / indexOfRegex.js
Created October 5, 2015 13:19
JS Array's indexOfRegex
var x = ['one', 'two', 'three'];
Array.prototype.indexOfRegex = function(regex) {
for(var i=0; i < this.length; i++) {
if(this[i].search(regex) > -1)
return i;
}
return -1;
}
@code2be
code2be / socket_sample.py
Last active August 29, 2015 14:04
Socket Server using Python
# http://facebook.com/code.we.bas
import socket
import sys
from thread import *
# Define HOST and PORT
HOST = '' # Host, Can be Empty to work on all available interfaces.
PORT = 8003 # Port to be used, must not be already used by another process.