Skip to content

Instantly share code, notes, and snippets.

Avatar
🌗
Working from home

Essa Mamdani essamamdani

🌗
Working from home
View GitHub Profile
@essamamdani
essamamdani / inlineCSStoReact.php
Last active Feb 24, 2019
PHP code of simple little tool is intended to help translate plain CSS into the React in-line style specific JSON representation. Making it easy to copy and paste into an inline React component.
View inlineCSStoReact.php
function inlineCSStoReact($normalcss){
$json = preg_replace_callback(
"|(\w+)\-?(\w+)?\s*:\s*([^;]+)\s*;?|",
function($matches){
return '"'.$matches[1].ucfirst($matches[2]).'":"'.$matches[3].'",';
},
$normalcss);
return "{".rtrim($json,",")."}";
}
View JS Comment 1
<script>
//prints Hello World
document.write("Hello World");
</script>
View JSComments2
<script>
//declaring a function to sort numbers
function sortNumbers(){
//declare and initialize array of numbers
const nums = [3,14,45,12];
//sort the array and display the result
document.write(nums.sort());
}
sortNumbers();
@essamamdani
essamamdani / SingleLineComment
Created Apr 21, 2020
Single line comments also use as inline comments which means that they appear at the end of code.
View SingleLineComment
<script>
var x = 5; //declare and initalize the variable x
var y = x * 4; //multiply the value of x four times
</script>
@essamamdani
essamamdani / MultipleLinesComments
Created Apr 21, 2020
Multi-line / Block comments are used when you need to comment on multiple lines that are placed together.
View MultipleLinesComments
<script>
/* initialize and call a function
which takes users name in a variable
and welcome them on page */
function greetingMessage() {
var name = promp("Type your first name.");
document.write("Welcome to our page " + name + "!");
}
@essamamdani
essamamdani / MultipleLinesComments2
Created Apr 21, 2020
These types of comments can also be used when you want to test some functionality like you created a function but comment that out and create one more with a slight difference to check the working.
View MultipleLinesComments2
<script>
var a = 2;
var b = 7;
var c = 2;
document.write("Answer is " + sum());
/* function sum(){
return a+b;
} */
@essamamdani
essamamdani / setJS.js
Created Apr 27, 2020
declaration of set in JS
View setJS.js
var setA = new Set();
@essamamdani
essamamdani / AddInSet.js
Last active Apr 27, 2020
adding single and multiple values in a set in JS
View AddInSet.js
var setA = new Set();
setA.add(“maps”);
setA.add("maps").add("filters").add("generators").add("arrow functions");
console.log(setA.size)
@essamamdani
essamamdani / checkItem.js
Created Apr 27, 2020
Check an item from the Set:
View checkItem.js
var setA = new Set();
setA.add(“maps”);
setA.add("maps").add("filters").add("generators").add("arrow functions");
setA.has(“promises”);
setA.has(“generators”);
@essamamdani
essamamdani / DeleteItem.js
Created Apr 27, 2020
deleting and emptying item in set
View DeleteItem.js
var setA = new Set();
setA.add(“maps”);
setA.add("maps").add("filters").add("generators").add("arrow functions");
setA.delete(“filters”);
setA.clear();