Skip to content

Instantly share code, notes, and snippets.

@Eyad-Bereh
Eyad-Bereh / markup.php
Created December 5, 2018 00:14
Creating custom markup using PHP
<?php
function string_to_html(string $str) {
$str = str_ireplace("[newline]", "<br/>", $str);
$str = str_ireplace("[bold]", "<b>", $str);
$str = str_ireplace("[/bold]", "</b>", $str);
$str = str_ireplace("[italic]", "<i>", $str);
$str = str_ireplace("[/italic]", "</i>", $str);
$str = str_ireplace("[center]", "<span style=\"text-align:center;\">", $str);
$str = str_ireplace("[/center]", "</span>", $str);
$str = str_ireplace("[left]", "<span style=\"text-align:left;\">", $str);
@Eyad-Bereh
Eyad-Bereh / Rextester.java
Created December 13, 2018 19:54
A java function to check whether an object is numeric
//'main' method must be in a class 'Rextester'.
//Compiler version 1.8.0_111
import java.util.*;
import java.lang.*;
class Rextester
{
public static boolean isNumeric(Object parameter) {
try {
@Eyad-Bereh
Eyad-Bereh / Program.cs
Created March 8, 2019 20:39
Simple task manager in C# , built using .NET Core with .NET SDK 2.2.104
using System;
using System.Diagnostics;
using System.Collections;
namespace Test
{
public class Program
{
public static int Main(string[] args)
{
@Eyad-Bereh
Eyad-Bereh / MultiFilesWordsFrequencies.py
Created March 13, 2019 22:51
A multi-files words frequencies computing program made using python 3.6.8 , i've had this as a homework .
import re
import sys
def WordFrequency(filename, case_sensitive = True):
file = None
file_content = None
split_pattern = r"\t|\r|\n|\s+|\,|\.|\?|\!"
# Exceptions might occur, we don't want to print the native ugly error messages
try:
@Eyad-Bereh
Eyad-Bereh / GetURLParameters.js
Last active May 9, 2019 22:34
A JavaScript function to obtain GET parameters from a URL
//nodejs v4.2.6
'use strict'; // needed in nodejs v4.2.6 to enable "let" keyword
function GetURLParameters(url) { // url to provide as string
let parameters_string = url.split("?")[1]; // all parameters comes after "?"
let parameters = parameters_string.split("&"); // split to pairs of key/value
let parameters_object = {}; // the object which will contain those pairs
for (let i = 0; i < parameters.length; i++) {
@Eyad-Bereh
Eyad-Bereh / ConvertLinksToMultimedia.js
Created July 4, 2019 23:00
A JS function to replace links that points to images of types JPG,PNG,or JPEG into an <img> element that view them
function ConvertLinksToMultimedia(text) {
const regex = /(?<!src\=\')https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)\.(png|jpg|jpeg)(?!\')/i;
while (regex.test(text)) {
text = text.replace(regex, (match) => {
return "<img src='" + match + "'>";
});
}
return text;
}
@Eyad-Bereh
Eyad-Bereh / StringToHTML.php
Created August 8, 2019 21:29
A function to convert some special formatting codes into their equivalents in HTML
<?php
if (!function_exists("StringToHTML")) {
function StringToHTML($string) {
// The following regular expression was originally formed by Diego Perini
// Take a look at it here: https://gist.github.com/dperini/729294
$LinkRegex = "<\[url\](?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\[\/url\]>u";
$string = preg_replace_callback($LinkRegex, function($matches) {
$match = preg_replace("<\[url\]|\[\/url\]>", "", $matches[0]);
return "<a href='" . $match . "' target='_blank'>" . $match ."</a>";
@Eyad-Bereh
Eyad-Bereh / ColorAdapter.cpp
Created December 13, 2019 02:14
Computer Graphics - Moving in 3D space using OpenGL
#include "ColorAdapter.h"
RGB ColorAdapter::HexToRGB(int color) {
int Red = ((color & 0xFF0000) >> 16);
int Green = ((color & 0x00FF00) >> 8);
int Blue = color & 0x0000FF;
RGB Result;
Result.Red = Red;
Result.Green = Green;
Result.Blue = Blue;
@Eyad-Bereh
Eyad-Bereh / ColorAdapter.cpp
Last active December 17, 2019 21:02
Computer Graphics - Moving in 3D space using OpenGL with collision handling
#include "ColorAdapter.h"
RGB ColorAdapter::HexToRGB(int color) {
int Red = ((color & 0xFF0000) >> 16);
int Green = ((color & 0x00FF00) >> 8);
int Blue = color & 0x0000FF;
RGB Result;
Result.Red = Red;
Result.Green = Green;
Result.Blue = Blue;
package app;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class App {
public static void main(String[] args) throws Exception {
int PORT_NUMBER = 45012;